int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, uv_fs_event_cb cb, int flags) { int portfd; loop->counters.fs_event_init++; /* We don't support any flags yet. */ assert(!flags); if ((portfd = port_create()) == -1) { uv__set_sys_error(loop, errno); return -1; } uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT); handle->filename = strdup(filename); handle->fd = portfd; handle->cb = cb; memset(&handle->fo, 0, sizeof handle->fo); handle->fo.fo_name = handle->filename; uv__fs_event_rearm(handle); ev_io_init(&handle->event_watcher, uv__fs_event_read, portfd, EV_READ); ev_io_start(loop->ev, &handle->event_watcher); ev_unref(loop->ev); return 0; }
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, uv_fs_event_cb cb, int flags) { int portfd; int first_run = 0; if (loop->fs_fd == -1) { if ((portfd = port_create()) == -1) { uv__set_sys_error(loop, errno); return -1; } loop->fs_fd = portfd; first_run = 1; } uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT); uv__handle_start(handle); /* FIXME shouldn't start automatically */ handle->filename = strdup(filename); handle->fd = PORT_UNUSED; handle->cb = cb; memset(&handle->fo, 0, sizeof handle->fo); handle->fo.fo_name = handle->filename; uv__fs_event_rearm(handle); if (first_run) { uv__io_init(&loop->fs_event_watcher, uv__fs_event_read, portfd); uv__io_start(loop, &loop->fs_event_watcher, UV__POLLIN); } return 0; }
void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream, uv_handle_type type) { int err; uv__handle_init(loop, (uv_handle_t*)stream, type); stream->read_cb = NULL; stream->alloc_cb = NULL; stream->close_cb = NULL; stream->connection_cb = NULL; stream->connect_req = NULL; stream->shutdown_req = NULL; stream->accepted_fd = -1; stream->queued_fds = NULL; stream->delayed_error = 0; QUEUE_INIT(&stream->write_queue); QUEUE_INIT(&stream->write_completed_queue); stream->write_queue_size = 0; if (loop->emfile_fd == -1) { err = uv__open_cloexec("/", O_RDONLY); //if (err >= 0) if (err > 0) // 0 is invalid loop->emfile_fd = err; } uv__io_init(&stream->io_watcher, uv__stream_io, -1); }
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, uv_fs_event_cb cb, int flags) { int events; int wd; loop->counters.fs_event_init++; /* We don't support any flags yet. */ assert(!flags); if (init_inotify(loop)) return -1; events = IN_ATTRIB | IN_CREATE | IN_MODIFY | IN_DELETE | IN_DELETE_SELF | IN_MOVED_FROM | IN_MOVED_TO; wd = inotify_add_watch(loop->inotify_fd, filename, events); if (wd == -1) return uv__set_sys_error(loop, errno); uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT); handle->filename = strdup(filename); handle->cb = cb; handle->fd = wd; add_watcher(handle); return 0; }
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, uv_fs_event_cb cb, int flags) { int fd; loop->counters.fs_event_init++; /* We don't support any flags yet. */ assert(!flags); if (cb == NULL) { uv__set_sys_error(loop, EINVAL); return -1; } /* TODO open asynchronously - but how do we report back errors? */ if ((fd = open(filename, O_RDONLY)) == -1) { uv__set_sys_error(loop, errno); return -1; } uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT); handle->filename = strdup(filename); handle->fflags = 0; handle->cb = cb; handle->fd = fd; uv__fs_event_start(handle); return 0; }
int uv_poll_init(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; /* If ioctl(FIONBIO) reports ENOTTY, try fcntl(F_GETFL) + fcntl(F_SETFL). * Workaround for e.g. kqueue fds not supporting ioctls. */ err = uv__nonblock(fd, 1); if (err == UV_ENOTTY) if (uv__nonblock == uv__nonblock_ioctl) err = uv__nonblock_fcntl(fd, 1); 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_tcp_init(uv_tcp_t* tcp) { uv__handle_init((uv_handle_t*)tcp, UV_TCP); uv_counters()->tcp_init++; tcp->alloc_cb = NULL; tcp->connect_req = NULL; tcp->accepted_fd = -1; tcp->fd = -1; tcp->delayed_error = 0; ngx_queue_init(&tcp->write_queue); ngx_queue_init(&tcp->write_completed_queue); tcp->write_queue_size = 0; ev_init(&tcp->read_watcher, uv__tcp_io); tcp->read_watcher.data = tcp; ev_init(&tcp->write_watcher, uv__tcp_io); tcp->write_watcher.data = tcp; assert(ngx_queue_empty(&tcp->write_queue)); assert(ngx_queue_empty(&tcp->write_completed_queue)); assert(tcp->write_queue_size == 0); return 0; }
void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream, uv_handle_type type) { uv__handle_init(loop, (uv_handle_t*)stream, type); stream->read_cb = NULL; stream->read2_cb = NULL; stream->alloc_cb = NULL; stream->close_cb = NULL; stream->connection_cb = NULL; stream->connect_req = NULL; stream->shutdown_req = NULL; stream->accepted_fd = -1; stream->delayed_error = 0; ngx_queue_init(&stream->write_queue); ngx_queue_init(&stream->write_completed_queue); stream->write_queue_size = 0; if (loop->emfile_fd == -1) loop->emfile_fd = uv__open_cloexec("/", O_RDONLY); #if defined(__APPLE__) stream->select = NULL; #endif /* defined(__APPLE_) */ uv__io_init(&stream->io_watcher, uv__stream_io, -1); }
int uv_udp_init_ex(uv_loop_t* loop, uv_udp_t* handle, unsigned int flags) { int domain; int err; int fd; /* Use the lower 8 bits for the domain */ domain = flags & 0xFF; if (domain != AF_INET && domain != AF_INET6 && domain != AF_UNSPEC) return -EINVAL; if (flags & ~0xFF) return -EINVAL; if (domain != AF_UNSPEC) { err = uv__socket(domain, SOCK_DGRAM, 0); if (err < 0) return err; fd = err; } else { fd = -1; } uv__handle_init(loop, (uv_handle_t*)handle, UV_UDP); handle->alloc_cb = NULL; handle->recv_cb = NULL; handle->send_queue_size = 0; handle->send_queue_count = 0; uv__io_init(&handle->io_watcher, uv__udp_io, fd); QUEUE_INIT(&handle->write_queue); QUEUE_INIT(&handle->write_completed_queue); return 0; }
void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream, uv_handle_type type) { uv__handle_init(loop, (uv_handle_t*)stream, type); loop->counters.stream_init++; stream->alloc_cb = NULL; stream->close_cb = NULL; stream->connection_cb = NULL; stream->connect_req = NULL; stream->accepted_fd = -1; stream->fd = -1; stream->delayed_error = 0; stream->blocking = 0; ngx_queue_init(&stream->write_queue); ngx_queue_init(&stream->write_completed_queue); stream->write_queue_size = 0; ev_init(&stream->read_watcher, uv__stream_io); stream->read_watcher.data = stream; ev_init(&stream->write_watcher, uv__stream_io); stream->write_watcher.data = stream; assert(ngx_queue_empty(&stream->write_queue)); assert(ngx_queue_empty(&stream->write_completed_queue)); assert(stream->write_queue_size == 0); }
int uv_timer_init(uv_loop_t* loop, uv_timer_t* handle) { uv__handle_init(loop, (uv_handle_t*)handle, UV_TIMER); handle->timer_cb = NULL; handle->repeat = 0; return 0; }
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) { #ifdef HAVE_SYS_AHAFS_EVPRODS_H uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT); return 0; #else return -ENOSYS; #endif }
int uv_timer_init(uv_loop_t* loop, uv_timer_t* timer) { uv__handle_init(loop, (uv_handle_t*)timer, UV_TIMER); loop->counters.timer_init++; ev_init(&timer->timer_watcher, uv__timer_cb); return 0; }
int uv_timer_init(uv_handle_t* handle, uv_close_cb close_cb, void* data) { uv__handle_init(handle, UV_TIMER, close_cb, data); ev_init(&handle->timer_watcher, uv__timer_cb); handle->timer_watcher.data = handle; return 0; }
int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) { uv__handle_init(loop, (uv_handle_t*)handle, UV_UDP); handle->alloc_cb = NULL; handle->recv_cb = NULL; uv__io_init(&handle->io_watcher, uv__udp_io, -1); ngx_queue_init(&handle->write_queue); ngx_queue_init(&handle->write_completed_queue); return 0; }
int uv_prepare_init(uv_loop_t* loop, uv_prepare_t* prepare) { uv__handle_init(loop, (uv_handle_t*)prepare, UV_PREPARE); loop->counters.prepare_init++; ev_prepare_init(&prepare->prepare_watcher, uv__prepare); prepare->prepare_cb = NULL; return 0; }
int uv_check_init(uv_loop_t* loop, uv_check_t* check) { uv__handle_init(loop, (uv_handle_t*)check, UV_CHECK); loop->counters.check_init++; ev_check_init(&check->check_watcher, uv__check); check->check_cb = NULL; return 0; }
int uv_idle_init(uv_loop_t* loop, uv_idle_t* idle) { uv__handle_init(loop, (uv_handle_t*)idle, UV_IDLE); loop->counters.idle_init++; ev_idle_init(&idle->idle_watcher, uv__idle); idle->idle_cb = NULL; return 0; }
int uv_timer_init(uv_timer_t* timer) { uv__handle_init((uv_handle_t*)timer, UV_TIMER); uv_counters()->timer_init++; ev_init(&timer->timer_watcher, uv__timer_cb); timer->timer_watcher.data = timer; return 0; }
int uv_prepare_init(uv_handle_t* handle, uv_close_cb close_cb, void* data) { uv__handle_init(handle, UV_PREPARE, close_cb, data); ev_prepare_init(&handle->prepare_watcher, uv__prepare); handle->prepare_watcher.data = handle; handle->prepare_cb = NULL; return 0; }
int uv_idle_init(uv_handle_t* handle, uv_close_cb close_cb, void* data) { uv__handle_init(handle, UV_IDLE, close_cb, data); ev_idle_init(&handle->idle_watcher, uv__idle); handle->idle_watcher.data = handle; handle->idle_cb = NULL; return 0; }
int uv_check_init(uv_handle_t* handle, uv_close_cb close_cb, void* data) { uv__handle_init(handle, UV_CHECK, close_cb, data); ev_check_init(&handle->check_watcher, uv__check); handle->check_watcher.data = handle; handle->check_cb = NULL; return 0; }
int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) { memset(handle, 0, sizeof *handle); uv__handle_init(loop, (uv_handle_t*)handle, UV_UDP); handle->fd = -1; ngx_queue_init(&handle->write_queue); ngx_queue_init(&handle->write_completed_queue); return 0; }
int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd) { uv__handle_init(loop, (uv_handle_t*) handle, UV_POLL); loop->counters.poll_init++; handle->fd = fd; handle->poll_cb = NULL; uv__io_init(&handle->io_watcher, uv__poll_io, fd, 0); return 0; }
int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) { uv__handle_init(loop, (uv_handle_t*) handle, UV_ASYNC); handle->async_sent = 0; handle->async_cb = async_cb; QUEUE_INSERT_TAIL(&loop->async_handles, &handle->queue); uv__handle_start(handle); return 0; }
int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) { uv__handle_init(loop, (uv_handle_t*)handle, UV_UDP); handle->alloc_cb = NULL; handle->recv_cb = NULL; handle->send_queue_size = 0; handle->send_queue_count = 0; uv__io_init(&handle->io_watcher, uv__udp_io, -1); QUEUE_INIT(&handle->write_queue); QUEUE_INIT(&handle->write_completed_queue); return 0; }
int uv_prepare_init(uv_prepare_t* prepare) { uv__handle_init((uv_handle_t*)prepare, UV_PREPARE); uv_counters()->prepare_init++; ev_prepare_init(&prepare->prepare_watcher, uv__prepare); prepare->prepare_watcher.data = prepare; prepare->prepare_cb = NULL; return 0; }
int uv_idle_init(uv_idle_t* idle) { uv__handle_init((uv_handle_t*)idle, UV_IDLE); uv_counters()->idle_init++; ev_idle_init(&idle->idle_watcher, uv__idle); idle->idle_watcher.data = idle; idle->idle_cb = NULL; return 0; }
int uv_check_init(uv_check_t* check) { uv__handle_init((uv_handle_t*)check, UV_CHECK); uv_counters()->check_init++; ev_check_init(&check->check_watcher, uv__check); check->check_watcher.data = check; check->check_cb = NULL; return 0; }
int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd) { int err; err = uv__nonblock(fd, 1); 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; }