Raise UV_ECANCELED on premature close.

Set the error code to the more appropriate UV_ECANCELED instead of UV_EINTR
when the handle is closed and there are in-flight requests.
This commit is contained in:
Ben Noordhuis 2012-07-27 15:13:27 +02:00
parent 9f59e8e38c
commit cf05c5f0d6
8 changed files with 14 additions and 17 deletions

View File

@ -127,7 +127,8 @@ extern "C" {
XX( 54, ENOSPC, "no space left on device") \
XX( 55, EIO, "i/o error") \
XX( 56, EROFS, "read-only file system" ) \
XX( 57, ENODEV, "no such device" )
XX( 57, ENODEV, "no such device" ) \
XX( 58, ECANCELED, "operation canceled" )
#define UV_ERRNO_GEN(val, name, s) UV_##name = val,
@ -436,7 +437,7 @@ UV_EXTERN void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg);
*
* In-progress requests, like uv_connect_t or uv_write_t, are cancelled and
* have their callbacks called asynchronously with status=-1 and the error code
* set to UV_EINTR.
* set to UV_ECANCELED.
*/
UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb);

View File

@ -120,7 +120,7 @@ void uv__stream_destroy(uv_stream_t* stream) {
if (stream->connect_req) {
uv__req_unregister(stream->loop, stream->connect_req);
uv__set_artificial_error(stream->loop, UV_EINTR);
uv__set_artificial_error(stream->loop, UV_ECANCELED);
stream->connect_req->cb(stream->connect_req, -1);
stream->connect_req = NULL;
}
@ -136,7 +136,7 @@ void uv__stream_destroy(uv_stream_t* stream) {
free(req->bufs);
if (req->cb) {
uv__set_artificial_error(req->handle->loop, UV_EINTR);
uv__set_artificial_error(req->handle->loop, UV_ECANCELED);
req->cb(req, -1);
}
}
@ -156,7 +156,7 @@ void uv__stream_destroy(uv_stream_t* stream) {
if (stream->shutdown_req) {
uv__req_unregister(stream->loop, stream->shutdown_req);
uv__set_artificial_error(stream->loop, UV_EINTR);
uv__set_artificial_error(stream->loop, UV_ECANCELED);
stream->shutdown_req->cb(stream->shutdown_req, -1);
stream->shutdown_req = NULL;
}

View File

@ -300,7 +300,7 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
/* Already closing. Cancel the shutdown. */
if (req->cb) {
uv__set_sys_error(loop, WSAEINTR);
uv__set_artificial_error(loop, UV_ECANCELED);
req->cb(req, -1);
}

View File

@ -157,7 +157,6 @@ int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* handle) {
void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {
int status;
int sys_error;
unsigned int i;
uv_tcp_accept_t* req;
@ -169,19 +168,16 @@ void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {
if (handle->flags & UV_HANDLE_CLOSING) {
status = -1;
sys_error = WSAEINTR;
uv__set_artificial_error(loop, UV_ECANCELED);
} else if (shutdown(handle->socket, SD_SEND) != SOCKET_ERROR) {
status = 0;
handle->flags |= UV_HANDLE_SHUT;
} else {
status = -1;
sys_error = WSAGetLastError();
uv__set_sys_error(loop, WSAGetLastError());
}
if (handle->shutdown_req->cb) {
if (status == -1) {
uv__set_sys_error(loop, sys_error);
}
handle->shutdown_req->cb(handle->shutdown_req, status);
}

View File

@ -1751,7 +1751,7 @@ void uv_tty_endgame(uv_loop_t* loop, uv_tty_t* handle) {
/* TTY shutdown is really just a no-op */
if (handle->shutdown_req->cb) {
if (handle->flags & UV_HANDLE_CLOSING) {
uv__set_sys_error(loop, WSAEINTR);
uv__set_artificial_error(loop, UV_ECANCELED);
handle->shutdown_req->cb(handle->shutdown_req, -1);
} else {
handle->shutdown_req->cb(handle->shutdown_req, 0);

View File

@ -91,7 +91,7 @@ static void recv_cb(uv_udp_t* handle,
return;
if (nread == -1) {
ASSERT(uv_last_error(loop).code == UV_EINTR); /* FIXME change error code */
ASSERT(uv_last_error(loop).code == UV_ECANCELED);
return;
}

View File

@ -37,9 +37,9 @@ static int close_cb_called = 0;
static void shutdown_cb(uv_shutdown_t* req, int status) {
int err = uv_last_error(uv_default_loop()).code;
ASSERT(req == &shutdown_req);
ASSERT(status == 0 ||
(status == -1 && uv_last_error(uv_default_loop()).code == UV_EINTR));
ASSERT(status == 0 || (status == -1 && err == UV_ECANCELED));
shutdown_cb_called++;
}

View File

@ -38,7 +38,7 @@ static void close_cb(uv_handle_t* handle) {
static void connect_cb(uv_connect_t* req, int status) {
ASSERT(status == -1);
ASSERT(uv_last_error(req->handle->loop).code == UV_EINTR);
ASSERT(uv_last_error(req->handle->loop).code == UV_ECANCELED);
uv_timer_stop(&timer2_handle);
connect_cb_called++;
}