static int couv_is_readable(lua_State *L) { uv_stream_t *handle; handle = couvL_checkudataclass(L, 1, COUV_STREAM_MTBL_NAME); lua_pushboolean(L, uv_is_readable(handle)); return 1; }
static void send_recv_start() { int r; ASSERT(1 == uv_is_readable((uv_stream_t*)&ctx2.channel)); ASSERT(1 == uv_is_writable((uv_stream_t*)&ctx2.channel)); ASSERT(0 == uv_is_closing((uv_handle_t*)&ctx2.channel)); r = uv_read_start((uv_stream_t*)&ctx2.channel, alloc_cb, read_cb); ASSERT(r == 0); }
static PyObject * Stream_readable_get(Stream *self, void *closure) { UNUSED_ARG(closure); RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL); return PyBool_FromLong((long)uv_is_readable((uv_stream_t *)UV_HANDLE(self))); }
int ipc_helper_tcp_connection(void) { /* * This is launched from test-ipc.c. stdin is a duplex channel * over which a handle will be transmitted. */ int r; struct sockaddr_in addr; uv_os_fd_t stdin_handle = uv_convert_fd_to_handle(0); r = uv_pipe_init(uv_default_loop(), &channel, 1); ASSERT(r == 0); uv_pipe_open(&channel, stdin_handle); ASSERT(1 == uv_is_readable((uv_stream_t*) &channel)); ASSERT(1 == uv_is_writable((uv_stream_t*) &channel)); ASSERT(0 == uv_is_closing((uv_handle_t*) &channel)); r = uv_tcp_init(uv_default_loop(), &tcp_server); ASSERT(r == 0); ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr)); r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0); ASSERT(r == 0); r = uv_listen((uv_stream_t*)&tcp_server, BACKLOG, ipc_on_connection_tcp_conn); ASSERT(r == 0); /* Make a connection to the server */ r = uv_tcp_init(uv_default_loop(), &conn.conn); ASSERT(r == 0); ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); r = uv_tcp_connect(&conn.conn_req, (uv_tcp_t*) &conn.conn, (const struct sockaddr*) &addr, connect_child_process_cb); ASSERT(r == 0); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); ASSERT(r == 0); ASSERT(tcp_conn_read_cb_called == 1); ASSERT(tcp_conn_write_cb_called == 1); ASSERT(close_cb_called == 4); MAKE_VALGRIND_HAPPY(); return 0; }
int ipc_helper(int listen_after_write) { /* * This is launched from test-ipc.c. stdin is a duplex channel that we * over which a handle will be transmitted. */ struct sockaddr_in addr; uv_write_t write_req; int r; uv_buf_t buf; uv_os_fd_t stdin_handle = uv_convert_fd_to_handle(0); ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr)); r = uv_pipe_init(uv_default_loop(), &channel, 1); ASSERT(r == 0); uv_pipe_open(&channel, stdin_handle); ASSERT(1 == uv_is_readable((uv_stream_t*) &channel)); ASSERT(1 == uv_is_writable((uv_stream_t*) &channel)); ASSERT(0 == uv_is_closing((uv_handle_t*) &channel)); r = uv_tcp_init(uv_default_loop(), &tcp_server); ASSERT(r == 0); r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0); ASSERT(r == 0); if (!listen_after_write) { r = uv_listen((uv_stream_t*)&tcp_server, BACKLOG, ipc_on_connection); ASSERT(r == 0); } buf = uv_buf_init("hello\n", 6); r = uv_write2(&write_req, (uv_stream_t*)&channel, &buf, 1, (uv_stream_t*)&tcp_server, NULL); ASSERT(r == 0); if (listen_after_write) { r = uv_listen((uv_stream_t*)&tcp_server, BACKLOG, ipc_on_connection); ASSERT(r == 0); } r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); ASSERT(r == 0); ASSERT(connection_accepted == 1); ASSERT(close_cb_called == 3); MAKE_VALGRIND_HAPPY(); return 0; }
int ipc_helper_closed_handle(void) { int r; struct sockaddr_in addr; uv_write_t write_req; uv_write_t write_req2; uv_buf_t buf; char buffer[LARGE_SIZE]; r = uv_pipe_init(uv_default_loop(), &channel, 1); ASSERT(r == 0); uv_pipe_open(&channel, 0); ASSERT(1 == uv_is_readable((uv_stream_t*) &channel)); ASSERT(1 == uv_is_writable((uv_stream_t*) &channel)); ASSERT(0 == uv_is_closing((uv_handle_t*) &channel)); memset(buffer, '.', LARGE_SIZE); buf = uv_buf_init(buffer, LARGE_SIZE); r = uv_tcp_init(uv_default_loop(), &tcp_server); ASSERT(r == 0); ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr)); r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0); ASSERT(r == 0); r = uv_write(&write_req, (uv_stream_t*)&channel, &buf, 1, closed_handle_large_write_cb); ASSERT(r == 0); r = uv_write2(&write_req2, (uv_stream_t*)&channel, &buf, 1, (uv_stream_t*)&tcp_server, closed_handle_write_cb); ASSERT(r == 0); uv_close((uv_handle_t*)&tcp_server, NULL); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); ASSERT(r == 0); MAKE_VALGRIND_HAPPY(); return 0; }
static int ipc_helper(int listen_after_write) { /* * This is launched from test-ipc.c. stdin is a duplex channel that we * over which a handle will be transmitted. In this initial version only * data is transfered over the channel. XXX edit this comment after handle * transfer is added. */ uv_write_t write_req; int r; uv_buf_t buf; r = uv_pipe_init(uv_default_loop(), &channel, 1); ASSERT(r == 0); uv_pipe_open(&channel, 0); ASSERT(uv_is_readable(&channel)); ASSERT(uv_is_writable(&channel)); r = uv_tcp_init(uv_default_loop(), &tcp_server); ASSERT(r == 0); r = uv_tcp_bind(&tcp_server, uv_ip4_addr("0.0.0.0", TEST_PORT)); ASSERT(r == 0); if (!listen_after_write) { r = uv_listen((uv_stream_t*)&tcp_server, 12, ipc_on_connection); ASSERT(r == 0); } buf = uv_buf_init("hello\n", 6); r = uv_write2(&write_req, (uv_stream_t*)&channel, &buf, 1, (uv_stream_t*)&tcp_server, NULL); ASSERT(r == 0); if (listen_after_write) { r = uv_listen((uv_stream_t*)&tcp_server, 12, ipc_on_connection); ASSERT(r == 0); } r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(connection_accepted == 1); ASSERT(close_cb_called == 3); return 0; }
int ipc_helper(int listen_after_write) { /* * This is launched from test-ipc.c. stdin is a duplex channel that we * over which a handle will be transmitted. */ uv_write_t write_req; int r; uv_buf_t buf; r = uv_pipe_init(uv_default_loop(), &channel, 1); ASSERT(r == 0); uv_pipe_open(&channel, 0); ASSERT(uv_is_readable((uv_stream_t*) &channel)); ASSERT(uv_is_writable((uv_stream_t*) &channel)); ASSERT(!uv_is_closing((uv_handle_t*) &channel)); r = uv_tcp_init(uv_default_loop(), &tcp_server); ASSERT(r == 0); r = uv_tcp_bind(&tcp_server, uv_ip4_addr("0.0.0.0", TEST_PORT)); ASSERT(r == 0); if (!listen_after_write) { r = uv_listen((uv_stream_t*)&tcp_server, 12, ipc_on_connection); ASSERT(r == 0); } buf = uv_buf_init("hello\n", 6); r = uv_write2(&write_req, (uv_stream_t*)&channel, &buf, 1, (uv_stream_t*)&tcp_server, NULL); ASSERT(r == 0); if (listen_after_write) { r = uv_listen((uv_stream_t*)&tcp_server, 12, ipc_on_connection); ASSERT(r == 0); } r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(connection_accepted == 1); ASSERT(close_cb_called == 3); MAKE_VALGRIND_HAPPY(); return 0; }
static void pinger_on_connect(uv_connect_t *req, int status) { pinger_t *pinger = (pinger_t*)req->handle->data; pinger_on_connect_count++; ASSERT(status == 0); ASSERT(uv_is_readable(req->handle)); ASSERT(uv_is_writable(req->handle)); ASSERT(!uv_is_closing((uv_handle_t *)req->handle)); pinger_write_ping(pinger); uv_read_start((uv_stream_t*)(req->handle), alloc_cb, pinger_read_cb); }
int ipc_helper_bind_twice(void) { /* * This is launched from test-ipc.c. stdin is a duplex channel * over which two handles will be transmitted. */ struct sockaddr_in addr; uv_write_t write_req; uv_write_t write_req2; int r; uv_buf_t buf; uv_os_fd_t stdin_handle = uv_convert_fd_to_handle(0); ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr)); r = uv_pipe_init(uv_default_loop(), &channel, 1); ASSERT(r == 0); uv_pipe_open(&channel, stdin_handle); ASSERT(1 == uv_is_readable((uv_stream_t*) &channel)); ASSERT(1 == uv_is_writable((uv_stream_t*) &channel)); ASSERT(0 == uv_is_closing((uv_handle_t*) &channel)); buf = uv_buf_init("hello\n", 6); r = uv_tcp_init(uv_default_loop(), &tcp_server); ASSERT(r == 0); r = uv_tcp_init(uv_default_loop(), &tcp_server2); ASSERT(r == 0); r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0); ASSERT(r == 0); r = uv_tcp_bind(&tcp_server2, (const struct sockaddr*) &addr, 0); ASSERT(r == 0); r = uv_write2(&write_req, (uv_stream_t*)&channel, &buf, 1, (uv_stream_t*)&tcp_server, NULL); ASSERT(r == 0); r = uv_write2(&write_req2, (uv_stream_t*)&channel, &buf, 1, (uv_stream_t*)&tcp_server2, NULL); ASSERT(r == 0); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); ASSERT(r == 0); MAKE_VALGRIND_HAPPY(); return 0; }
int ipc_helper_tcp_connection() { /* * This is launched from test-ipc.c. stdin is a duplex channel that we * over which a handle will be transmitted. */ int r; struct sockaddr_in addr; r = uv_pipe_init(uv_default_loop(), &channel, 1); ASSERT(r == 0); uv_pipe_open(&channel, 0); ASSERT(uv_is_readable((uv_stream_t*)&channel)); ASSERT(uv_is_writable((uv_stream_t*)&channel)); ASSERT(!uv_is_closing((uv_handle_t*)&channel)); r = uv_tcp_init(uv_default_loop(), &tcp_server); ASSERT(r == 0); r = uv_tcp_bind(&tcp_server, uv_ip4_addr("0.0.0.0", TEST_PORT)); ASSERT(r == 0); r = uv_listen((uv_stream_t*)&tcp_server, 12, ipc_on_connection_tcp_conn); ASSERT(r == 0); /* Make a connection to the server */ r = uv_tcp_init(uv_default_loop(), &conn.conn); ASSERT(r == 0); addr = uv_ip4_addr("127.0.0.1", TEST_PORT); r = uv_tcp_connect(&conn.conn_req, (uv_tcp_t*)&conn.conn, addr, connect_child_process_cb); ASSERT(r == 0); r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(tcp_conn_read_cb_called == 1); ASSERT(tcp_conn_write_cb_called == 1); ASSERT(close_cb_called == 4); MAKE_VALGRIND_HAPPY(); return 0; }
/* stdin is a duplex channel over which a handle is sent. * We receive it and send it back where it came from. */ int ipc_send_recv_helper(void) { int r; memset(&ctx, 0, sizeof(ctx)); r = uv_pipe_init(uv_default_loop(), &ctx.channel, 1); ASSERT(r == 0); uv_pipe_open(&ctx.channel, 0); ASSERT(1 == uv_is_readable((uv_stream_t*)&ctx.channel)); ASSERT(1 == uv_is_writable((uv_stream_t*)&ctx.channel)); ASSERT(0 == uv_is_closing((uv_handle_t*)&ctx.channel)); r = uv_read2_start((uv_stream_t*)&ctx.channel, alloc_cb, read2_cb); ASSERT(r == 0); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); ASSERT(r == 0); MAKE_VALGRIND_HAPPY(); return 0; }
void uv__stream_osx_select(void* arg) { uv_stream_t* stream; uv__stream_select_t* s; char buf[1024]; fd_set sread; fd_set swrite; fd_set serror; int events; int fd; int r; int max_fd; stream = arg; s = stream->select; fd = stream->io_watcher.fd; if (fd > s->int_fd) max_fd = fd; else max_fd = s->int_fd; while (1) { /* Terminate on semaphore */ if (uv_sem_trywait(&s->sem) == 0) break; /* Watch fd using select(2) */ FD_ZERO(&sread); FD_ZERO(&swrite); FD_ZERO(&serror); if (uv_is_readable(stream)) FD_SET(fd, &sread); if (uv_is_writable(stream)) FD_SET(fd, &swrite); FD_SET(fd, &serror); FD_SET(s->int_fd, &sread); /* Wait indefinitely for fd events */ r = select(max_fd + 1, &sread, &swrite, &serror, NULL); if (r == -1) { if (errno == EINTR) continue; /* XXX: Possible?! */ abort(); } /* Ignore timeouts */ if (r == 0) continue; /* Empty socketpair's buffer in case of interruption */ if (FD_ISSET(s->int_fd, &sread)) while (1) { r = read(s->int_fd, buf, sizeof(buf)); if (r == sizeof(buf)) continue; if (r != -1) break; if (errno == EAGAIN || errno == EWOULDBLOCK) break; if (errno == EINTR) continue; abort(); } /* Handle events */ events = 0; if (FD_ISSET(fd, &sread)) events |= UV__POLLIN; if (FD_ISSET(fd, &swrite)) events |= UV__POLLOUT; if (FD_ISSET(fd, &serror)) events |= UV__POLLERR; uv_mutex_lock(&s->mutex); s->events |= events; uv_mutex_unlock(&s->mutex); if (events != 0) uv_async_send(&s->async); } }
void uv__stream_osx_select(void* arg) { uv_stream_t* stream; uv__stream_select_t* s; fd_set read; fd_set write; fd_set error; struct timeval timeout; int events; int fd; int r; int max_fd; stream = arg; s = stream->select; fd = stream->io_watcher.fd; if (fd > s->int_fd) max_fd = fd; else max_fd = s->int_fd; while (1) { /* Terminate on semaphore */ if (uv_sem_trywait(&s->sem) == 0) break; /* Watch fd using select(2) */ FD_ZERO(&read); FD_ZERO(&write); FD_ZERO(&error); if (uv_is_readable(stream)) FD_SET(fd, &read); if (uv_is_writable(stream)) FD_SET(fd, &write); FD_SET(fd, &error); FD_SET(s->int_fd, &read); timeout.tv_sec = 0; timeout.tv_usec = 250000; /* 250 ms timeout */ r = select(max_fd + 1, &read, &write, &error, &timeout); if (r == -1) { if (errno == EINTR) continue; /* XXX: Possible?! */ abort(); } /* Ignore timeouts */ if (r == 0) continue; /* Handle events */ events = 0; if (FD_ISSET(fd, &read)) events |= UV__POLLIN; if (FD_ISSET(fd, &write)) events |= UV__POLLOUT; if (FD_ISSET(fd, &error)) events |= UV__POLLERR; uv_mutex_lock(&s->mutex); s->events |= events; uv_mutex_unlock(&s->mutex); if (events != 0) uv_async_send(&s->async); } }
static void uv__stream_osx_select(void* arg) { uv_stream_t* stream; uv__stream_select_t* s; char buf[1024]; fd_set sread; fd_set swrite; int events; int fd; int r; int max_fd; stream = arg; s = stream->select; fd = s->fd; if (fd > s->int_fd) max_fd = fd; else max_fd = s->int_fd; while (1) { /* Terminate on semaphore */ if (uv_sem_trywait(&s->close_sem) == 0) break; /* Watch fd using select(2) */ FD_ZERO(&sread); FD_ZERO(&swrite); if (uv_is_readable(stream)) FD_SET(fd, &sread); if (uv_is_writable(stream)) FD_SET(fd, &swrite); FD_SET(s->int_fd, &sread); /* Wait indefinitely for fd events */ r = select(max_fd + 1, &sread, &swrite, NULL, NULL); if (r == -1) { if (errno == EINTR) continue; /* XXX: Possible?! */ abort(); } /* Ignore timeouts */ if (r == 0) continue; /* Empty socketpair's buffer in case of interruption */ if (FD_ISSET(s->int_fd, &sread)) while (1) { r = read(s->int_fd, buf, sizeof(buf)); if (r == sizeof(buf)) continue; if (r != -1) break; if (errno == EAGAIN || errno == EWOULDBLOCK) break; if (errno == EINTR) continue; abort(); } /* Handle events */ events = 0; if (FD_ISSET(fd, &sread)) events |= UV__POLLIN; if (FD_ISSET(fd, &swrite)) events |= UV__POLLOUT; assert(events != 0 || FD_ISSET(s->int_fd, &sread)); if (events != 0) { ACCESS_ONCE(int, s->events) = events; uv_async_send(&s->async); uv_sem_wait(&s->async_sem); /* Should be processed at this stage */ assert((s->events == 0) || (stream->flags & UV_CLOSING)); } }
static int luv_is_readable(lua_State* L) { uv_stream_t* handle = luv_check_stream(L, 1); lua_pushboolean(L, uv_is_readable(handle)); return 1; }
static int luv_stream_readable(lua_State* L) { luv_object_t* self = (luv_object_t*)lua_touserdata(L, 1); lua_pushboolean(L, uv_is_readable(&self->h.stream)); return 1; }