Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
windows: turn WSAECONNABORTED from WSARecv to UV_ECONNRESET
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky committed Nov 9, 2011
1 parent 4794c12 commit f17d483
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
14 changes: 8 additions & 6 deletions src/win/tcp.c
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions test/test-tcp-write-to-half-open-connection.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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;
}

0 comments on commit f17d483

Please sign in to comment.