event/SocketEvent: add Abandon()

This commit is contained in:
Max Kellermann 2020-10-15 16:55:43 +02:00
parent f8ff597963
commit caa2611ad5
2 changed files with 21 additions and 0 deletions

View File

@ -85,6 +85,15 @@ SocketEvent::Schedule(unsigned flags) noexcept
return success;
}
void
SocketEvent::Abandon() noexcept
{
if (std::exchange(scheduled_flags, 0) != 0)
loop.AbandonFD(fd.Get());
fd = SocketDescriptor::Undefined();
}
void
SocketEvent::Dispatch() noexcept
{

View File

@ -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;
}