Author: ahenderson
Date: 2008-01-17 18:07:34 -0500 (Thu, 17 Jan 2008)
New Revision: 93216
Modified:
trunk/bitsharp/src/MonoTorrent/Client/Managers/ConnectionManager.cs
Log:
Made sure read errors result in a CleanupSocket and improved diagnostics
Modified: trunk/bitsharp/src/MonoTorrent/Client/Managers/ConnectionManager.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Client/Managers/ConnectionManager.cs
2008-01-17 23:04:50 UTC (rev 93215)
+++ trunk/bitsharp/src/MonoTorrent/Client/Managers/ConnectionManager.cs
2008-01-17 23:07:34 UTC (rev 93216)
@@ -366,14 +366,23 @@
// 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)
- {
- reason = "EndReceiveMessage: " +
id.ErrorCode.ToString();
- Logger.Log(id, "Couldn't receive message");
- cleanUp = true;
- return;
- }
+ // Recycle the connection if we
got an error
+ if (id.ErrorCode !=
SocketError.Success)
+ {
+ Logger.Log(id,
"EndReceiveMessage: Error from EndReceive: " + id.ErrorCode.ToString());
+ CleanupSocket(id,
"EndReceiveMessage: Error from EndReceive: " + id.ErrorCode.ToString());
+ return;
+ }
+
+ // Recycle the connection if we
get a zero length return - indicates a lost connection
+ if (bytesReceived == 0)
+ {
+ Logger.Log(id,
"EndReceiveMessage: EndReceive returned empty string");
+ CleanupSocket(id,
"EndReceiveMessage: EndReceive returned empty string");
+ 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
// any non piece messages that happen to have '7' as
the first byte.
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches