Skip to content

Commit

Permalink
socket: Return -ECONNRESET from socket_receive_timeout() instead of -…
Browse files Browse the repository at this point in the history
…EAGAIN if peer closed the socket

Returning -EAGAIN would indicate the caller can try again, but if the peer
closed the socket that wouldn't make any sense. Thanks to sctol for reporting.
  • Loading branch information
nikias committed May 20, 2019
1 parent cf265a8 commit 9efb174
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion common/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ static int wsa_init = 0;
#define RECV_TIMEOUT 20000
#define CONNECT_TIMEOUT 5000

#ifndef ECONNRESET
#define ECONNRESET 108
#endif

static int verbose = 0;

void socket_set_verbose(int level)
Expand Down Expand Up @@ -475,7 +479,7 @@ int socket_receive_timeout(int fd, void *data, size_t length, int flags,
// but this is an error condition
if (verbose >= 3)
fprintf(stderr, "%s: fd=%d recv returned 0\n", __func__, fd);
return -EAGAIN;
return -ECONNRESET;
}
if (result < 0) {
return -errno;
Expand Down

0 comments on commit 9efb174

Please sign in to comment.