Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Fix for endless receive loop #4

Merged
merged 1 commit into from Jan 9, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/Mono.WebServer.FastCgi/StandardSocket.cs
Expand Up @@ -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)
Expand Down Expand Up @@ -105,4 +124,4 @@ public override Socket EndAccept (IAsyncResult asyncResult)
}

}
}
}