Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #4 from nickbruun/master

Fix for endless receive loop
  • Loading branch information...
commit a64120768be0ecce0f92bfe46d77a58bc0a074b0 2 parents fc71d3e + dce1435
@gonzalop gonzalop authored
Showing with 21 additions and 2 deletions.
  1. +21 −2 src/Mono.WebServer.FastCgi/StandardSocket.cs
View
23 src/Mono.WebServer.FastCgi/StandardSocket.cs
@@ -76,7 +76,26 @@ public override void Close ()
public override int Receive (byte [] buffer, int offset, int size, System.Net.Sockets.SocketFlags flags)
{
- return socket.Receive (buffer, offset, size, flags);
+ // According to the MSDN specification, a call to Sockets.Socket.Receive
+ // (http://msdn.microsoft.com/en-us/library/8s4y8aff.aspx) will return
+ // 0 immediately, if the remote end has read all incoming data and
+ // gracefully closed the connection.
+ //
+ // As all calls to this function are synchronous in the current FastCGI
+ // implementation, we can safely assume that a Receive of 0 bytes would
+ // only arise in this case.
+ // All other errors are expected to throw an exception.
+
+ int received = socket.Receive(buffer, offset, size, flags);
+
+ if (received == 0)
+ {
+ // Note: a better error message would probably be deemed fit.
+ socket.Close();
+ throw new Exception("Remote end hung up.");
+ }
+
+ return received;
}
public override int Send (byte [] data, int offset, int size, System.Net.Sockets.SocketFlags flags)
@@ -105,4 +124,4 @@ public override Socket EndAccept (IAsyncResult asyncResult)
}
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.