aboutsummaryrefslogtreecommitdiffstats
path: root/src/event/SocketMonitor.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-15 22:48:38 +0100
committerMax Kellermann <max@duempel.org>2013-01-15 22:56:06 +0100
commita0ebd444ad52e00d23abca606819257fcb48889b (patch)
tree95be45b69a6db4f3d1ac7d831cd04d590bba59ca /src/event/SocketMonitor.cxx
parent0c6072c4e4e442433f3b19c26d8332219a4666a1 (diff)
downloadmpd-a0ebd444ad52e00d23abca606819257fcb48889b.tar.gz
mpd-a0ebd444ad52e00d23abca606819257fcb48889b.tar.xz
mpd-a0ebd444ad52e00d23abca606819257fcb48889b.zip
event/SocketMonitor: add method Open()
Allow creating a closed SocketMonitor instance.
Diffstat (limited to '')
-rw-r--r--src/event/SocketMonitor.cxx31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/event/SocketMonitor.cxx b/src/event/SocketMonitor.cxx
index ec31647f2..b75dc72a4 100644
--- a/src/event/SocketMonitor.cxx
+++ b/src/event/SocketMonitor.cxx
@@ -74,16 +74,11 @@ static GSourceFuncs socket_monitor_source_funcs = {
};
SocketMonitor::SocketMonitor(int _fd, EventLoop &_loop)
- :fd(_fd), loop(_loop),
- source((Source *)g_source_new(&socket_monitor_source_funcs,
- sizeof(*source))),
- poll{fd, 0, 0} {
- assert(fd >= 0);
+ :fd(-1), loop(_loop),
+ source(nullptr) {
+ assert(_fd >= 0);
- source->monitor = this;
-
- g_source_attach(&source->base, loop.GetContext());
- g_source_add_poll(&source->base, &poll);
+ Open(_fd);
}
SocketMonitor::~SocketMonitor()
@@ -93,6 +88,24 @@ SocketMonitor::~SocketMonitor()
}
void
+SocketMonitor::Open(int _fd)
+{
+ assert(fd < 0);
+ assert(source == nullptr);
+ assert(_fd >= 0);
+
+ fd = _fd;
+ poll = {fd, 0, 0};
+
+ source = (Source *)g_source_new(&socket_monitor_source_funcs,
+ sizeof(*source));
+ source->monitor = this;
+
+ g_source_attach(&source->base, loop.GetContext());
+ g_source_add_poll(&source->base, &poll);
+}
+
+void
SocketMonitor::Close()
{
assert(IsDefined());