19 #include "glib_tools.h"
27 static GSourceFuncs sourceFuncs;
30 PipeSourceCallback cb;
34 gboolean g_prepare (GSource*, gint *timeout_)
39 gboolean g_check (GSource *base)
41 auto* source =
reinterpret_cast<EventSource*
>(base);
42 return !!source->pfd.revents;
44 gboolean g_dispatch (GSource *base,
48 auto* source =
reinterpret_cast<EventSource*
>(base);
49 if (source->pfd.revents & G_IO_IN)
54 static char discard[1];
55 int ret = HANDLE_EINTR_EAGAIN(read(source->pfd.fd, discard, 1));
57 perror(
"unable to read from pipe");
59 source->cb(source->ctx);
62 if (source->pfd.revents & (G_IO_ERR | G_IO_HUP))
65 puts(
"ERROR during read from file descriptor");
69 source->pfd.revents = 0;
73 GSourceFuncs EventSource::sourceFuncs =
86 auto* source = (GSource*) Esource;
89 int ret = pipe(pipefd);
91 perror(
"can't create pipe");
94 Esource->pfd.fd = pipefd[PIPE_LISTEN];
95 Esource->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP;
96 Esource->pfd.revents = 0;
99 g_source_add_poll(source, &Esource->pfd);
101 g_source_set_name(source,
"rtRemoteSource");
102 g_source_set_priority(source, G_PRIORITY_DEFAULT);
103 g_source_set_can_recurse(source,
TRUE);