Skip to content

Commit b7800d5

Browse files
committed
pipe: add back error handling to connect / bind
This was incorrectly dropped by libuv#4030, where previously connecting to "" might fail eventually, now instead it would return EINVAL and then fail to initialize the struct or call the callback.
1 parent aa4f864 commit b7800d5

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

src/unix/pipe.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,22 @@ void uv_pipe_connect(uv_connect_t* req,
210210
uv_pipe_t* handle,
211211
const char* name,
212212
uv_connect_cb cb) {
213-
uv_pipe_connect2(req, handle, name, strlen(name), 0, cb);
213+
int err;
214+
215+
err = uv_pipe_connect2(req, handle, name, strlen(name), 0, cb);
216+
217+
if (err) {
218+
handle->delayed_error = err;
219+
handle->connect_req = req;
220+
221+
uv__req_init(handle->loop, req, UV_CONNECT);
222+
req->handle = (uv_stream_t*) handle;
223+
req->cb = cb;
224+
uv__queue_init(&req->queue);
225+
226+
/* Force callback to run on next tick in case of error. */
227+
uv__io_feed(handle->loop, &handle->io_watcher);
228+
}
214229
}
215230

216231

@@ -295,7 +310,7 @@ int uv_pipe_connect2(uv_connect_t* req,
295310
handle->connect_req = req;
296311

297312
uv__req_init(handle->loop, req, UV_CONNECT);
298-
req->handle = (uv_stream_t*)handle;
313+
req->handle = (uv_stream_t*) handle;
299314
req->cb = cb;
300315
uv__queue_init(&req->queue);
301316

src/win/pipe.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,19 @@ void uv_pipe_connect(uv_connect_t* req,
834834
uv_pipe_t* handle,
835835
const char* name,
836836
uv_connect_cb cb) {
837-
uv_pipe_connect2(req, handle, name, strlen(name), 0, cb);
837+
uv_loop_t* loop;
838+
int err;
839+
840+
err = uv_pipe_connect2(req, handle, name, strlen(name), 0, cb);
841+
842+
if (err) {
843+
loop = handle->loop;
844+
/* Make this req pending reporting an error. */
845+
SET_REQ_ERROR(req, err);
846+
uv__insert_pending_req(loop, (uv_req_t*) req);
847+
handle->reqs_pending++;
848+
REGISTER_HANDLE_REQ(loop, handle, req);
849+
}
838850
}
839851

840852

@@ -844,12 +856,20 @@ int uv_pipe_connect2(uv_connect_t* req,
844856
size_t namelen,
845857
unsigned int flags,
846858
uv_connect_cb cb) {
847-
uv_loop_t* loop = handle->loop;
859+
uv_loop_t* loop;
848860
int err;
849861
size_t nameSize;
850862
HANDLE pipeHandle = INVALID_HANDLE_VALUE;
851863
DWORD duplex_flags;
852864

865+
loop = handle->loop;
866+
UV_REQ_INIT(req, UV_CONNECT);
867+
req->handle = (uv_stream_t*) handle;
868+
req->cb = cb;
869+
req->u.connect.pipeHandle = INVALID_HANDLE_VALUE;
870+
req->u.connect.duplex_flags = 0;
871+
req->u.connect.name = NULL;
872+
853873
if (flags & ~UV_PIPE_NO_TRUNCATE) {
854874
return UV_EINVAL;
855875
}
@@ -872,13 +892,6 @@ int uv_pipe_connect2(uv_connect_t* req,
872892
}
873893
}
874894

875-
UV_REQ_INIT(req, UV_CONNECT);
876-
req->handle = (uv_stream_t*) handle;
877-
req->cb = cb;
878-
req->u.connect.pipeHandle = INVALID_HANDLE_VALUE;
879-
req->u.connect.duplex_flags = 0;
880-
req->u.connect.name = NULL;
881-
882895
if (handle->flags & UV_HANDLE_PIPESERVER) {
883896
err = ERROR_INVALID_PARAMETER;
884897
goto error;

0 commit comments

Comments
 (0)