diff --git a/include/wx/unix/pipe.h b/include/wx/unix/pipe.h index d1a058beca..3581008a6e 100644 --- a/include/wx/unix/pipe.h +++ b/include/wx/unix/pipe.h @@ -52,6 +52,16 @@ public: return true; } + // switch the given end of the pipe to non-blocking IO + bool MakeNonBlocking(Direction which) + { + const int flags = fcntl(m_fds[which], F_GETFL, 0); + if ( flags == -1 ) + return false; + + return fcntl(m_fds[which], F_SETFL, flags | O_NONBLOCK) == 0; + } + // return TRUE if we were created successfully bool IsOk() const { return m_fds[Read] != INVALID_FD; } diff --git a/src/unix/evtloopunix.cpp b/src/unix/evtloopunix.cpp index 453f1c354a..b219d1b2dc 100644 --- a/src/unix/evtloopunix.cpp +++ b/src/unix/evtloopunix.cpp @@ -88,17 +88,14 @@ bool PipeIOHandler::Create() return false; } - const int fdRead = GetReadFd(); - - int flags = fcntl(fdRead, F_GETFL, 0); - if ( flags == -1 || fcntl(fdRead, F_SETFL, flags | O_NONBLOCK) == -1 ) + if ( !m_pipe.MakeNonBlocking(wxPipe::Read) ) { wxLogSysError(_("Failed to switch wake up pipe to non-blocking mode")); return false; } wxLogTrace(TRACE_EVENTS, wxT("Wake up pipe (%d, %d) created"), - fdRead, m_pipe[wxPipe::Write]); + m_pipe[wxPipe::Read], m_pipe[wxPipe::Write]); return true; }