Win: ignore ECONNRESET when receiving udp packets

This commit is contained in:
Bert Belder 2011-11-24 19:13:46 +01:00
parent 261d792a7a
commit ea63f06987

View File

@ -466,17 +466,31 @@ void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle,
handle->flags &= ~UV_HANDLE_READ_PENDING;
if (!REQ_SUCCESS(req) &&
GET_REQ_SOCK_ERROR(req) != WSAEMSGSIZE) {
/* An error occurred doing the read. */
if (handle->flags & UV_HANDLE_READING) {
uv__set_sys_error(loop, GET_REQ_SOCK_ERROR(req));
uv_udp_recv_stop(handle);
buf = (handle->flags & UV_HANDLE_ZERO_READ) ?
uv_buf_init(NULL, 0) : handle->recv_buffer;
handle->recv_cb(handle, -1, buf, NULL, 0);
if (!REQ_SUCCESS(req)) {
DWORD err = GET_REQ_SOCK_ERROR(req);
if (err == WSAEMSGSIZE) {
/* Not a real error, it just indicates that the received packet */
/* was bigger than the receive buffer. */
} else if (err == WSAECONNRESET || err == WSAENETRESET) {
/* A previous sendto operation failed; ignore this error. If */
/* zero-reading we need to call WSARecv/WSARecvFrom _without_ the */
/* MSG_PEEK flag to clear out the error queue. For nonzero reads, */
/* immediately queue a new receive. */
if (!(handle->flags & UV_HANDLE_ZERO_READ)) {
goto done;
}
} else {
/* A real error occurred. Report the error to the user only if we're */
/* currently reading. */
if (handle->flags & UV_HANDLE_READING) {
uv__set_sys_error(loop, err);
uv_udp_recv_stop(handle);
buf = (handle->flags & UV_HANDLE_ZERO_READ) ?
uv_buf_init(NULL, 0) : handle->recv_buffer;
handle->recv_cb(handle, -1, buf, NULL, 0);
}
goto done;
}
goto done;
}
if (!(handle->flags & UV_HANDLE_ZERO_READ)) {
@ -527,8 +541,10 @@ void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle,
/* Kernel buffer empty */
uv__set_sys_error(loop, WSAEWOULDBLOCK);
handle->recv_cb(handle, 0, buf, NULL, 0);
} else {
/* Ouch! serious error. */
} else if (err != WSAECONNRESET && err != WSAENETRESET) {
/* Serious error. WSAECONNRESET/WSANETRESET is ignored because this */
/* just indicates that a previous sendto operation failed. */
uv_udp_recv_stop(handle);
uv__set_sys_error(loop, err);
handle->recv_cb(handle, -1, buf, NULL, 0);
}