Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix for data errors

  • Loading branch information...
commit dce1435acde38268caac98b069bd4f31aa386b68 1 parent fc71d3e
Nick Bruun nickbruun authored

Showing 1 changed file with 21 additions and 2 deletions. Show diff stats Hide diff stats

  1. +21 2 src/Mono.WebServer.FastCgi/StandardSocket.cs
23 src/Mono.WebServer.FastCgi/StandardSocket.cs
@@ -76,7 +76,26 @@ public override void Close ()
76 76
77 77 public override int Receive (byte [] buffer, int offset, int size, System.Net.Sockets.SocketFlags flags)
78 78 {
79   - return socket.Receive (buffer, offset, size, flags);
  79 + // According to the MSDN specification, a call to Sockets.Socket.Receive
  80 + // (http://msdn.microsoft.com/en-us/library/8s4y8aff.aspx) will return
  81 + // 0 immediately, if the remote end has read all incoming data and
  82 + // gracefully closed the connection.
  83 + //
  84 + // As all calls to this function are synchronous in the current FastCGI
  85 + // implementation, we can safely assume that a Receive of 0 bytes would
  86 + // only arise in this case.
  87 + // All other errors are expected to throw an exception.
  88 +
  89 + int received = socket.Receive(buffer, offset, size, flags);
  90 +
  91 + if (received == 0)
  92 + {
  93 + // Note: a better error message would probably be deemed fit.
  94 + socket.Close();
  95 + throw new Exception("Remote end hung up.");
  96 + }
  97 +
  98 + return received;
80 99 }
81 100
82 101 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)
105 124 }
106 125
107 126 }
108   -}
  127 +}

0 comments on commit dce1435

Please sign in to comment.
Something went wrong with that request. Please try again.