]> git.mxchange.org Git - flightgear.git/commitdiff
#410: multiplay manager reporting errors
authorThorstenB <brehmt@gmail.com>
Thu, 18 Aug 2011 20:36:44 +0000 (22:36 +0200)
committerThorstenB <brehmt@gmail.com>
Thu, 18 Aug 2011 20:36:44 +0000 (22:36 +0200)
receive on a non-blocking socket may return 0, which does not indicate an
error - and does not mean "errno" was upated. So do not check "errno",
errors there belong to calls elsewhere...
Error message apparently triggered constantly with FG2.4.0 on Windows.

src/MultiPlayer/multiplaymgr.cxx

index 40a9c438a9c7a5974b113187d799c9509f043e1d..d6be380dae31e157607ad5b2a682068f0dc501b6 100644 (file)
@@ -849,16 +849,24 @@ FGMultiplayMgr::update(double dt)
     //  packet waiting to be processed.
     //////////////////////////////////////////////////
     simgear::IPAddress SenderAddress;
-    bytes = mSocket->recvfrom(msgBuf.Msg, sizeof(msgBuf.Msg), 0,
+    int RecvStatus = mSocket->recvfrom(msgBuf.Msg, sizeof(msgBuf.Msg), 0,
                               &SenderAddress);
     //////////////////////////////////////////////////
     //  no Data received
     //////////////////////////////////////////////////
-    if (bytes <= 0) {
+    if (RecvStatus == 0)
+        break;
+    // socket error reported?
+    if (RecvStatus < 0)
+    {
+      // errno isn't thread-safe - so only check its value when
+      // socket return status < 0 really indicates a failure.
       if (errno != EAGAIN && errno != 0) // MSVC output "NoError" otherwise
         perror("FGMultiplayMgr::MP_ProcessData");
       break;
     }
+    // status is positive: bytes received
+    bytes = (ssize_t) RecvStatus;
     if (bytes <= static_cast<ssize_t>(sizeof(T_MsgHdr))) {
       SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
               << "received message with insufficient data" );