int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd) { int fd_out; switch (handle->type) { case UV_TCP: case UV_NAMED_PIPE: case UV_TTY: fd_out = uv__stream_fd((uv_stream_t*) handle); break; case UV_UDP: fd_out = ((uv_udp_t *) handle)->io_watcher.fd; break; case UV_POLL: fd_out = ((uv_poll_t *) handle)->io_watcher.fd; break; default: return -EINVAL; } if (uv__is_closing(handle) || fd_out == -1) return -EBADF; *fd = fd_out; return 0; }
int uv_poll_start(uv_poll_t* handle, int pevents, uv_poll_cb poll_cb) { int events; assert((pevents & ~(UV_READABLE | UV_WRITABLE | UV_DISCONNECT)) == 0); assert(!uv__is_closing(handle)); uv__poll_stop(handle); if (pevents == 0) return 0; events = 0; if (pevents & UV_READABLE) events |= POLLIN; if (pevents & UV_WRITABLE) events |= POLLOUT; if (pevents & UV_DISCONNECT) events |= UV__POLLRDHUP; uv__io_start(handle->loop, &handle->io_watcher, events); uv__handle_start(handle); handle->poll_cb = poll_cb; return 0; }
int uv_is_closing(const uv_handle_t* handle) { return uv__is_closing(handle); }
void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { assert(!uv__is_closing(handle)); handle->flags |= UV_HANDLE_CLOSING; handle->close_cb = close_cb; switch (handle->type) { case UV_NAMED_PIPE: uv__pipe_close((uv_pipe_t*)handle); break; case UV_TTY: uv__stream_close((uv_stream_t*)handle); break; case UV_TCP: uv__tcp_close((uv_tcp_t*)handle); break; case UV_UDP: uv__udp_close((uv_udp_t*)handle); break; case UV_PREPARE: uv__prepare_close((uv_prepare_t*)handle); break; case UV_CHECK: uv__check_close((uv_check_t*)handle); break; case UV_IDLE: uv__idle_close((uv_idle_t*)handle); break; case UV_ASYNC: uv__async_close((uv_async_t*)handle); break; case UV_TIMER: uv__timer_close((uv_timer_t*)handle); break; case UV_PROCESS: uv__process_close((uv_process_t*)handle); break; case UV_FS_EVENT: uv__fs_event_close((uv_fs_event_t*)handle); break; case UV_POLL: uv__poll_close((uv_poll_t*)handle); break; case UV_FS_POLL: uv__fs_poll_close((uv_fs_poll_t*)handle); break; case UV_SIGNAL: uv__signal_close((uv_signal_t*) handle); /* Signal handles may not be closed immediately. The signal code will * itself close uv__make_close_pending whenever appropriate. */ return; default: assert(0); } uv__make_close_pending(handle); }
int uv_poll_stop(uv_poll_t* handle) { assert(!uv__is_closing(handle)); uv__poll_stop(handle); return 0; }