From f17d4837a8c2e406daa36bce8bd787021a09cef4 Mon Sep 17 00:00:00 2001 From: Igor Zinkovsky Date: Wed, 9 Nov 2011 14:55:34 -0800 Subject: [PATCH] windows: turn WSAECONNABORTED from WSARecv to UV_ECONNRESET --- src/win/tcp.c | 14 ++++++++------ test/test-tcp-write-to-half-open-connection.c | 8 ++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/win/tcp.c b/src/win/tcp.c index f57c825d..5506ede0 100644 --- a/src/win/tcp.c +++ b/src/win/tcp.c @@ -830,9 +830,10 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, err = GET_REQ_SOCK_ERROR(req); if (err == WSAECONNABORTED) { - /* Treat WSAECONNABORTED as connection closed. */ - handle->flags |= UV_HANDLE_EOF; - uv__set_error(loop, UV_EOF, ERROR_SUCCESS); + /* + * Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with Unix. + */ + uv__set_error(loop, UV_ECONNRESET, err); } else { uv__set_sys_error(loop, err); } @@ -898,9 +899,10 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, handle->read_cb((uv_stream_t*)handle, 0, buf); } else { if (err == WSAECONNABORTED) { - /* Treat WSAECONNABORTED as connection closed. */ - handle->flags |= UV_HANDLE_EOF; - uv__set_error(loop, UV_EOF, ERROR_SUCCESS); + /* + * Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with Unix. + */ + uv__set_error(loop, UV_ECONNRESET, err); } else { /* Ouch! serious error. */ uv__set_sys_error(loop, err); diff --git a/test/test-tcp-write-to-half-open-connection.c b/test/test-tcp-write-to-half-open-connection.c index 9e7f553a..26f914b9 100644 --- a/test/test-tcp-write-to-half-open-connection.c +++ b/test/test-tcp-write-to-half-open-connection.c @@ -40,8 +40,6 @@ static uv_write_t write_req; static int write_cb_called; static int read_cb_called; -static int read_eof_cb_called; - static void connection_cb(uv_stream_t* server, int status) { int r; @@ -76,12 +74,11 @@ static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { if (nread == -1) { fprintf(stderr, "read_cb error: %s\n", uv_err_name(uv_last_error(stream->loop))); - ASSERT(uv_last_error(stream->loop).code == UV_EOF); + ASSERT(uv_last_error(stream->loop).code == UV_ECONNRESET || + uv_last_error(stream->loop).code == UV_EOF); uv_close((uv_handle_t*)&tcp_server, NULL); uv_close((uv_handle_t*)&tcp_peer, NULL); - - read_eof_cb_called++; } read_cb_called++; @@ -133,7 +130,6 @@ TEST_IMPL(tcp_write_to_half_open_connection) { ASSERT(write_cb_called > 0); ASSERT(read_cb_called > 0); - ASSERT(read_eof_cb_called > 0); return 0; }