diff --git a/src/unix/pipe.c b/src/unix/pipe.c index d332f3518303..b08b85ff11d3 100644 --- a/src/unix/pipe.c +++ b/src/unix/pipe.c @@ -210,7 +210,22 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, const char* name, uv_connect_cb cb) { - uv_pipe_connect2(req, handle, name, strlen(name), 0, cb); + int err; + + err = uv_pipe_connect2(req, handle, name, strlen(name), 0, cb); + + if (err) { + handle->delayed_error = err; + handle->connect_req = req; + + uv__req_init(handle->loop, req, UV_CONNECT); + req->handle = (uv_stream_t*)handle; + req->cb = cb; + uv__queue_init(&req->queue); + + /* Force callback to run on next tick in case of error. */ + uv__io_feed(handle->loop, &handle->io_watcher); + } } diff --git a/src/win/pipe.c b/src/win/pipe.c index cec72ff750b5..c57494185465 100644 --- a/src/win/pipe.c +++ b/src/win/pipe.c @@ -834,7 +834,19 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, const char* name, uv_connect_cb cb) { - uv_pipe_connect2(req, handle, name, strlen(name), 0, cb); + uv_loop_t* loop; + int err; + + err = uv_pipe_connect2(req, handle, name, strlen(name), 0, cb); + + if (err) { + loop = handle->loop; + /* Make this req pending reporting an error. */ + SET_REQ_ERROR(req, err); + uv__insert_pending_req(loop, (uv_req_t*) req); + handle->reqs_pending++; + REGISTER_HANDLE_REQ(loop, handle, req); + } } @@ -844,12 +856,20 @@ int uv_pipe_connect2(uv_connect_t* req, size_t namelen, unsigned int flags, uv_connect_cb cb) { - uv_loop_t* loop = handle->loop; + uv_loop_t* loop; int err; size_t nameSize; HANDLE pipeHandle = INVALID_HANDLE_VALUE; DWORD duplex_flags; + loop = handle->loop; + UV_REQ_INIT(req, UV_CONNECT); + req->handle = (uv_stream_t*) handle; + req->cb = cb; + req->u.connect.pipeHandle = INVALID_HANDLE_VALUE; + req->u.connect.duplex_flags = 0; + req->u.connect.name = NULL; + if (flags & ~UV_PIPE_NO_TRUNCATE) { return UV_EINVAL; } @@ -872,13 +892,6 @@ int uv_pipe_connect2(uv_connect_t* req, } } - UV_REQ_INIT(req, UV_CONNECT); - req->handle = (uv_stream_t*) handle; - req->cb = cb; - req->u.connect.pipeHandle = INVALID_HANDLE_VALUE; - req->u.connect.duplex_flags = 0; - req->u.connect.name = NULL; - if (handle->flags & UV_HANDLE_PIPESERVER) { err = ERROR_INVALID_PARAMETER; goto error;