public override int EndRead(IAsyncResult r) { WebAsyncResult result = (WebAsyncResult)r; if (result.EndCalled) { int xx = result.NBytes; return((xx >= 0) ? xx : 0); } result.EndCalled = true; if (!result.IsCompleted) { int nbytes = -1; try { nbytes = cnc.EndRead(request, result); } catch (Exception exc) { lock (locker) { pendingReads--; if (pendingReads == 0) { pending.Set(); } } nextReadCalled = true; cnc.Close(true); result.SetCompleted(false, exc); result.DoCallback(); throw; } if (nbytes < 0) { nbytes = 0; read_eof = true; } totalRead += nbytes; result.SetCompleted(false, nbytes + result.NBytes); result.DoCallback(); if (nbytes == 0) { contentLength = totalRead; } } lock (locker) { pendingReads--; if (pendingReads == 0) { pending.Set(); } } if (totalRead >= contentLength && !nextReadCalled) { ReadAll(); } int nb = result.NBytes; return((nb >= 0) ? nb : 0); }