event/SocketMonitor: add method Abandon()
This commit is contained in:
parent
ed436c6f0c
commit
154bdf0bca
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -118,6 +118,11 @@ public:
|
|||
*/
|
||||
int Steal();
|
||||
|
||||
/**
|
||||
* Somebody has closed the socket. Unregister this object.
|
||||
*/
|
||||
void Abandon();
|
||||
|
||||
void Close();
|
||||
|
||||
unsigned GetScheduledFlags() const {
|
||||
|
|
Loading…
Reference in New Issue