aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/event/SocketMonitor.cxx31
-rw-r--r--src/event/SocketMonitor.hxx5
2 files changed, 27 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());
diff --git a/src/event/SocketMonitor.hxx b/src/event/SocketMonitor.hxx
index ca3c5dcc4..236e5fbda 100644
--- a/src/event/SocketMonitor.hxx
+++ b/src/event/SocketMonitor.hxx
@@ -54,6 +54,9 @@ public:
static constexpr unsigned ERROR = G_IO_ERR;
static constexpr unsigned HANGUP = G_IO_HUP;
+ SocketMonitor(EventLoop &_loop)
+ :fd(-1), loop(_loop), source(nullptr) {}
+
SocketMonitor(int _fd, EventLoop &_loop);
~SocketMonitor();
@@ -68,6 +71,8 @@ public:
return fd;
}
+ void Open(int _fd);
+
void Close();
void Schedule(unsigned flags) {