【发布时间】:2013-04-13 20:52:48
【问题描述】:
我正在查看https://github.com/benfleis/samples/blob/master/libuv/stdio/stdio_poll.c 的 libuv 示例并试图理解它。
我基本明白了,但是我在底部的 uv_poll_init 遇到了一些问题,我找不到任何文档。
有人可以指点我的一些文档吗?
谢谢!
【问题讨论】:
标签: libuv
我正在查看https://github.com/benfleis/samples/blob/master/libuv/stdio/stdio_poll.c 的 libuv 示例并试图理解它。
我基本明白了,但是我在底部的 uv_poll_init 遇到了一些问题,我找不到任何文档。
有人可以指点我的一些文档吗?
谢谢!
【问题讨论】:
标签: libuv
官方文档是include/uv.h头文件中的cmets形式,为uv_poll_init()提供了如下文档:
使用文件描述符初始化 poll watcher。
但是,可以在here 找到一些更好的涵盖观察者概念的文档。简而言之:
uv_poll_init(loop, &stdin_watcher, STDIN_FILENO);
初始化stdin_watcher 以观察STDIN_FILENO。当 watcher 启动时,它的所有回调都将在 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)
【讨论】:
最新、最新、最棒的文档:http://docs.libuv.org/en/latest/
【讨论】: