void ipc_connect_cb(uv_connect_t* req, int status) { int rc; struct ipc_client_ctx* ctx; ctx = container_of(req, struct ipc_client_ctx, connect_req); rc = uv_read2_start((uv_stream_t*)&ctx->ipc_pipe, ipc_alloc_cb, ipc_read2_cb); }
static int run_test(void) { uv_process_t process; uv_buf_t buf; int r; spawn_helper(&ctx.channel, &process, "ipc_send_recv_helper"); buf = uv_buf_init(".", 1); r = uv_write2(&ctx.write_req, (uv_stream_t*)&ctx.channel, &buf, 1, &ctx.send.stream, NULL); ASSERT(r == 0); r = uv_read2_start((uv_stream_t*)&ctx.channel, alloc_cb, recv_cb); ASSERT(r == 0); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); ASSERT(r == 0); ASSERT(num_recv_handles == 1); return 0; }
static PyObject * Pipe_func_start_read2(Pipe *self, PyObject *args) { int r; PyObject *tmp, *callback; tmp = NULL; RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL); RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL); if (!PyArg_ParseTuple(args, "O:start_read2", &callback)) { return NULL; } if (!PyCallable_Check(callback)) { PyErr_SetString(PyExc_TypeError, "a callable is required"); return NULL; } r = uv_read2_start((uv_stream_t *)UV_HANDLE(self), (uv_alloc_cb)on_stream_alloc, (uv_read2_cb)on_pipe_read2); if (r != 0) { RAISE_UV_EXCEPTION(UV_HANDLE_LOOP(self), PyExc_PipeError); return NULL; } tmp = ((Stream *)self)->on_read_cb; Py_INCREF(callback); ((Stream *)self)->on_read_cb = callback; Py_XDECREF(tmp); Py_RETURN_NONE; }
int main() { loop = uv_default_loop(); uv_pipe_init(loop, &queue, 1); uv_pipe_open(&queue, 0); uv_read2_start((uv_stream_t*)&queue, alloc_buffer, on_new_connection); return uv_run(loop, UV_RUN_DEFAULT); }
static int run_ipc_test(const char* helper, uv_read2_cb read_cb) { uv_process_t process; int r; spawn_helper(&channel, &process, helper); uv_read2_start((uv_stream_t*)&channel, on_alloc, read_cb); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); ASSERT(r == 0); 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; }