Skip to content

Commit

Permalink
stream: squelch ECONNRESET error if already closed
Browse files Browse the repository at this point in the history
  • Loading branch information
santigimeno committed Jun 18, 2015
1 parent 70bbfa0 commit 3e5eeb9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/unix/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@
#endif

#if defined(__linux__)
# define UV__POLLIN UV__EPOLLIN
# define UV__POLLOUT UV__EPOLLOUT
# define UV__POLLERR UV__EPOLLERR
# define UV__POLLHUP UV__EPOLLHUP
# define UV__POLLIN UV__EPOLLIN
# define UV__POLLOUT UV__EPOLLOUT
# define UV__POLLERR UV__EPOLLERR
# define UV__POLLHUP UV__EPOLLHUP
# define UV__POLLRDHUP UV__EPOLLRDHUP
#endif

#if defined(__sun) || defined(_AIX)
Expand All @@ -118,6 +119,10 @@
# define UV__POLLHUP 8
#endif

#ifndef UV__POLLRDHUP
# define UV__POLLRDHUP 16

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Jun 18, 2015

16 is probably a bad value, it's POLLHUP on the BSDs.

This comment has been minimized.

Copy link
@santigimeno

santigimeno Jun 18, 2015

Author Owner

I'll use 0x200 that apparently is free

#endif

#if !defined(O_CLOEXEC) && defined(__FreeBSD__)
/*
* It may be that we are just missing `__POSIX_VISIBLE >= 200809`.
Expand All @@ -143,6 +148,7 @@ enum {
UV_TCP_NODELAY = 0x400, /* Disable Nagle. */
UV_TCP_KEEPALIVE = 0x800, /* Turn on keep-alive. */
UV_TCP_SINGLE_ACCEPT = 0x1000, /* Only accept() when idle. */
UV_STREAM_DISCONNECT = 0x2000, /* Remote end is forcibly closed */
UV_HANDLE_IPV6 = 0x10000, /* Handle is bound to a IPv6 socket. */
UV_UDP_PROCESSING = 0x20000 /* Handle is running the send callback queue. */
};
Expand Down
3 changes: 3 additions & 0 deletions src/unix/kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
if (ev->flags & EV_ERROR)
revents |= UV__POLLERR;

if (ev->flags & EV_EOF)
revents |= UV__POLLRDHUP;

if (revents == 0)
continue;

Expand Down
4 changes: 2 additions & 2 deletions src/unix/linux-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
assert(w->fd >= 0);
assert(w->fd < (int) loop->nwatchers);

e.events = w->pevents;
e.events = w->pevents | UV__POLLRDHUP;
e.data = w->fd;

if (w->events == 0)
Expand Down Expand Up @@ -321,7 +321,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
* the current watcher. Also, filters out events that users has not
* requested us to watch.
*/
pe->events &= w->pevents | UV__POLLERR | UV__POLLHUP;
pe->events &= w->pevents | UV__POLLERR | UV__POLLHUP | UV__POLLRDHUP;

/* Work around an epoll quirk where it sometimes reports just the
* EPOLLERR or EPOLLHUP event. In order to force the event loop to
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux-syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#define UV__EPOLLOUT 4
#define UV__EPOLLERR 8
#define UV__EPOLLHUP 16
#define UV__EPOLLRDHUP 0x2000
#define UV__EPOLLONESHOT 0x40000000
#define UV__EPOLLET 0x80000000

Expand Down
12 changes: 11 additions & 1 deletion src/unix/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,11 @@ static void uv__read(uv_stream_t* stream) {
}
stream->read_cb(stream, 0, &buf);
} else {
if ((errno == ECONNRESET) && (stream->flags & UV_STREAM_DISCONNECT)) {
uv__stream_eof(stream, &buf);
return;
}

/* Error. User should call uv_close(). */
stream->read_cb(stream, -errno, &buf);
if (stream->flags & UV_STREAM_READING) {
Expand Down Expand Up @@ -1227,8 +1232,13 @@ static void uv__stream_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
assert(uv__stream_fd(stream) >= 0);

/* Ignore POLLHUP here. Even it it's set, there may still be data to read. */
if (events & (UV__POLLIN | UV__POLLERR | UV__POLLHUP))
if (events & (UV__POLLIN | UV__POLLERR | UV__POLLHUP)) {

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Jun 18, 2015

Don't you need to include UV__POLLRDHUP here as well?

This comment has been minimized.

Copy link
@santigimeno

santigimeno Jun 18, 2015

Author Owner

Yes, you're right

if (events & UV__POLLRDHUP) {
stream->flags |= UV_STREAM_DISCONNECT;
}

uv__read(stream);
}

if (uv__stream_fd(stream) == -1)
return; /* read_cb closed stream. */
Expand Down

0 comments on commit 3e5eeb9

Please sign in to comment.