2017-03-06 6 views
0

다음과 같이 libev의 공식 예제를 시도했습니다. 컴파일하고 실행 한 후에는 stdin에서 아무 것도 입력하지 않으면 이벤트가 트리거됩니다. 하지만 내가 입력 한 내용은 여전히 ​​견고한 입력으로 취급되어 내 콘솔에 표시됩니다. 내 질문은 :이 콘솔 입력을 콘솔 프롬프트에서 피할 수있는 방법이며, libev를 잡아서 저장하는 것일까 요?linux C++ libev 공식 예제 중복 콘솔 동작 표시

libev에서 어떤 방식 으로든이 작업을 수행 할 수 있습니까?

// a single header file is required 
    #include <ev.h> 

    #include <stdio.h> // for puts 

    // every watcher type has its own typedef'd struct 
    // with the name ev_TYPE 
    ev_io stdin_watcher; 
    ev_timer timeout_watcher; 

    // all watcher callbacks have a similar signature 
    // this callback is called when data is readable on stdin 
    static void 
    stdin_cb (EV_P_ ev_io *w, int revents) 
    { 
     puts ("stdin ready"); 
     // for one-shot events, one must manually stop the watcher 
     // with its corresponding stop function. 
     ev_io_stop (EV_A_ w); 

     // this causes all nested ev_run's to stop iterating 
     ev_break (EV_A_ EVBREAK_ALL); 
    } 

    // another callback, this time for a time-out 
    static void 
    timeout_cb (EV_P_ ev_timer *w, int revents) 
    { 
     puts ("timeout"); 
     // this causes the innermost ev_run to stop iterating 
     ev_break (EV_A_ EVBREAK_ONE); 
    } 

    int 
    main (void) 
    { 
     // use the default event loop unless you have special needs 
     struct ev_loop *loop = EV_DEFAULT; 

     // initialise an io watcher, then start it 
     // this one will watch for stdin to become readable 
     ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ); 
     ev_io_start (loop, &stdin_watcher); 

     // initialise a timer watcher, then start it 
     // simple non-repeating 5.5 second timeout 
     ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.); 
     ev_timer_start (loop, &timeout_watcher); 

     // now wait for events to arrive 
     ev_run (loop, 0); 

     // break was called, so exit 
     return 0; 
    } 
+0

콘솔 에코를 비활성화하는 방법을 묻는 질문이 있으십니까? –

답변

1

난 당신이 무엇을 쓰기의 반향을 의미 가정

은 여기 공식 예제를 붙여? 이것은 터미널 프로그램의 기본 동작입니다. 에코를 사용하지 않으려면 termios 함수 및 플래그를 사용할 수 있습니다. 프로그램을 끝내기 전에 활성화하는 것을 잊지 마십시오.

1

ev_io_init에서 트리거를 설정합니다. STDIN_FILENO를 설정하는 대신 소켓에서 fd를 사용하도록 선택할 수 있습니다. 이것이 당신이 찾고있는 것인지 모른다. 여기 내가 말하는 바가 example입니다.