Commit caa2611a authored by Max Kellermann's avatar Max Kellermann

event/SocketEvent: add Abandon()

parent f8ff5979
......@@ -86,6 +86,15 @@ SocketEvent::Schedule(unsigned flags) noexcept
}
void
SocketEvent::Abandon() noexcept
{
if (std::exchange(scheduled_flags, 0) != 0)
loop.AbandonFD(fd.Get());
fd = SocketDescriptor::Undefined();
}
void
SocketEvent::Dispatch() noexcept
{
const unsigned flags = std::exchange(ready_flags, 0) &
......
......@@ -121,6 +121,18 @@ public:
*/
void Close() noexcept;
/**
* Call this instead of Cancel() to unregister this object
* after the underlying socket has already been closed. This
* skips the `EPOLL_CTL_DEL` call because the kernel
* automatically removes closed file descriptors from epoll.
*
* Doing `EPOLL_CTL_DEL` on a closed file descriptor usually
* fails with `-EBADF` or could unregister a different socket
* which happens to be on the same file descriptor number.
*/
void Abandon() noexcept;
unsigned GetScheduledFlags() const noexcept {
return scheduled_flags;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment