Refactor: extract code to make an fd non-clocking into a function.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 2 Nov 2010 11:57:19 +0000 (11:57 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 2 Nov 2010 11:57:19 +0000 (11:57 +0000)
Simply extract part of the code from evtloopunix.cpp into a reusable
wxPipe::MakeNonBlocking() function to be able to reuse it elsewhere.

See #12636.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65992 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/unix/pipe.h
src/unix/evtloopunix.cpp

index d1a058beca4d76e8ea2016a2abe595f0a7ae6bed..3581008a6eb41f6c4e6fabea040a097602f53b93 100644 (file)
@@ -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; }
 
index 453f1c354ae6056d8c0c9f6b6764f956016d6dcb..b219d1b2dca30138516d60b68f9df0b3329b38ae 100644 (file)
@@ -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;
 }