예제 #1
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();
                    }
                }
            }
        }
예제 #2
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));
        }
예제 #3
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);
        }