pipe: add back error handling to connect / bind (#4202)
This was incorrectly dropped by #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.
This commit is contained in:
parent
e135dfe183
commit
d843b7cf7f
@ -210,7 +210,22 @@ void uv_pipe_connect(uv_connect_t* req,
|
|||||||
uv_pipe_t* handle,
|
uv_pipe_t* handle,
|
||||||
const char* name,
|
const char* name,
|
||||||
uv_connect_cb cb) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -834,7 +834,19 @@ void uv_pipe_connect(uv_connect_t* req,
|
|||||||
uv_pipe_t* handle,
|
uv_pipe_t* handle,
|
||||||
const char* name,
|
const char* name,
|
||||||
uv_connect_cb cb) {
|
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,
|
size_t namelen,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
uv_connect_cb cb) {
|
uv_connect_cb cb) {
|
||||||
uv_loop_t* loop = handle->loop;
|
uv_loop_t* loop;
|
||||||
int err;
|
int err;
|
||||||
size_t nameSize;
|
size_t nameSize;
|
||||||
HANDLE pipeHandle = INVALID_HANDLE_VALUE;
|
HANDLE pipeHandle = INVALID_HANDLE_VALUE;
|
||||||
DWORD duplex_flags;
|
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) {
|
if (flags & ~UV_PIPE_NO_TRUNCATE) {
|
||||||
return UV_EINVAL;
|
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) {
|
if (handle->flags & UV_HANDLE_PIPESERVER) {
|
||||||
err = ERROR_INVALID_PARAMETER;
|
err = ERROR_INVALID_PARAMETER;
|
||||||
goto error;
|
goto error;
|
||||||
|
|||||||
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
|
|
||||||
static int close_cb_called = 0;
|
static int close_cb_called = 0;
|
||||||
|
static int connect_cb_called = 0;
|
||||||
|
|
||||||
|
|
||||||
static void close_cb(uv_handle_t* handle) {
|
static void close_cb(uv_handle_t* handle) {
|
||||||
@ -154,6 +155,14 @@ TEST_IMPL(pipe_bind_or_listen_error_after_close) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void connect_overlong_cb(uv_connect_t* connect_req, int status) {
|
||||||
|
ASSERT_EQ(status, UV_EINVAL);
|
||||||
|
connect_cb_called++;
|
||||||
|
uv_close((uv_handle_t*) connect_req->handle, close_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_IMPL(pipe_overlong_path) {
|
TEST_IMPL(pipe_overlong_path) {
|
||||||
char path[512];
|
char path[512];
|
||||||
uv_pipe_t pipe;
|
uv_pipe_t pipe;
|
||||||
@ -170,9 +179,17 @@ TEST_IMPL(pipe_overlong_path) {
|
|||||||
sizeof(path),
|
sizeof(path),
|
||||||
UV_PIPE_NO_TRUNCATE,
|
UV_PIPE_NO_TRUNCATE,
|
||||||
(uv_connect_cb) abort));
|
(uv_connect_cb) abort));
|
||||||
uv_close((uv_handle_t*) &pipe, NULL);
|
|
||||||
ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
|
ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
|
||||||
|
|
||||||
|
ASSERT_EQ(UV_EINVAL, uv_pipe_bind(&pipe, ""));
|
||||||
|
uv_pipe_connect(&req,
|
||||||
|
&pipe,
|
||||||
|
"",
|
||||||
|
(uv_connect_cb) connect_overlong_cb);
|
||||||
|
ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
|
||||||
|
ASSERT_EQ(1, connect_cb_called);
|
||||||
|
ASSERT_EQ(1, close_cb_called);
|
||||||
|
|
||||||
MAKE_VALGRIND_HAPPY(uv_default_loop());
|
MAKE_VALGRIND_HAPPY(uv_default_loop());
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user