Skip to content

Commit

Permalink
[WebConnection]: Fix incorrect end-of-stream with null callback.
Browse files Browse the repository at this point in the history
This fixes mono#12355/mono#12395/mono#5904.

When EndRead() is called with a null "inner" IAsyncResult, then
we should not consider this as an end-of-stream condition.

This happens sometimes when using SSL and chunked encoding.
  • Loading branch information
Martin Baulig committed May 27, 2013
1 parent dd94066 commit 8348451
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mcs/class/System/System.Net/WebConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -916,20 +916,23 @@ internal int EndRead (HttpWebRequest request, IAsyncResult result)
}

int nbytes = 0;
bool done = false;
WebAsyncResult wr = null;
IAsyncResult nsAsync = ((WebAsyncResult) result).InnerAsyncResult;
if (chunkedRead && (nsAsync is WebAsyncResult)) {
wr = (WebAsyncResult) nsAsync;
IAsyncResult inner = wr.InnerAsyncResult;
if (inner != null && !(inner is WebAsyncResult))
if (inner != null && !(inner is WebAsyncResult)) {
nbytes = s.EndRead (inner);
done = nbytes == 0;
}
} else if (!(nsAsync is WebAsyncResult)) {
nbytes = s.EndRead (nsAsync);
wr = (WebAsyncResult) result;
done = nbytes == 0;
}

if (chunkedRead) {
bool done = (nbytes == 0);
try {
chunkStream.WriteAndReadBack (wr.Buffer, wr.Offset, wr.Size, ref nbytes);
if (!done && nbytes == 0 && chunkStream.WantMore)
Expand Down

0 comments on commit 8348451

Please sign in to comment.