diff options
author | Max Kellermann <max@duempel.org> | 2014-01-06 18:02:57 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-06 18:26:55 +0100 |
commit | 793962c5b86cd063036a2d28907b0b33012483e1 (patch) | |
tree | 39531d85b0ab2bf480f74c74da788e566991ee25 /src | |
parent | 0d20130d07d69bb8ac4392af8f2ed25e5ea0bbad (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/AvahiPoll.cxx | 4 | ||||
-rw-r--r-- | src/Client.hxx | 5 | ||||
-rw-r--r-- | src/InotifySource.hxx | 4 | ||||
-rw-r--r-- | src/ZeroconfBonjour.cxx | 1 | ||||
-rw-r--r-- | src/event/Loop.cxx | 3 | ||||
-rw-r--r-- | src/event/MultiSocketMonitor.hxx | 1 | ||||
-rw-r--r-- | src/event/ServerSocket.cxx | 3 | ||||
-rw-r--r-- | src/event/SignalMonitor.cxx | 8 | ||||
-rw-r--r-- | src/event/SocketMonitor.cxx | 2 | ||||
-rw-r--r-- | src/event/SocketMonitor.hxx | 5 | ||||
-rw-r--r-- | src/input/CurlInputPlugin.cxx | 2 | ||||
-rw-r--r-- | src/output/HttpdClient.cxx | 3 |
12 files changed, 20 insertions, 21 deletions
diff --git a/src/AvahiPoll.cxx b/src/AvahiPoll.cxx index d6f8b9f79..de0f2b1e3 100644 --- a/src/AvahiPoll.cxx +++ b/src/AvahiPoll.cxx @@ -57,10 +57,6 @@ public: Schedule(FromAvahiWatchEvent(_event)); } - ~AvahiWatch() { - Steal(); - } - static void WatchUpdate(AvahiWatch *w, AvahiWatchEvent event) { w->Schedule(FromAvahiWatchEvent(event)); } diff --git a/src/Client.hxx b/src/Client.hxx index c794bf0ee..202cff4da 100644 --- a/src/Client.hxx +++ b/src/Client.hxx @@ -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(); } diff --git a/src/InotifySource.hxx b/src/InotifySource.hxx index 026b156e6..e2ce9301e 100644 --- a/src/InotifySource.hxx +++ b/src/InotifySource.hxx @@ -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. diff --git a/src/ZeroconfBonjour.cxx b/src/ZeroconfBonjour.cxx index 73e84fbc2..7aebd0514 100644 --- a/src/ZeroconfBonjour.cxx +++ b/src/ZeroconfBonjour.cxx @@ -43,7 +43,6 @@ public: } ~BonjourMonitor() { - Steal(); DNSServiceRefDeallocate(service_ref); } diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx index 58c25e040..6281b09ec 100644 --- a/src/event/Loop.cxx +++ b/src/event/Loop.cxx @@ -42,9 +42,6 @@ EventLoop::~EventLoop() { assert(idle.empty()); assert(timers.empty()); - - /* avoid closing the WakeFD twice */ - SocketMonitor::Steal(); } void diff --git a/src/event/MultiSocketMonitor.hxx b/src/event/MultiSocketMonitor.hxx index d6ad3b177..963745be1 100644 --- a/src/event/MultiSocketMonitor.hxx +++ b/src/event/MultiSocketMonitor.hxx @@ -143,7 +143,6 @@ public: i->SetEvents(events); prev = i; } else { - i->Steal(); fds.erase_after(prev); } } diff --git a/src/event/ServerSocket.cxx b/src/event/ServerSocket.cxx index a05d7bde2..64e38776f 100644 --- a/src/event/ServerSocket.cxx +++ b/src/event/ServerSocket.cxx @@ -90,6 +90,9 @@ public: ~OneServerSocket() { g_free(address); + + if (IsDefined()) + Close(); } unsigned GetSerial() const { diff --git a/src/event/SignalMonitor.cxx b/src/event/SignalMonitor.cxx index bb75f49a3..eac011616 100644 --- a/src/event/SignalMonitor.cxx +++ b/src/event/SignalMonitor.cxx @@ -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 diff --git a/src/event/SocketMonitor.cxx b/src/event/SocketMonitor.cxx index 92693949f..ef2128684 100644 --- a/src/event/SocketMonitor.cxx +++ b/src/event/SocketMonitor.cxx @@ -43,7 +43,7 @@ SocketMonitor::Dispatch(unsigned flags) SocketMonitor::~SocketMonitor() { if (IsDefined()) - Close(); + Cancel(); } void diff --git a/src/event/SocketMonitor.hxx b/src/event/SocketMonitor.hxx index 3a84dc094..d0fcf1b57 100644 --- a/src/event/SocketMonitor.hxx +++ b/src/event/SocketMonitor.hxx @@ -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(); diff --git a/src/input/CurlInputPlugin.cxx b/src/input/CurlInputPlugin.cxx index fa8f9affc..3b73597de 100644 --- a/src/input/CurlInputPlugin.cxx +++ b/src/input/CurlInputPlugin.cxx @@ -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(); } /** diff --git a/src/output/HttpdClient.cxx b/src/output/HttpdClient.cxx index c0b2429d2..102ce1ec3 100644 --- a/src/output/HttpdClient.cxx +++ b/src/output/HttpdClient.cxx @@ -42,6 +42,9 @@ HttpdClient::~HttpdClient() if (metadata) metadata->Unref(); + + if (IsDefined()) + BufferedSocket::Close(); } void |