Author: alanmc
Date: 2008-01-20 19:41:59 -0500 (Sun, 20 Jan 2008)
New Revision: 93367

Modified:
   trunk/bitsharp/src/MonoTorrent/Client/Managers/ConnectionManager.cs
Log:
Pushed back in the logging improvements

Modified: trunk/bitsharp/src/MonoTorrent/Client/Managers/ConnectionManager.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Client/Managers/ConnectionManager.cs 
2008-01-21 00:36:55 UTC (rev 93366)
+++ trunk/bitsharp/src/MonoTorrent/Client/Managers/ConnectionManager.cs 
2008-01-21 00:41:59 UTC (rev 93367)
@@ -366,13 +366,20 @@
 
                         // If we receive 0 bytes, the connection has been 
closed, so exit
                         int bytesReceived = id.Connection.EndReceive(result, 
out id.ErrorCode);
-                        if (id.ErrorCode != SocketError.Success || 
bytesReceived == 0)
+                        if (id.ErrorCode != SocketError.Success)
                         {
                             reason = "EndReceiveMessage: " + 
id.ErrorCode.ToString();
-                            Logger.Log(id, "Couldn't receive message");
+                            Logger.Log(id, "Couldn't receive message. Error 
from socket" + id.ErrorCode.ToString());
                             cleanUp = true;
                             return;
                         }
+                        if (bytesReceived == 0)
+                        {
+                            reason = "EndReceiveMessage: Received zero bytes";
+                            Logger.Log(id, "Got zero bytes when receiving a 
message");
+                            cleanUp = true;
+                            return;
+                        }
 
                         // If the first byte is '7' and we're receiving more 
than 256 bytes (a made up number)
                         // then this is a piece message, so we add it as 
"data", not protocol. 256 bytes should filter out
@@ -427,13 +434,20 @@
 
                         // If we have sent zero bytes, that is a sign the 
connection has been closed
                         int bytesSent = id.Connection.EndSend(result, out 
id.ErrorCode);
-                        if (id.ErrorCode != SocketError.Success || bytesSent 
== 0)
+                        if (id.ErrorCode != SocketError.Success)
                         {
                             reason = "Sending error: " + 
id.ErrorCode.ToString();
-                            Logger.Log(id, "Couldn't send message");
+                            Logger.Log(id, "Couldn't send message. Socket 
returned: " + id.ErrorCode.ToString());
                             cleanup = true;
                             return;
                         }
+                        if (bytesSent == 0)
+                        {
+                            reason = "Sending error: Sent zero bytes";
+                            Logger.Log(id, "Sent zero bytes when sending a 
message");
+                            cleanup = true;
+                            return;
+                        }
 
                         // Log the data sent in both the peers and 
torrentmangers connection monitors
                         TransferType type = 
(id.Connection.CurrentlySendingMessage is PieceMessage) ? TransferType.Data : 
TransferType.Protocol;

_______________________________________________
Mono-patches maillist  -  Mono-patches@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to