Commit 793962c5 authored by Max Kellermann's avatar Max Kellermann

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.
parent 0d20130d
......@@ -57,10 +57,6 @@ public:
Schedule(FromAvahiWatchEvent(_event));
}
~AvahiWatch() {
Steal();
}
static void WatchUpdate(AvahiWatch *w, AvahiWatchEvent event) {
w->Schedule(FromAvahiWatchEvent(event));
}
......
......@@ -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();
}
......
......@@ -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.
......
......@@ -43,7 +43,6 @@ public:
}
~BonjourMonitor() {
Steal();
DNSServiceRefDeallocate(service_ref);
}
......
......@@ -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();
......
......@@ -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();
}
/**
......
......@@ -42,6 +42,9 @@ HttpdClient::~HttpdClient()
if (metadata)
metadata->Unref();
if (IsDefined())
BufferedSocket::Close();
}
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment