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

@ -57,10 +57,6 @@ public:
Schedule(FromAvahiWatchEvent(_event));
}
~AvahiWatch() {
Steal();
}
static void WatchUpdate(AvahiWatch *w, AvahiWatchEvent event) {
w->Schedule(FromAvahiWatchEvent(event));
}

View File

@ -82,6 +82,11 @@ public:
Client(EventLoop &loop, Partition &partition,
int fd, int uid, int num);
~Client() {
if (FullyBufferedSocket::IsDefined())
FullyBufferedSocket::Close();
}
bool IsConnected() const {
return FullyBufferedSocket::IsDefined();
}

View File

@ -38,6 +38,10 @@ class InotifySource final : private SocketMonitor {
mpd_inotify_callback_t callback, void *ctx, int fd);
public:
~InotifySource() {
Close();
}
/**
* Creates a new inotify source and registers it in the GLib main
* loop.

View File

@ -43,7 +43,6 @@ public:
}
~BonjourMonitor() {
Steal();
DNSServiceRefDeallocate(service_ref);
}

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

View File

@ -200,8 +200,6 @@ public:
Abandon() would be most appropriate, but it breaks
the second case - is that a CURL bug? is there a
better solution? */
Steal();
}
/**

View File

@ -42,6 +42,9 @@ HttpdClient::~HttpdClient()
if (metadata)
metadata->Unref();
if (IsDefined())
BufferedSocket::Close();
}
void