using namespace PBD;
using namespace Glib;
-CrossThreadChannel::CrossThreadChannel ()
+CrossThreadChannel::CrossThreadChannel (bool non_blocking)
{
_ios = 0;
fds[0] = -1;
return;
}
- if (fcntl (fds[0], F_SETFL, O_NONBLOCK)) {
- error << "cannot set non-blocking mode for x-thread pipe (read) (" << ::strerror (errno) << ')' << endmsg;
- return;
- }
-
- if (fcntl (fds[1], F_SETFL, O_NONBLOCK)) {
- error << "cannot set non-blocking mode for x-thread pipe (write) (%2)" << ::strerror (errno) << ')' << endmsg;
- return;
+ if (non_blocking) {
+ if (fcntl (fds[0], F_SETFL, O_NONBLOCK)) {
+ error << "cannot set non-blocking mode for x-thread pipe (read) (" << ::strerror (errno) << ')' << endmsg;
+ return;
+ }
+
+ if (fcntl (fds[1], F_SETFL, O_NONBLOCK)) {
+ error << "cannot set non-blocking mode for x-thread pipe (write) (%2)" << ::strerror (errno) << ')' << endmsg;
+ return;
+ }
}
}
CrossThreadChannel::wakeup ()
{
char c = 0;
- ::write (fds[1], &c, 1);
+ (void) ::write (fds[1], &c, 1);
}
RefPtr<IOSource>
{
/* drain selectable fd */
char buf[64];
- while (::read (fd, buf, sizeof (buf)) > 0);
+ while (::read (fd, buf, sizeof (buf)) > 0) {};
+}
+
+int
+CrossThreadChannel::deliver (char msg)
+{
+ return ::write (fds[1], &msg, 1);
+}
+
+int
+CrossThreadChannel::receive (char& msg)
+{
+ return ::read (fds[0], &msg, 1);
}