예제 #1
0
 Task <int> ProcessRead(byte[] buffer, int offset, int size, CancellationToken cancellationToken)
 {
     if (read_eof)
     {
         return(Task.FromResult(0));
     }
     if (cancellationToken.IsCancellationRequested)
     {
         return(Task.FromCanceled <int> (cancellationToken));
     }
     return(HttpWebRequest.RunWithTimeout(
                ct => innerStream.ReadAsync(buffer, offset, size, ct),
                ReadTimeout,
                () => {
         Operation.Abort();
         innerStream.Dispose();
     }, cancellationToken));
 }
예제 #2
0
 protected override void Close_internal(ref bool disposed)
 {
     WebConnection.Debug($"{ME} CLOSE: disposed={disposed} closed={closed} nextReadCalled={nextReadCalled}");
     if (!closed && !nextReadCalled)
     {
         nextReadCalled = true;
         WebConnection.Debug($"{ME} CLOSE #1: read_eof={read_eof} bufferedEntireContent={bufferedEntireContent}");
         if (read_eof || bufferedEntireContent)
         {
             disposed = true;
             innerStream?.Dispose();
             innerStream = null;
             Operation.Finish(true);
         }
         else
         {
             // If we have not read all the contents
             closed   = true;
             disposed = true;
             Operation.Finish(false);
         }
     }
 }