static void init_async(h2o_multithread_queue_t *queue, h2o_loop_t *loop) { #if defined(__linux__) /** * The kernel overhead of an eventfd file descriptor is * much lower than that of a pipe, and only one file descriptor is required */ int fd; fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); if (fd == -1) { perror("eventfd"); abort(); } queue->async.write = fd; queue->async.read = h2o_evloop_socket_create(loop, fd, 0); #else int fds[2]; if (cloexec_pipe(fds) != 0) { perror("pipe"); abort(); } fcntl(fds[1], F_SETFL, O_NONBLOCK); queue->async.write = fds[1]; queue->async.read = h2o_evloop_socket_create(loop, fds[0], 0); #endif queue->async.read->data = queue; h2o_socket_read_start(queue->async.read, on_read); }
static void init_async(h2o_multithread_queue_t *queue, h2o_loop_t *loop) { int fds[2]; if (cloexec_pipe(fds) != 0) { perror("pipe"); abort(); } fcntl(fds[1], F_SETFL, O_NONBLOCK); queue->async.write = fds[1]; queue->async.read = h2o_evloop_socket_create(loop, fds[0], 0); queue->async.read->data = queue; h2o_socket_read_start(queue->async.read, on_read); }