event/SocketMonitor: add method Abandon()

This commit is contained in:
Max Kellermann 2013-11-06 18:20:51 +01:00
parent ed436c6f0c
commit 154bdf0bca
4 changed files with 32 additions and 2 deletions

View File

@ -58,13 +58,18 @@ EventLoop::Break()
AddCall([this]() { Break(); });
}
bool
EventLoop::RemoveFD(int _fd, SocketMonitor &m)
void
EventLoop::Abandon(SocketMonitor &m)
{
for (unsigned i = 0, n = n_events; i < n; ++i)
if (events[i].data.ptr == &m)
events[i].events = 0;
}
bool
EventLoop::RemoveFD(int _fd, SocketMonitor &m)
{
Abandon(m);
return epoll.Remove(_fd);
}

View File

@ -121,6 +121,13 @@ public:
return epoll.Modify(_fd, flags, &m);
}
/**
* Remove the given #SocketMonitor after the file descriptor
* has been closed. This is like RemoveFD(), but does not
* attempt to use #EPOLL_CTL_DEL.
*/
void Abandon(SocketMonitor &m);
bool RemoveFD(int fd, SocketMonitor &m);
void AddIdle(IdleMonitor &i);

View File

@ -151,6 +151,19 @@ SocketMonitor::Steal()
return result;
}
void
SocketMonitor::Abandon()
{
assert(IsDefined());
#ifdef USE_EPOLL
fd = -1;
loop.Abandon(*this);
#else
Steal();
#endif
}
void
SocketMonitor::Close()
{

View File

@ -118,6 +118,11 @@ public:
*/
int Steal();
/**
* Somebody has closed the socket. Unregister this object.
*/
void Abandon();
void Close();
unsigned GetScheduledFlags() const {