3 CrossThreadChannel::CrossThreadChannel (bool non_blocking)
10 error << "cannot create x-thread pipe for read (%2)" << ::strerror (errno) << endmsg;
15 if (fcntl (fds[0], F_SETFL, O_NONBLOCK)) {
16 error << "cannot set non-blocking mode for x-thread pipe (read) (" << ::strerror (errno) << ')' << endmsg;
20 if (fcntl (fds[1], F_SETFL, O_NONBLOCK)) {
21 error << "cannot set non-blocking mode for x-thread pipe (write) (%2)" << ::strerror (errno) << ')' << endmsg;
26 receive_channel = g_io_channel_unix_new (fds[0]);
29 CrossThreadChannel::~CrossThreadChannel ()
31 if (receive_channel) {
32 g_io_channel_unref (receive_channel);
47 CrossThreadChannel::wakeup ()
50 (void) ::write (fds[1], &c, 1);
54 CrossThreadChannel::drain ()
57 while (::read (fds[0], buf, sizeof (buf)) > 0) {};
61 CrossThreadChannel::deliver (char msg)
63 return ::write (fds[1], &msg, 1);
67 CrossThreadChannel::poll_for_request()
71 pfd[0].events = POLLIN|POLLERR|POLLHUP;
73 if (poll (pfd, 1, -1) < 0) {
79 if (pfd[0].revents & ~POLLIN) {
83 if (pfd[0].revents & POLLIN) {
91 CrossThreadChannel::receive (char& msg, bool wait)
94 if (!poll_for_request ()) {
98 return ::read (fds[0], &msg, 1);