]> git.saurik.com Git - wxWidgets.git/commitdiff
Changed the order in which events are checked, so that LOST events are
authorGuillermo Rodriguez Garcia <guille@iies.es>
Tue, 8 Feb 2000 18:31:07 +0000 (18:31 +0000)
committerGuillermo Rodriguez Garcia <guille@iies.es>
Tue, 8 Feb 2000 18:31:07 +0000 (18:31 +0000)
ignored until there are no more events pending. This is because you can
have data waiting to be read, for example, even when the peer has already
closed the connection. This affects _Wait() and OnRequest().

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

src/common/socket.cpp

index 0058d50318d2a66b87f9a46f8cb5f41fb662092c..330868a1782b6f58b7e8579b14e37ca2a2a5e96e 100644 (file)
@@ -635,7 +635,8 @@ void wxSocketBase::RestoreState()
 //
 // XXX: Should it honour the wxSOCKET_BLOCK flag ?
 //
-bool wxSocketBase::_Wait(long seconds, long milliseconds,
+bool wxSocketBase::_Wait(long seconds,
+                         long milliseconds,
                          wxSocketEventFlags flags)
 {
   GSocketEventFlags result;
@@ -683,13 +684,10 @@ bool wxSocketBase::_Wait(long seconds, long milliseconds,
   {
     result = GSocket_Select(m_socket, flags | GSOCK_LOST_FLAG);
 
-    // Connection lost
-    if (result & GSOCK_LOST_FLAG)
-    {
-      timer.Stop();
-      Close();
-      return TRUE;
-    }
+    // The order in which we check events is important; in particular,
+    // GSOCKET_LOST events should be checked last (there might be still
+    // data to read in the incoming queue even after the peer has closed
+    // the connection).
 
     // Incoming connection (server) or connection established (client)
     if (result & GSOCK_CONNECTION_FLAG)
@@ -700,12 +698,21 @@ bool wxSocketBase::_Wait(long seconds, long milliseconds,
       return TRUE;
     }
 
+    // Input and output
     if ((result & GSOCK_INPUT_FLAG) || (result & GSOCK_OUTPUT_FLAG))
     {
       timer.Stop();
       return TRUE;
     }
 
+    // Connection lost
+    if (result & GSOCK_LOST_FLAG)
+    {
+      timer.Stop();
+      Close();
+      return TRUE;
+    }
+
     // Wait more?
     if ((timeout == 0) || (m_interrupt))
       break;
@@ -828,18 +835,20 @@ void wxSocketBase::OnRequest(wxSocketNotify req_evt)
 
   switch (req_evt)
   {
-    // This duplicates some code in _Wait(), but this doesn't
-    // hurt. It has to be here because we don't know whether
-    // WaitXXX will be used, and it has to be in _Wait as well
+    // This duplicates some code in _Wait(), but this doesn't hurt.
+    // It has to be here because we don't know whether the Wait()
+    // functions will be used, and it has to be in _Wait as well
     // because the event might be a bit delayed.
     //
+    // The order in which we check events is important; in particular,
+    // GSOCKET_LOST events should be checked last (there might be still
+    // data to read in the incoming queue even after the peer has
+    // closed the connection).
+
     case wxSOCKET_CONNECTION :
       m_establishing = FALSE;
       m_connected = TRUE;
       break;
-    case wxSOCKET_LOST:
-      Close();
-      break;
 
     // If we are in the middle of a R/W operation, do not
     // propagate events to users. Also, filter 'late' events
@@ -856,6 +865,10 @@ void wxSocketBase::OnRequest(wxSocketNotify req_evt)
         return;
       else
         break;
+
+    case wxSOCKET_LOST:
+      Close();
+      break;
   }
 
   if (((m_neededreq & flag) == flag) && m_notify_state)