我正在https://github.com/benfleis/samples/blob/master/libuv/stdio/stdio_poll.c查看一个libuv示例并尝试理解它。
我最了解它,但是我在底部的uv_poll_init遇到了一些问题,我找不到任何文档。
有人能指点我一些文件吗?
谢谢!
答案 0 :(得分:2)
最新,最新且最好的文档:http://docs.libuv.org/en/latest/
答案 1 :(得分: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)