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:
Max Kellermann
2014-01-06 18:02:57 +01:00
parent 0d20130d07
commit 793962c5b8
12 changed files with 20 additions and 21 deletions

View File

@@ -42,9 +42,6 @@ EventLoop::~EventLoop()
{
assert(idle.empty());
assert(timers.empty());
/* avoid closing the WakeFD twice */
SocketMonitor::Steal();
}
void

View File

@@ -143,7 +143,6 @@ public:
i->SetEvents(events);
prev = i;
} else {
i->Steal();
fds.erase_after(prev);
}
}

View File

@@ -90,6 +90,9 @@ public:
~OneServerSocket() {
g_free(address);
if (IsDefined())
Close();
}
unsigned GetSerial() const {

View File

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

View File

@@ -43,7 +43,7 @@ SocketMonitor::Dispatch(unsigned flags)
SocketMonitor::~SocketMonitor()
{
if (IsDefined())
Close();
Cancel();
}
void

View File

@@ -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();