aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/event/SocketMonitor.cxx14
-rw-r--r--src/event/SocketMonitor.hxx6
2 files changed, 17 insertions, 3 deletions
diff --git a/src/event/SocketMonitor.cxx b/src/event/SocketMonitor.cxx
index b75dc72a4..57364c883 100644
--- a/src/event/SocketMonitor.cxx
+++ b/src/event/SocketMonitor.cxx
@@ -105,17 +105,25 @@ SocketMonitor::Open(int _fd)
g_source_add_poll(&source->base, &poll);
}
-void
-SocketMonitor::Close()
+int
+SocketMonitor::Steal()
{
assert(IsDefined());
Cancel();
- close_socket(fd);
+ int result = fd;
fd = -1;
g_source_destroy(&source->base);
g_source_unref(&source->base);
source = nullptr;
+
+ return result;
+}
+
+void
+SocketMonitor::Close()
+{
+ close_socket(Steal());
}
diff --git a/src/event/SocketMonitor.hxx b/src/event/SocketMonitor.hxx
index 236e5fbda..ddfc21a42 100644
--- a/src/event/SocketMonitor.hxx
+++ b/src/event/SocketMonitor.hxx
@@ -73,6 +73,12 @@ public:
void Open(int _fd);
+ /**
+ * "Steal" the socket descriptor. This abandons the socket
+ * and puts the responsibility for closing it to the caller.
+ */
+ int Steal();
+
void Close();
void Schedule(unsigned flags) {