]> git.saurik.com Git - wxWidgets.git/commitdiff
don't close UDP socket if it receives an empty datagram (patch 1885472)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 9 Feb 2008 23:51:38 +0000 (23:51 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 9 Feb 2008 23:51:38 +0000 (23:51 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51623 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/unix/gsocket.cpp

index 08dbb42dfa745a9fb5d6fb88568085a04fa2dc21..1d1b9cec698620fa8075b03c4acf143fd9aa1a92 100644 (file)
@@ -1198,11 +1198,16 @@ int GSocket::Read(char *buffer, int size)
     else
       ret = Recv_Dgram(buffer, size);
 
-    /* If recv returned zero, then the connection has been gracefully closed.
-     * Otherwise, recv has returned an error (-1), in which case we have lost the
-     * socket only if errno does _not_ indicate that there may be more data to read.
+    /*
+     * If recv returned zero for a TCP socket (if m_stream == NULL, it's an UDP
+     * socket and empty datagrams are possible), then the connection has been
+     * gracefully closed.
+     *
+     * Otherwise, recv has returned an error (-1), in which case we have lost
+     * the socket only if errno does _not_ indicate that there may be more data
+     * to read.
      */
-    if (ret == 0)
+    if ((ret == 0) && m_stream)
     {
       /* Make sure wxSOCKET_LOST event gets sent and shut down the socket */
       if (m_use_events)
@@ -1777,9 +1782,17 @@ void GSocket::Detected_Read()
     }
     else if (num == 0)
     {
-      /* graceful shutdown */
-      CALL_CALLBACK(this, GSOCK_LOST);
-      Shutdown();
+      if (m_stream)
+      {
+        /* graceful shutdown */
+        CALL_CALLBACK(this, GSOCK_LOST);
+        Shutdown();
+      }
+      else
+      {
+        /* Empty datagram received */
+        CALL_CALLBACK(this, GSOCK_INPUT);
+      }
     }
     else
     {