Commit 068f191c authored by Max Kellermann's avatar Max Kellermann

event/SocketMonitor: add method Steal()

parent 6bf6c921
...@@ -105,17 +105,25 @@ SocketMonitor::Open(int _fd) ...@@ -105,17 +105,25 @@ SocketMonitor::Open(int _fd)
g_source_add_poll(&source->base, &poll); g_source_add_poll(&source->base, &poll);
} }
void int
SocketMonitor::Close() SocketMonitor::Steal()
{ {
assert(IsDefined()); assert(IsDefined());
Cancel(); Cancel();
close_socket(fd); int result = fd;
fd = -1; fd = -1;
g_source_destroy(&source->base); g_source_destroy(&source->base);
g_source_unref(&source->base); g_source_unref(&source->base);
source = nullptr; source = nullptr;
return result;
}
void
SocketMonitor::Close()
{
close_socket(Steal());
} }
...@@ -73,6 +73,12 @@ public: ...@@ -73,6 +73,12 @@ public:
void Open(int _fd); 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 Close();
void Schedule(unsigned flags) { void Schedule(unsigned flags) {
......
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