event/SocketMonitor: don't close the socket automatically
Users now have to call Close() explicitly. This simplifies using the class, as most users have automatic socket management already, and Steal() had to be used often.
This commit is contained in:
@@ -42,9 +42,6 @@ EventLoop::~EventLoop()
|
||||
{
|
||||
assert(idle.empty());
|
||||
assert(timers.empty());
|
||||
|
||||
/* avoid closing the WakeFD twice */
|
||||
SocketMonitor::Steal();
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -143,7 +143,6 @@ public:
|
||||
i->SetEvents(events);
|
||||
prev = i;
|
||||
} else {
|
||||
i->Steal();
|
||||
fds.erase_after(prev);
|
||||
}
|
||||
}
|
||||
|
@@ -90,6 +90,9 @@ public:
|
||||
|
||||
~OneServerSocket() {
|
||||
g_free(address);
|
||||
|
||||
if (IsDefined())
|
||||
Close();
|
||||
}
|
||||
|
||||
unsigned GetSerial() const {
|
||||
|
@@ -58,14 +58,6 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
~SignalMonitor() {
|
||||
/* prevent the descriptor to be closed twice */
|
||||
#ifdef USE_SIGNALFD
|
||||
if (SocketMonitor::IsDefined())
|
||||
#endif
|
||||
SocketMonitor::Steal();
|
||||
}
|
||||
|
||||
using SocketMonitor::GetEventLoop;
|
||||
|
||||
#ifdef USE_SIGNALFD
|
||||
|
@@ -43,7 +43,7 @@ SocketMonitor::Dispatch(unsigned flags)
|
||||
SocketMonitor::~SocketMonitor()
|
||||
{
|
||||
if (IsDefined())
|
||||
Close();
|
||||
Cancel();
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -44,6 +44,9 @@ class EventLoop;
|
||||
* #EventLoop will invoke virtual method OnSocketReady() as soon as
|
||||
* any of the subscribed events are ready.
|
||||
*
|
||||
* This class does not feel responsible for closing the socket. Call
|
||||
* Close() to do it manually.
|
||||
*
|
||||
* This class is not thread-safe, all methods must be called from the
|
||||
* thread that runs the #EventLoop, except where explicitly documented
|
||||
* as thread-safe.
|
||||
@@ -91,7 +94,7 @@ public:
|
||||
|
||||
/**
|
||||
* "Steal" the socket descriptor. This abandons the socket
|
||||
* and puts the responsibility for closing it to the caller.
|
||||
* and returns it.
|
||||
*/
|
||||
int Steal();
|
||||
|
||||
|
Reference in New Issue
Block a user