20 #include "glib_tools.h"
28 static GSourceFuncs sourceFuncs;
31 PipeSourceCallback cb;
35 gboolean g_prepare (GSource*, gint *timeout_)
40 gboolean g_check (GSource *base)
42 auto* source =
reinterpret_cast<EventSource*
>(base);
43 return !!source->pfd.revents;
45 gboolean g_dispatch (GSource *base,
49 auto* source =
reinterpret_cast<EventSource*
>(base);
50 if (source->pfd.revents & G_IO_IN)
55 static char discard[1];
56 int ret = HANDLE_EINTR_EAGAIN(read(source->pfd.fd, discard, 1));
58 perror(
"unable to read from pipe");
60 source->cb(source->ctx);
63 if (source->pfd.revents & (G_IO_ERR | G_IO_HUP))
66 puts(
"ERROR during read from file descriptor");
70 source->pfd.revents = 0;
74 GSourceFuncs EventSource::sourceFuncs =
87 auto* source = (GSource*) Esource;
90 int ret = pipe(pipefd);
92 perror(
"can't create pipe");
95 Esource->pfd.fd = pipefd[PIPE_LISTEN];
96 Esource->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP;
97 Esource->pfd.revents = 0;
100 g_source_add_poll(source, &Esource->pfd);
102 g_source_set_name(source,
"rtRemoteSource");
103 g_source_set_priority(source, G_PRIORITY_DEFAULT);
104 g_source_set_can_recurse(source,
TRUE);