Skip to content

Commit

Permalink
Made changes to Error handling in client
Browse files Browse the repository at this point in the history
- Make SetHttpResponse internal.
- Use Stream.CopyTo in .NET 4.0
  • Loading branch information
davidfowl committed Aug 14, 2012
1 parent aea3e61 commit ed9c605
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 9 additions & 2 deletions SignalR.Client/Infrastructure/ErrorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ public static SignalRError GetError(this Exception ex)
private static Stream Clone(Stream source)
{
var cloned = new MemoryStream();
byte[] buffer = new byte[2048];// Copy up to 2048 bytes at a time
int copiedBytes;// Maintains how many bytes were read
#if NET35
// Copy up to 2048 bytes at a time
byte[] buffer = new byte[2048];

// Maintains how many bytes were read
int copiedBytes;

// Read bytes and copy them into a buffer making sure not to trigger the dispose
while ((copiedBytes = source.Read(buffer, 0, buffer.Length)) > 0)
Expand All @@ -58,6 +62,9 @@ private static Stream Clone(Stream source)
cloned.Write(buffer, 0, copiedBytes);
}

#else
source.CopyTo(cloned);
#endif
// Move the stream pointers back to the original start locations
if (source.CanSeek)
{
Expand Down
6 changes: 1 addition & 5 deletions SignalR.Client/Infrastructure/SignalRError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ public SignalRError(Exception exception)
Exception = exception;
}

/// <summary>
/// Capture the response so we can dispose of it later
/// </summary>
/// <param name="response">The HttpWebResponse associated with the Exception, assuming its a WebException</param>
public void SetResponse(HttpWebResponse response)
internal void SetResponse(HttpWebResponse response)
{
_response = response;
}
Expand Down

0 comments on commit ed9c605

Please sign in to comment.