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 ()
32 if (receive_channel) {
33 g_io_channel_unref (receive_channel);
49 CrossThreadChannel::wakeup ()
52 (void) ::write (fds[1], &c, 1);
56 CrossThreadChannel::drain ()
59 while (::read (fds[0], buf, sizeof (buf)) > 0) {};
63 CrossThreadChannel::deliver (char msg)
65 return ::write (fds[1], &msg, 1);
69 CrossThreadChannel::poll_for_request()
73 pfd[0].events = POLLIN|POLLERR|POLLHUP;
75 if (poll (pfd, 1, -1) < 0) {
81 if (pfd[0].revents & ~POLLIN) {
85 if (pfd[0].revents & POLLIN) {
93 CrossThreadChannel::receive (char& msg, bool wait)
96 if (!poll_for_request ()) {
100 return ::read (fds[0], &msg, 1);