Revision: 7563
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7563&view=rev
Author:   gbiggs
Date:     2009-03-31 03:34:57 +0000 (Tue, 31 Mar 2009)

Log Message:
-----------
Fixing problems with remote drivers (see patch #2697041).

Modified Paths:
--------------
    code/player/trunk/libplayertcp/remote_driver.cc

Modified: code/player/trunk/libplayertcp/remote_driver.cc
===================================================================
--- code/player/trunk/libplayertcp/remote_driver.cc     2009-03-31 02:47:55 UTC 
(rev 7562)
+++ code/player/trunk/libplayertcp/remote_driver.cc     2009-03-31 03:34:57 UTC 
(rev 7563)
@@ -38,9 +38,7 @@
 
 #include <config.h>
 
-#if defined (WIN32)
-  #include <io.h> // For read() and write()
-#else
+#if !defined (WIN32)
   #include <unistd.h>
 #endif
 #include <errno.h>
@@ -156,15 +154,30 @@
   numread=0;
   while(numread < (int)sizeof(banner))
   {
-    if((thisnumread = read(this->sock, banner+numread,
-                           sizeof(banner)-numread)) < 0)
+    thisnumread = recv(this->sock, banner+numread, sizeof(banner)-numread, 0);
+    if(thisnumread < 0)
     {
-      if(errno != ERRNO_EAGAIN)
+      if(ErrNo != ERRNO_EAGAIN)
       {
+        // Error on the socket
+#if defined (WIN32)
+        LPVOID buffer = NULL;
+        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
FORMAT_MESSAGE_FROM_SYSTEM, NULL,
+                      ErrNo, 0, reinterpret_cast<LPTSTR> (&buffer), 0, NULL);
+        PLAYER_MSG1(2, "recv() failed: %s", reinterpret_cast<LPTSTR> (buffer));
+        LocalFree(buffer);
+#else
+        PLAYER_MSG1(2,"recv() failed: %s", strerror(ErrNo));
+#endif
         PLAYER_ERROR("error reading banner from remote device");
         return(-1);
       }
     }
+    else if(thisnumread == 0)
+    {
+      PLAYER_ERROR("error reading banner from remote device (connection closed 
by peer)");
+      return(-1);
+    }
     else
       numread += thisnumread;
     GlobalTime->GetTimeDouble(&t2);
@@ -282,15 +295,30 @@
   numbytes = 0;
   while(numbytes < PLAYERXDR_MSGHDR_SIZE)
   {
-    if((thisnumbytes = read(this->sock, buf+numbytes,
-                            PLAYERXDR_MSGHDR_SIZE-numbytes)) < 0)
+    thisnumbytes = recv(this->sock, buf+numbytes, 
PLAYERXDR_MSGHDR_SIZE-numbytes, 0);
+    if(thisnumbytes < 0)
     {
-      if(errno != ERRNO_EAGAIN)
+      if(ErrNo != ERRNO_EAGAIN)
       {
-        PLAYER_ERROR1("read failed: %s", strerror(errno));
+        // Error on the socket
+#if defined (WIN32)
+        LPVOID buffer = NULL;
+        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
FORMAT_MESSAGE_FROM_SYSTEM, NULL,
+                      ErrNo, 0, reinterpret_cast<LPTSTR> (&buffer), 0, NULL);
+        PLAYER_MSG1(2, "recv() failed: %s", reinterpret_cast<LPTSTR> (buffer));
+        LocalFree(buffer);
+#else
+        PLAYER_MSG1(2, "recv() failed: %s", strerror(ErrNo));
+#endif
+        PLAYER_ERROR("error reading message header from remote device");
         return(-1);
       }
     }
+    else if(thisnumbytes == 0)
+    {
+      PLAYER_ERROR("error reading message header from remote device 
(connection closed by peer)");
+      return(-1);
+    }
     else
       numbytes += thisnumbytes;
     GlobalTime->GetTimeDouble(&t2);
@@ -323,15 +351,30 @@
   numbytes = 0;
   while(numbytes < (int)hdr.size)
   {
-    if((thisnumbytes = read(this->sock, buf+PLAYERXDR_MSGHDR_SIZE+numbytes,
-                            hdr.size-numbytes)) < 0)
+    thisnumbytes = recv(this->sock, buf+PLAYERXDR_MSGHDR_SIZE+numbytes, 
hdr.size-numbytes, 0);
+    if(thisnumbytes < 0)
     {
-      if(errno != ERRNO_EAGAIN)
+      if(ErrNo != ERRNO_EAGAIN)
       {
-        PLAYER_ERROR1("read failed: %s", strerror(errno));
+        // Error on the socket
+#if defined (WIN32)
+        LPVOID buffer = NULL;
+        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
FORMAT_MESSAGE_FROM_SYSTEM, NULL,
+                      ErrNo, 0, reinterpret_cast<LPTSTR> (&buffer), 0, NULL);
+        PLAYER_MSG1(2, "recv() failed: %s", reinterpret_cast<LPTSTR> (buffer));
+        LocalFree(buffer);
+#else
+        PLAYER_MSG1(2, "recv() failed: %s", strerror(ErrNo));
+#endif
+        PLAYER_ERROR("error reading message body from remote device");
         return(-1);
       }
     }
+    else if(thisnumbytes == 0)
+    {
+      PLAYER_ERROR("error reading message body from remote device (connection 
closed by peer)");
+      return(-1);
+    }
     else
       numbytes += thisnumbytes;
     GlobalTime->GetTimeDouble(&t2);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to