#include "evthread-internal.h"
#include "time-internal.h"
+/* Since Linux 2.6.17, poll is able to report about peer half-closed connection
+ using special POLLRDHUP flag on a read event.
+*/
+#if !defined(POLLRDHUP)
+#define POLLRDHUP 0
+#define EARLY_CLOSE_IF_HAVE_RDHUP 0
+#else
+#define EARLY_CLOSE_IF_HAVE_RDHUP EV_FEATURE_EARLY_CLOSE
+#endif
+
+
struct pollidx {
int idxplus1;
};
poll_dispatch,
poll_dealloc,
0, /* doesn't need_reinit */
- EV_FEATURE_FDS,
+ EV_FEATURE_FDS|EARLY_CLOSE_IF_HAVE_RDHUP,
sizeof(struct pollidx),
};
res |= EV_READ;
if (what & POLLOUT)
res |= EV_WRITE;
+ if (what & POLLRDHUP)
+ res |= EV_CLOSED;
if (res == 0)
continue;
int i;
EVUTIL_ASSERT((events & EV_SIGNAL) == 0);
- if (!(events & (EV_READ|EV_WRITE)))
+ if (!(events & (EV_READ|EV_WRITE|EV_CLOSED)))
return (0);
poll_check_ok(pop);
pfd->events |= POLLOUT;
if (events & EV_READ)
pfd->events |= POLLIN;
+ if (events & EV_CLOSED)
+ pfd->events |= POLLRDHUP;
poll_check_ok(pop);
return (0);
int i;
EVUTIL_ASSERT((events & EV_SIGNAL) == 0);
- if (!(events & (EV_READ|EV_WRITE)))
+ if (!(events & (EV_READ|EV_WRITE|EV_CLOSED)))
return (0);
poll_check_ok(pop);
pfd->events &= ~POLLIN;
if (events & EV_WRITE)
pfd->events &= ~POLLOUT;
+ if (events & EV_CLOSED)
+ pfd->events &= ~POLLRDHUP;
poll_check_ok(pop);
if (pfd->events)
/* Another event cares about that fd. */