]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/utilsexc.cpp
fix for hot keys in menu items (patch 1013082)
[wxWidgets.git] / src / msw / utilsexc.cpp
index 671d9e9083aaf7141449e3b810ef87cf76412353..4dcec53bde5bb06ccef8b037593a0af3886ae2f2 100644 (file)
@@ -5,7 +5,7 @@
 // Modified by:
 // Created:     04/01/98
 // RCS-ID:      $Id$
-// Copyright:   (c) 1998-2002 wxWindows dev team
+// Copyright:   (c) 1998-2002 wxWidgets dev team
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
@@ -235,21 +235,12 @@ public:
     bool IsOk() const { return m_handles[Read] != INVALID_HANDLE_VALUE; }
 
     // return the descriptor for one of the pipe ends
-    HANDLE operator[](Direction which) const
-    {
-        wxASSERT_MSG( which >= 0 && (size_t)which < WXSIZEOF(m_handles),
-                      _T("invalid pipe index") );
-
-        return m_handles[which];
-    }
+    HANDLE operator[](Direction which) const { return m_handles[which]; }
 
     // detach a descriptor, meaning that the pipe dtor won't close it, and
     // return it
     HANDLE Detach(Direction which)
     {
-        wxASSERT_MSG( which >= 0 && (size_t)which < WXSIZEOF(m_handles),
-                      _T("invalid pipe index") );
-
         HANDLE handle = m_handles[which];
         m_handles[which] = INVALID_HANDLE_VALUE;
 
@@ -436,6 +427,21 @@ size_t wxPipeInputStream::OnSysRead(void *buffer, size_t len)
 wxPipeOutputStream::wxPipeOutputStream(HANDLE hOutput)
 {
     m_hOutput = hOutput;
+
+    // unblock the pipe to prevent deadlocks when we're writing to the pipe
+    // from which the child process can't read because it is writing in its own
+    // end of it
+    DWORD mode = PIPE_READMODE_BYTE | PIPE_NOWAIT;
+    if ( !::SetNamedPipeHandleState
+            (
+                m_hOutput,
+                &mode,
+                NULL,       // collection count (we don't set it)
+                NULL        // timeout (we don't set it neither)
+            ) )
+    {
+        wxLogLastError(_T("SetNamedPipeHandleState(PIPE_NOWAIT)"));
+    }
 }
 
 wxPipeOutputStream::~wxPipeOutputStream()
@@ -445,17 +451,29 @@ wxPipeOutputStream::~wxPipeOutputStream()
 
 size_t wxPipeOutputStream::OnSysWrite(const void *buffer, size_t len)
 {
-    DWORD bytesWritten;
-
     m_lasterror = wxSTREAM_NO_ERROR;
-    if ( !::WriteFile(m_hOutput, buffer, len, &bytesWritten, NULL) )
+
+    DWORD totalWritten = 0;
+    while ( len > 0 )
     {
-        m_lasterror = ::GetLastError() == ERROR_BROKEN_PIPE
-                            ? wxSTREAM_EOF
-                            : wxSTREAM_WRITE_ERROR;
+        DWORD chunkWritten;
+        if ( !::WriteFile(m_hOutput, buffer, len, &chunkWritten, NULL) )
+        {
+            m_lasterror = ::GetLastError() == ERROR_BROKEN_PIPE
+                                ? wxSTREAM_EOF
+                                : wxSTREAM_WRITE_ERROR;
+            break;
+        }
+
+        if ( !chunkWritten )
+            break;
+
+        buffer = (char *)buffer + chunkWritten;
+        totalWritten += chunkWritten;
+        len -= chunkWritten;
     }
 
-    return bytesWritten;
+    return totalWritten;
 }
 
 #endif // wxUSE_STREAMS