Skip to content

Commit b19a0fb

Browse files
committed
event/SocketEvent: add EPOLLRDHUP support
1 parent 6503e62 commit b19a0fb

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/event/EpollEvents.hxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ struct EpollEvents {
1010
static constexpr unsigned WRITE = EPOLLOUT;
1111
static constexpr unsigned ERROR = EPOLLERR;
1212
static constexpr unsigned HANGUP = EPOLLHUP;
13+
static constexpr unsigned READ_HANGUP = EPOLLRDHUP;
1314

1415
/**
1516
* A mask containing all events which indicate a dead socket
1617
* connection (i.e. error or hangup). It may still be
1718
* possible to receive pending data from the socket buffer.
1819
*/
19-
static constexpr unsigned DEAD_MASK = ERROR|HANGUP;
20+
static constexpr unsigned DEAD_MASK = ERROR|HANGUP|READ_HANGUP;
2021
};

src/event/SocketEvent.hxx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include "BackendEvents.hxx"
7+
#include "event/Features.h" // for USE_EPOLL
78
#include "net/SocketDescriptor.hxx"
89
#include "util/BindMethod.hxx"
910
#include "util/IntrusiveList.hxx"
@@ -175,6 +176,18 @@ public:
175176
Schedule(IMPLICIT_FLAGS);
176177
}
177178

179+
#ifdef USE_EPOLL
180+
/**
181+
* Cancel READ but schedule READ_HANGUP. This is useful to be
182+
* able to detect hangup while we're not interested in reading
183+
* further data from the socket; in that case, the Linux
184+
* kernel will not report HANGUP.
185+
*/
186+
void CancelReadAndScheduleReadHangup() noexcept {
187+
Schedule((GetScheduledFlags() & ~READ) | READ_HANGUP);
188+
}
189+
#endif
190+
178191
bool IsReadPending() const noexcept {
179192
return GetScheduledFlags() & READ;
180193
}

0 commit comments

Comments
 (0)