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:
parent
0d20130d07
commit
793962c5b8
@ -57,10 +57,6 @@ public:
|
|||||||
Schedule(FromAvahiWatchEvent(_event));
|
Schedule(FromAvahiWatchEvent(_event));
|
||||||
}
|
}
|
||||||
|
|
||||||
~AvahiWatch() {
|
|
||||||
Steal();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void WatchUpdate(AvahiWatch *w, AvahiWatchEvent event) {
|
static void WatchUpdate(AvahiWatch *w, AvahiWatchEvent event) {
|
||||||
w->Schedule(FromAvahiWatchEvent(event));
|
w->Schedule(FromAvahiWatchEvent(event));
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,11 @@ public:
|
|||||||
Client(EventLoop &loop, Partition &partition,
|
Client(EventLoop &loop, Partition &partition,
|
||||||
int fd, int uid, int num);
|
int fd, int uid, int num);
|
||||||
|
|
||||||
|
~Client() {
|
||||||
|
if (FullyBufferedSocket::IsDefined())
|
||||||
|
FullyBufferedSocket::Close();
|
||||||
|
}
|
||||||
|
|
||||||
bool IsConnected() const {
|
bool IsConnected() const {
|
||||||
return FullyBufferedSocket::IsDefined();
|
return FullyBufferedSocket::IsDefined();
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,10 @@ class InotifySource final : private SocketMonitor {
|
|||||||
mpd_inotify_callback_t callback, void *ctx, int fd);
|
mpd_inotify_callback_t callback, void *ctx, int fd);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
~InotifySource() {
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new inotify source and registers it in the GLib main
|
* Creates a new inotify source and registers it in the GLib main
|
||||||
* loop.
|
* loop.
|
||||||
|
@ -43,7 +43,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~BonjourMonitor() {
|
~BonjourMonitor() {
|
||||||
Steal();
|
|
||||||
DNSServiceRefDeallocate(service_ref);
|
DNSServiceRefDeallocate(service_ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,9 +42,6 @@ EventLoop::~EventLoop()
|
|||||||
{
|
{
|
||||||
assert(idle.empty());
|
assert(idle.empty());
|
||||||
assert(timers.empty());
|
assert(timers.empty());
|
||||||
|
|
||||||
/* avoid closing the WakeFD twice */
|
|
||||||
SocketMonitor::Steal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -143,7 +143,6 @@ public:
|
|||||||
i->SetEvents(events);
|
i->SetEvents(events);
|
||||||
prev = i;
|
prev = i;
|
||||||
} else {
|
} else {
|
||||||
i->Steal();
|
|
||||||
fds.erase_after(prev);
|
fds.erase_after(prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,9 @@ public:
|
|||||||
|
|
||||||
~OneServerSocket() {
|
~OneServerSocket() {
|
||||||
g_free(address);
|
g_free(address);
|
||||||
|
|
||||||
|
if (IsDefined())
|
||||||
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned GetSerial() const {
|
unsigned GetSerial() const {
|
||||||
|
@ -58,14 +58,6 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
~SignalMonitor() {
|
|
||||||
/* prevent the descriptor to be closed twice */
|
|
||||||
#ifdef USE_SIGNALFD
|
|
||||||
if (SocketMonitor::IsDefined())
|
|
||||||
#endif
|
|
||||||
SocketMonitor::Steal();
|
|
||||||
}
|
|
||||||
|
|
||||||
using SocketMonitor::GetEventLoop;
|
using SocketMonitor::GetEventLoop;
|
||||||
|
|
||||||
#ifdef USE_SIGNALFD
|
#ifdef USE_SIGNALFD
|
||||||
|
@ -43,7 +43,7 @@ SocketMonitor::Dispatch(unsigned flags)
|
|||||||
SocketMonitor::~SocketMonitor()
|
SocketMonitor::~SocketMonitor()
|
||||||
{
|
{
|
||||||
if (IsDefined())
|
if (IsDefined())
|
||||||
Close();
|
Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -44,6 +44,9 @@ class EventLoop;
|
|||||||
* #EventLoop will invoke virtual method OnSocketReady() as soon as
|
* #EventLoop will invoke virtual method OnSocketReady() as soon as
|
||||||
* any of the subscribed events are ready.
|
* 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
|
* This class is not thread-safe, all methods must be called from the
|
||||||
* thread that runs the #EventLoop, except where explicitly documented
|
* thread that runs the #EventLoop, except where explicitly documented
|
||||||
* as thread-safe.
|
* as thread-safe.
|
||||||
@ -91,7 +94,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* "Steal" the socket descriptor. This abandons the socket
|
* "Steal" the socket descriptor. This abandons the socket
|
||||||
* and puts the responsibility for closing it to the caller.
|
* and returns it.
|
||||||
*/
|
*/
|
||||||
int Steal();
|
int Steal();
|
||||||
|
|
||||||
|
@ -200,8 +200,6 @@ public:
|
|||||||
Abandon() would be most appropriate, but it breaks
|
Abandon() would be most appropriate, but it breaks
|
||||||
the second case - is that a CURL bug? is there a
|
the second case - is that a CURL bug? is there a
|
||||||
better solution? */
|
better solution? */
|
||||||
|
|
||||||
Steal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,6 +42,9 @@ HttpdClient::~HttpdClient()
|
|||||||
|
|
||||||
if (metadata)
|
if (metadata)
|
||||||
metadata->Unref();
|
metadata->Unref();
|
||||||
|
|
||||||
|
if (IsDefined())
|
||||||
|
BufferedSocket::Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user