Reputation: 2630
I'm looking at a libuv example at https://github.com/benfleis/samples/blob/master/libuv/stdio/stdio_poll.c and trying to understand it.
I mostly understand it, but I'm having some trouble with the uv_poll_init's at the bottom, and I can't find any documentation.
Can someone point me to some documentation on it?
Thanks!
Upvotes: 2
Views: 1559
Reputation: 1392
Newest and latest and greatest documentation: http://docs.libuv.org/en/latest/
Upvotes: 2
Reputation: 51951
The official documentation is in the form of comments in the include/uv.h
header file, which provides the following documentation for uv_poll_init()
:
Initialize the poll watcher using a file descriptor.
However, some better documentation that covers the concept of watchers, can be found here. In short:
uv_poll_init(loop, &stdin_watcher, STDIN_FILENO);
Initializes stdin_watcher
to observe STDIN_FILENO
. When the watcher is started, all of its callbacks will be invoked within the context of loop
.
Here is a basic pseudo-flow of the program:
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)
Upvotes: 2