3 CrossThreadChannel::CrossThreadChannel (bool non_blocking)
11 error << "cannot create x-thread pipe for read (%2)" << ::strerror (errno) << endmsg;
16 if (fcntl (fds[0], F_SETFL, O_NONBLOCK)) {
17 error << "cannot set non-blocking mode for x-thread pipe (read) (" << ::strerror (errno) << ')' << endmsg;
21 if (fcntl (fds[1], F_SETFL, O_NONBLOCK)) {
22 error << "cannot set non-blocking mode for x-thread pipe (write) (%2)" << ::strerror (errno) << ')' << endmsg;
27 receive_channel = g_io_channel_unix_new (fds[0]);
30 CrossThreadChannel::~CrossThreadChannel ()
33 g_source_destroy (receive_source);
37 if (receive_channel) {
38 g_io_channel_unref (receive_channel);
54 CrossThreadChannel::wakeup ()
57 (void) ::write (fds[1], &c, 1);
61 CrossThreadChannel::drain ()
64 while (::read (fds[0], buf, sizeof (buf)) > 0) {};
68 CrossThreadChannel::deliver (char msg)
70 return ::write (fds[1], &msg, 1);
74 CrossThreadChannel::poll_for_request()
78 pfd[0].events = POLLIN|POLLERR|POLLHUP;
80 if (poll (pfd, 1, -1) < 0) {
86 if (pfd[0].revents & ~POLLIN) {
90 if (pfd[0].revents & POLLIN) {
98 CrossThreadChannel::receive (char& msg, bool wait)
101 if (!poll_for_request ()) {
105 return ::read (fds[0], &msg, 1);