Esempio n. 1
0
        public override int Read(byte [] buffer, int offset, int size)
        {
            if (!isRead)
            {
                throw new NotSupportedException("this stream does not allow reading");
            }

            if (totalRead >= contentLength)
            {
                return(0);
            }

            AsyncCallback  cb  = new AsyncCallback(ReadCallbackWrapper);
            WebAsyncResult res = (WebAsyncResult)BeginRead(buffer, offset, size, cb, null);

            if (!res.IsCompleted && !res.WaitUntilComplete(request.ReadWriteTimeout, false))
            {
                nextReadCalled = true;
                cnc.Close(true);
                throw new WebException("The operation has timed out.",
                                       WebExceptionStatus.Timeout);
            }

            return(EndRead(res));
        }
Esempio n. 2
0
        public override void EndWrite(IAsyncResult r)
        {
            if (r == null)
            {
                throw new ArgumentNullException("r");
            }
            WebAsyncResult webAsyncResult = r as WebAsyncResult;

            if (webAsyncResult == null)
            {
                throw new ArgumentException("Invalid IAsyncResult");
            }
            if (webAsyncResult.EndCalled)
            {
                return;
            }
            webAsyncResult.EndCalled = true;
            if (webAsyncResult.AsyncWriteAll)
            {
                webAsyncResult.WaitUntilComplete();
                if (webAsyncResult.GotException)
                {
                    throw webAsyncResult.Exception;
                }
            }
            else if (!allowBuffering || sendChunked)
            {
                if (webAsyncResult.GotException)
                {
                    throw webAsyncResult.Exception;
                }
                try
                {
                    cnc.EndWrite2(request, webAsyncResult.InnerAsyncResult);
                    webAsyncResult.SetCompleted(synch: false, 0);
                    webAsyncResult.DoCallback();
                }
                catch (Exception e)
                {
                    webAsyncResult.SetCompleted(synch: false, e);
                    webAsyncResult.DoCallback();
                    throw;
                    IL_00c4 :;
                }
                finally
                {
                    if (sendChunked)
                    {
                        lock (locker)
                        {
                            pendingWrites--;
                            if (pendingWrites == 0)
                            {
                                pending.Set();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public override WebResponse EndGetResponse(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }

            WebAsyncResult result = asyncResult as WebAsyncResult;

            if (result == null)
            {
                throw new ArgumentException("Invalid IAsyncResult", "asyncResult");
            }

            if (!result.WaitUntilComplete(timeout, false))
            {
                Abort();
                throw new WebException("The request timed out", WebExceptionStatus.Timeout);
            }

            if (result.GotException)
            {
                throw result.Exception;
            }

            return(result.Response);
        }
Esempio n. 4
0
        public override Stream EndGetRequestStream(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }

            WebAsyncResult result = asyncResult as WebAsyncResult;

            if (result == null)
            {
                throw new ArgumentException("Invalid IAsyncResult");
            }

            asyncWrite = result;
            result.WaitUntilComplete();

            Exception e = result.Exception;

            if (e != null)
            {
                throw e;
            }

            return(result.WriteStream);
        }
Esempio n. 5
0
        public override int Read(byte[] buffer, int offset, int size)
        {
            AsyncCallback  cb             = ReadCallbackWrapper;
            WebAsyncResult webAsyncResult = (WebAsyncResult)BeginRead(buffer, offset, size, cb, null);

            if (!webAsyncResult.IsCompleted && !webAsyncResult.WaitUntilComplete(ReadTimeout, exitContext: false))
            {
                nextReadCalled = true;
                cnc.Close(sendNext: true);
                throw new WebException("The operation has timed out.", WebExceptionStatus.Timeout);
            }
            return(EndRead(webAsyncResult));
        }
        public override int Read(byte[] buffer, int offset, int size)
        {
            AsyncCallback  cb             = new AsyncCallback(this.ReadCallbackWrapper);
            WebAsyncResult webAsyncResult = (WebAsyncResult)this.BeginRead(buffer, offset, size, cb, null);

            if (!webAsyncResult.IsCompleted && !webAsyncResult.WaitUntilComplete(this.ReadTimeout, false))
            {
                this.nextReadCalled = true;
                this.cnc.Close(true);
                throw new WebException("The operation has timed out.", WebExceptionStatus.Timeout);
            }
            return(this.EndRead(webAsyncResult));
        }
Esempio n. 7
0
        public override void EndWrite(IAsyncResult r)
        {
            if (r == null)
            {
                throw new ArgumentNullException("r");
            }

            WebAsyncResult result = r as WebAsyncResult;

            if (result == null)
            {
                throw new ArgumentException("Invalid IAsyncResult");
            }

            if (result.EndCalled)
            {
                return;
            }

            result.EndCalled = true;
            if (result.AsyncWriteAll)
            {
                result.WaitUntilComplete();
                if (result.GotException)
                {
                    throw result.Exception;
                }
                return;
            }

            if (allowBuffering && !sendChunked)
            {
                return;
            }

            if (result.GotException)
            {
                throw result.Exception;
            }

            if (sendChunked)
            {
                lock (locker) {
                    pendingWrites--;
                    if (pendingWrites == 0)
                    {
                        pending.Set();
                    }
                }
            }
        }
Esempio n. 8
0
        public override int Read(byte [] buffer, int offset, int size)
        {
            AsyncCallback  cb  = cb_wrapper;
            WebAsyncResult res = (WebAsyncResult)BeginRead(buffer, offset, size, cb, null);

            if (!res.IsCompleted && !res.WaitUntilComplete(ReadTimeout, false))
            {
                nextReadCalled = true;
                cnc.Close(true);
                throw new WebException("The operation has timed out.", WebExceptionStatus.Timeout);
            }

            return(EndRead(res));
        }
Esempio n. 9
0
        public override void Write(byte[] buffer, int offset, int size)
        {
            AsyncCallback  cb             = WriteCallbackWrapper;
            WebAsyncResult webAsyncResult = (WebAsyncResult)BeginWrite(buffer, offset, size, cb, null);

            if (!webAsyncResult.IsCompleted && !webAsyncResult.WaitUntilComplete(WriteTimeout, exitContext: false))
            {
                KillBuffer();
                nextReadCalled = true;
                cnc.Close(sendNext: true);
                throw new IOException("Write timed out.");
            }
            EndWrite(webAsyncResult);
        }
        public override void Write(byte[] buffer, int offset, int size)
        {
            AsyncCallback  cb             = new AsyncCallback(this.WriteCallbackWrapper);
            WebAsyncResult webAsyncResult = (WebAsyncResult)this.BeginWrite(buffer, offset, size, cb, null);

            if (!webAsyncResult.IsCompleted && !webAsyncResult.WaitUntilComplete(this.WriteTimeout, false))
            {
                this.KillBuffer();
                this.nextReadCalled = true;
                this.cnc.Close(true);
                throw new IOException("Write timed out.");
            }
            this.EndWrite(webAsyncResult);
        }
Esempio n. 11
0
        public override void Write(byte [] buffer, int offset, int size)
        {
            AsyncCallback  cb  = cb_wrapper;
            WebAsyncResult res = (WebAsyncResult)BeginWrite(buffer, offset, size, cb, null);

            if (!res.IsCompleted && !res.WaitUntilComplete(WriteTimeout, false))
            {
                KillBuffer();
                nextReadCalled = true;
                cnc.Close(true);
                throw new IOException("Write timed out.");
            }

            EndWrite(res);
        }
Esempio n. 12
0
        public override void Write(byte [] buffer, int offset, int size)
        {
            if (isRead)
            {
                throw new NotSupportedException("This stream does not allow writing");
            }

            AsyncCallback  cb  = new AsyncCallback(WriteCallbackWrapper);
            WebAsyncResult res = (WebAsyncResult)BeginWrite(buffer, offset, size, cb, null);

            if (!res.IsCompleted && !res.WaitUntilComplete(request.ReadWriteTimeout, false))
            {
                nextReadCalled = true;
                cnc.Close(true);
                throw new IOException("Write timed out.");
            }

            EndWrite(res);
        }
Esempio n. 13
0
        public override void EndWrite(IAsyncResult r)
        {
            if (r == null)
            {
                throw new ArgumentNullException("r");
            }

            WebAsyncResult result = r as WebAsyncResult;

            if (result == null)
            {
                throw new ArgumentException("Invalid IAsyncResult");
            }

            if (result.EndCalled)
            {
                return;
            }

            result.EndCalled = true;
            if (result.AsyncWriteAll)
            {
                result.WaitUntilComplete();
                if (result.GotException)
                {
                    throw result.Exception;
                }
                return;
            }

            if (allowBuffering && !sendChunked)
            {
                return;
            }

            if (result.GotException)
            {
                throw result.Exception;
            }

            try {
                cnc.EndWrite2(request, result.InnerAsyncResult);
                result.SetCompleted(false, 0);
                result.DoCallback();
            } catch (Exception e) {
                if (IgnoreIOErrors)
                {
                    result.SetCompleted(false, 0);
                }
                else
                {
                    result.SetCompleted(false, e);
                }
                result.DoCallback();
                if (!IgnoreIOErrors)
                {
                    throw;
                }
            } finally {
                if (sendChunked)
                {
                    lock (locker) {
                        pendingWrites--;
                        if (pendingWrites == 0)
                        {
                            pending.Set();
                        }
                    }
                }
            }
        }
        public override void EndWrite(IAsyncResult r)
        {
            if (r == null)
            {
                throw new ArgumentNullException("r");
            }
            WebAsyncResult webAsyncResult = r as WebAsyncResult;

            if (webAsyncResult == null)
            {
                throw new ArgumentException("Invalid IAsyncResult");
            }
            if (webAsyncResult.EndCalled)
            {
                return;
            }
            webAsyncResult.EndCalled = true;
            if (webAsyncResult.AsyncWriteAll)
            {
                webAsyncResult.WaitUntilComplete();
                if (webAsyncResult.GotException)
                {
                    throw webAsyncResult.Exception;
                }
                return;
            }
            else
            {
                if (this.allowBuffering && !this.sendChunked)
                {
                    return;
                }
                if (webAsyncResult.GotException)
                {
                    throw webAsyncResult.Exception;
                }
                try
                {
                    this.cnc.EndWrite2(this.request, webAsyncResult.InnerAsyncResult);
                    webAsyncResult.SetCompleted(false, 0);
                    webAsyncResult.DoCallback();
                }
                catch (Exception e)
                {
                    webAsyncResult.SetCompleted(false, e);
                    webAsyncResult.DoCallback();
                    throw;
                }
                finally
                {
                    if (this.sendChunked)
                    {
                        object obj = this.locker;
                        lock (obj)
                        {
                            this.pendingWrites--;
                            if (this.pendingWrites == 0)
                            {
                                this.pending.Set();
                            }
                        }
                    }
                }
                return;
            }
        }