static int run_test(int inprocess) { uv_process_t process; uv_thread_t tid; int r; if (inprocess) { r = uv_thread_create(&tid, ipc_send_recv_helper_threadproc, (void *) 42); ASSERT(r == 0); uv_sleep(1000); r = uv_pipe_init(uv_default_loop(), &ctx.channel, 1); ASSERT(r == 0); uv_pipe_connect(&ctx.connect_req, &ctx.channel, TEST_PIPENAME_3, connect_cb); } else { spawn_helper(&ctx.channel, &process, "ipc_send_recv_helper"); connect_cb(&ctx.connect_req, 0); } r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); ASSERT(r == 0); ASSERT(recv_cb_count == 2); if (inprocess) { r = uv_thread_join(&tid); ASSERT(r == 0); } return 0; }
static void maybe_connect_some() { uv_connect_t* req; uv_tcp_t* tcp; uv_pipe_t* pipe; int r; while (max_connect_socket < TARGET_CONNECTIONS && max_connect_socket < write_sockets + MAX_SIMULTANEOUS_CONNECTS) { if (type == TCP) { tcp = &tcp_write_handles[max_connect_socket++]; r = uv_tcp_init(tcp); ASSERT(r == 0); req = (uv_connect_t*) req_alloc(); r = uv_tcp_connect(req, tcp, connect_addr, connect_cb); ASSERT(r == 0); } else { pipe = &pipe_write_handles[max_connect_socket++]; r = uv_pipe_init(pipe); ASSERT(r == 0); req = (uv_connect_t*) req_alloc(); r = uv_pipe_connect(req, pipe, TEST_PIPENAME, connect_cb); ASSERT(r == 0); } } }
void connect(const std::string& name, CallbackWithResult callback) { callbacks::store(get()->data, internal::uv_cid_connect, callback); uv_pipe_connect(new uv_connect_t, get(), name.c_str(), [](uv_connect_t* req, int status) { std::unique_ptr<uv_connect_t> reqHolder(req); callbacks::invoke<decltype(callback)>(req->handle->data, internal::uv_cid_connect, error(status)); }); }
void get_listen_handle(uv_loop_t* loop, uv_stream_t* server_handle) { int rc; struct ipc_client_ctx ctx; ctx.server_handle = server_handle; ctx.server_handle->data = "server handle"; rc = uv_pipe_init(loop, &ctx.ipc_pipe, 1); uv_pipe_connect(&ctx.connect_req, &ctx.ipc_pipe, "HAYWIRE_CONNECTION_DISPATCH_PIPE_NAME", ipc_connect_cb); rc = uv_run(loop, UV_RUN_DEFAULT); }
/* * Class: com_iwebpp_libuvpp_handles_PipeHandle * Method: _connect * Signature: (JLjava/lang/String;)V */ extern "C" JNIEXPORT void JNICALL Java_com_iwebpp_libuvpp_handles_PipeHandle__1connect (JNIEnv *env, jobject that, jlong pipe, jstring name, jobject context) { assert(pipe); uv_pipe_t* handle = reinterpret_cast<uv_pipe_t*>(pipe); uv_connect_t* connect = new uv_connect_t(); connect->data = new ContextHolder(env, context); connect->handle = reinterpret_cast<uv_stream_t*>(handle); const char *pipeName = env->GetStringUTFChars(name, 0); uv_pipe_connect(connect, handle, pipeName, _pipe_connect_cb); env->ReleaseStringUTFChars(name, pipeName); }
static void pipe_make_connect(conn_rec* p) { int r; r = uv_pipe_init(loop, (uv_pipe_t*)&p->stream, 0); ASSERT(r == 0); uv_pipe_connect(&((pipe_conn_rec*)p)->conn_req, (uv_pipe_t*)&p->stream, TEST_PIPENAME, connect_cb); #if DEBUG printf("make connect %d\n", p->i); #endif p->conn_req.data = p; p->write_req.data = p; p->stream.data = p; }
static void pipe_pinger_new() { int r; pinger_t *pinger; pinger = (pinger_t*)malloc(sizeof(*pinger)); pinger->state = 0; pinger->pongs = 0; /* Try to connec to the server and do NUM_PINGS ping-pongs. */ r = uv_pipe_init(&pinger->pipe); pinger->pipe.data = pinger; ASSERT(!r); /* We are never doing multiple reads/connects at a time anyway. */ /* so these handles can be pre-initialized. */ r = uv_pipe_connect(&pinger->connect_req, &pinger->pipe, TEST_PIPENAME, pinger_on_connect); ASSERT(!r); }
static PyObject * Pipe_func_connect(Pipe *self, PyObject *args) { char *name; uv_connect_t *connect_req = NULL; PyObject *callback; RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL); RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL); if (!PyArg_ParseTuple(args, "sO:connect", &name, &callback)) { return NULL; } if (!PyCallable_Check(callback)) { PyErr_SetString(PyExc_TypeError, "a callable is required"); return NULL; } Py_INCREF(callback); connect_req = PyMem_Malloc(sizeof *connect_req); if (!connect_req) { PyErr_NoMemory(); goto error; } connect_req->data = (void *)callback; uv_pipe_connect(connect_req, (uv_pipe_t *)UV_HANDLE(self), name, on_pipe_client_connection); /* Increase refcount so that object is not removed before the callback is called */ Py_INCREF(self); Py_RETURN_NONE; error: Py_DECREF(callback); if (connect_req) { PyMem_Free(connect_req); } return NULL; }
static int wsn_client_start_connect_(wsn_client_ctx_t *client) { int err = 0; connect_timer_reset_(client); if (wsn_is_pipe(client->conf)) { uv_pipe_connect(&client->connect_req, &client->conn->io_handle.pipe, client->conf->host, on_connected_); } else { err = uv_tcp_connect(&client->connect_req, &client->conn->io_handle.tcp, &client->host_addr, on_connected_); } if (err) { wsn_report_err(WSN_ERR_CONNECT, "Connect to (\"%s\") failed: %s", client->conf->host, uv_strerror(err)); return WSN_ERR_CONNECT; } return 0; }
static void pipe_make_connect(conn_rec* p) { int r; r = uv_pipe_init(loop, (uv_pipe_t*)&p->stream); ASSERT(r == 0); r = uv_pipe_connect(&((pipe_conn_rec*)p)->conn_req, (uv_pipe_t*)&p->stream, TEST_PIPENAME, connect_cb); if (r) { fprintf(stderr, "uv_tcp_connect error %s\n", uv_err_name(uv_last_error(loop))); ASSERT(0); } #if DEBUG printf("make connect %d\n", p->i); #endif p->conn_req.data = p; p->write_req.data = p; p->stream.data = p; }
static void pipe_pinger_new(void) { int r; pinger_t *pinger; pinger = (pinger_t*)malloc(sizeof(*pinger)); pinger->state = 0; pinger->pongs = 0; /* Try to connect to the server and do NUM_PINGS ping-pongs. */ r = uv_pipe_init(uv_default_loop(), &pinger->stream.pipe, 0); pinger->stream.pipe.data = pinger; ASSERT(!r); /* We are never doing multiple reads/connects at a time anyway. */ /* so these handles can be pre-initialized. */ uv_pipe_connect(&pinger->connect_req, &pinger->stream.pipe, TEST_PIPENAME, pinger_on_connect); /* Synchronous connect callbacks are not allowed. */ ASSERT(pinger_on_connect_count == 0); }
int main(void) { uv_loop_t loop; struct sockaddr_in addr; uv_connect_t connect_req; int fd, r; /* loop init */ uv_loop_init(&loop); #if USE_PIPE uv_pipe_init(&loop, &client, 1); uv_pipe_connect(&connect_req, &client, "/var/tmp/pipe.server1", connect_cb); #else /*tcp socket initial */ uv_ip4_addr("127.0.0.1", 4789, &addr); uv_tcp_init(&loop, &client); uv_tcp_connect(&connect_req, &client, (const struct sockaddr *)&addr, connect_cb); #endif r = uv_tty_init(&loop, &tty, 0, 1); printf("r=%d\n", r); uv_read_start((uv_stream_t *) & tty, alloc_cb, recv_cb); uv_run(&loop, UV_RUN_DEFAULT); printf("end\n"); return 0; }
void ::yajr::comms::internal::ActiveUnixPeer::retry() { if (destroying_) { LOG(INFO) << this << "Not retrying because of pending destroy" ; return; } if (uvRefCnt_ != 1) { LOG(INFO) << this << " has to wait for reference count to fall to 1 before retrying" ; insert(internal::Peer::LoopData::RETRY_TO_CONNECT); return; } int rc; if ((rc = uv_pipe_init( getUvLoop(), reinterpret_cast<uv_pipe_t *>(getHandle()), 0))) { LOG(WARNING) << "uv_pipe_init: [" << uv_err_name(rc) << "] " << uv_strerror(rc) ; onError(rc); insert(internal::Peer::LoopData::RETRY_TO_CONNECT); return; } /* potentially switch uv loop if some rebalancing is needed */ uv_loop_t * newLoop = uvLoopSelector_(getData()); if (newLoop != getHandle()->loop) { getLoopData()->down(); getHandle()->loop = newLoop; getLoopData()->up(); } /* uv_pipe_connect errors are always asynchronous */ uv_pipe_connect(&connect_req_, reinterpret_cast<uv_pipe_t *>(getHandle()), socketName_.c_str(), on_active_connection); /* workaround for libuv synchronous uv_pipe_connect() failures bug */ getLoopData()->kickLibuv(); up(); status_ = Peer::kPS_CONNECTING; insert(internal::Peer::LoopData::ATTEMPTING_TO_CONNECT); VLOG(1) << this << " issued a pipe connect request: " << socketName_ ; }
extern "C" void rust_uv_pipe_connect(uv_connect_t *req, uv_pipe_t *handle, char *name, uv_connect_cb cb) { uv_pipe_connect(req, handle, name, cb); }
static void prepare_cb(uv_prepare_t* handle) { ASSERT(handle == &prepare_handle); uv_pipe_connect(&conn_req, &pipe_handle, BAD_PIPENAME, connect_cb); }