2013-04-13 69 views

回答

1

的正式文檔是在include/uv.h頭文件的註釋的形式,其提供了以下文檔uv_poll_init()

初始化使用文件描述符輪詢觀察者。

但是,一些涵蓋觀察者概念的更好的文檔可以在here找到。總之:

uv_poll_init(loop, &stdin_watcher, STDIN_FILENO); 

初始化stdin_watcher觀察STDIN_FILENO。觀察者啓動時,其所有回調將在loop的範圍內調用。

這裏是程序的基本僞流程:

stdout_cb: 
    write whatever is in log_buf to stdout 
    stop listening for when I can write to stdout 

log: 
    write message to log_buf 
    have stdout_watcher listen for when its file becomes writeable 
    when it becomes writable, stdout_cb will be called 

stdint_cb: 
    read from stdin 
    call log 

set_non_blocking: 
    set file descriptor as non-blocking 

main: 
    set stdin/out to nonblocking 

    get handle to default event loop 
    initialize stdint_watcher, it will listen to stdin and its callback will 
    run within the default loop 
    initialize stdout_watcher, it will listen to stdout and its callback will 
    run within the default loop 
    have stdin_watcher listen for when its file becomes readable 
    when it becomes readable, stdin_cb will be called 
    run the event loop until no more work exists 
    in this case, when both watchers are not running (i.e. stopped) 
相關問題