diff --git a/include/uv.h b/include/uv.h index defc0ac..0d22468 100644 --- a/include/uv.h +++ b/include/uv.h @@ -789,6 +789,8 @@ enum uv_poll_event { UV_PRIORITIZED = 8 }; +// User defined interface, to poll a block socket +UV_EXTERN int uv_poll_init_with_block_socket(uv_loop_t* loop, uv_poll_t* handle, int fd); UV_EXTERN int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd); UV_EXTERN int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle, diff --git a/src/unix/poll.c b/src/unix/poll.c index 3d5022b..88d0ee5 100644 --- a/src/unix/poll.c +++ b/src/unix/poll.c @@ -65,6 +65,23 @@ static void uv__poll_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) { } +int uv_poll_init_with_block_socket(uv_loop_t* loop, uv_poll_t* handle, int fd) { + int err; + + if (uv__fd_exists(loop, fd)) + return UV_EEXIST; + + err = uv__io_check_fd(loop, fd); + if (err) + return err; + + uv__handle_init(loop, (uv_handle_t*) handle, UV_POLL); + uv__io_init(&handle->io_watcher, uv__poll_io, fd); + handle->poll_cb = NULL; + return 0; +} + + int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd) { int err;