int EndReceive (IAsyncResult result)
{
SocketError error;
- return (EndReceive (result, out error));
+ int bytesReceived = EndReceive (result, out error);
+ if (error != SocketError.Success)
+ throw new SocketException ((int)error);
+ return bytesReceived;
}
#if !MOONLIGHT
asyncResult.AsyncWaitHandle.WaitOne ();
errorCode = req.ErrorCode;
- req.CheckIfThrowDelayedException ();
+ // If no socket error occurred, call CheckIfThrowDelayedException in case there are other
+ // kinds of exceptions that should be thrown.
+ if (errorCode == SocketError.Success)
+ req.CheckIfThrowDelayedException();
+
return(req.Total);
}
int EndSend (IAsyncResult result)
{
SocketError error;
- return(EndSend (result, out error));
+ int bytesSent = EndSend (result, out error);
+ if (error != SocketError.Success)
+ throw new SocketException ((int)error);
+ return bytesSent;
}
#if !MOONLIGHT
asyncResult.AsyncWaitHandle.WaitOne ();
errorCode = req.ErrorCode;
- req.CheckIfThrowDelayedException ();
+ // If no socket error occurred, call CheckIfThrowDelayedException in case there are other
+ // kinds of exceptions that should be thrown.
+ if (errorCode == SocketError.Success)
+ req.CheckIfThrowDelayedException ();
+
return(req.Total);
}