我正在查看https://github.com/benfleis/samples/blob/master/libuv/stdio/stdio_poll.c上的 libuv 示例并试图理解它。
我基本上理解它,但我在底部的 uv_poll_init 遇到了一些问题,我找不到任何文档。
有人可以指点我一些关于它的文件吗?
谢谢!
我正在查看https://github.com/benfleis/samples/blob/master/libuv/stdio/stdio_poll.c上的 libuv 示例并试图理解它。
我基本上理解它,但我在底部的 uv_poll_init 遇到了一些问题,我找不到任何文档。
有人可以指点我一些关于它的文件吗?
谢谢!
官方文档在include/uv.h
头文件中以注释的形式出现,其中提供了以下文档uv_poll_init()
:
使用文件描述符初始化轮询观察程序。
但是,可以在此处找到一些涵盖观察者概念的更好的文档。简而言之:
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/