EndWrite() private method

private EndWrite ( HttpWebRequest request, IAsyncResult result ) : bool
request HttpWebRequest
result IAsyncResult
return bool
Ejemplo n.º 1
0
        void WriteRequestAsyncCB(IAsyncResult r)
        {
            WebAsyncResult result = (WebAsyncResult)r.AsyncState;

            result.InnerAsyncResult = null;

            try {
                cnc.EndWrite(request, true, r);
                result.SetCompleted(false, 0);
                if (!initRead)
                {
                    initRead = true;
                    WebConnection.InitRead(cnc);
                }
            } catch (Exception e) {
                KillBuffer();
                nextReadCalled = true;
                cnc.Close(true);
                if (e is System.Net.Sockets.SocketException)
                {
                    e = new IOException("Error writing request", e);
                }
                result.SetCompleted(false, e);
            }

            if (allowBuffering && !sendChunked && request.ContentLength > 0 && totalWritten == request.ContentLength)
            {
                complete_request_written = true;
            }

            result.DoCallback();
        }
Ejemplo n.º 2
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 (allowBuffering && !sendChunked)
            {
                return;
            }

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

            try {
                cnc.EndWrite(result.InnerAsyncResult);
                result.SetCompleted(false, 0);
            } catch (Exception e) {
                result.SetCompleted(false, e);
            }

            if (sendChunked)
            {
                lock (locker) {
                    pendingWrites--;
                    if (pendingWrites == 0)
                    {
                        pending.Set();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        internal void WriteRequest()
        {
            if (requestWritten)
            {
                return;
            }

            requestWritten = true;
            if (sendChunked)
            {
                return;
            }

            if (!allowBuffering || writeBuffer == null)
            {
                return;
            }

            byte [] bytes  = writeBuffer.GetBuffer();
            int     length = (int)writeBuffer.Length;

            if (request.ContentLength != -1 && request.ContentLength < length)
            {
                nextReadCalled = true;
                cnc.Close(true);
                throw new WebException("Specified Content-Length is less than the number of bytes to write", null,
                                       WebExceptionStatus.ServerProtocolViolation, null);
            }

            if (!headersSent)
            {
                string method         = request.Method;
                bool   no_writestream = (method == "GET" || method == "CONNECT" || method == "HEAD" ||
                                         method == "TRACE");
                if (!no_writestream)
                {
                    request.InternalContentLength = length;
                }
                request.SendRequestHeaders(true);
            }
            WriteHeaders();
            if (cnc.Data.StatusCode != 0 && cnc.Data.StatusCode != 100)
            {
                return;
            }

            IAsyncResult result = null;

            if (length > 0)
            {
                result = cnc.BeginWrite(request, bytes, 0, length, null, null);
            }

            if (!initRead)
            {
                initRead = true;
                WebConnection.InitRead(cnc);
            }

            if (length > 0)
            {
                complete_request_written = cnc.EndWrite(request, result);
            }
            else
            {
                complete_request_written = true;
            }
        }
Ejemplo n.º 4
0
        internal void WriteRequest()
        {
            if (requestWritten)
            {
                return;
            }
            requestWritten = true;
            if (sendChunked || !allowBuffering || writeBuffer == null)
            {
                return;
            }
            byte[] buffer = writeBuffer.GetBuffer();
            int    num    = (int)writeBuffer.Length;

            if (request.ContentLength != -1 && request.ContentLength < num)
            {
                nextReadCalled = true;
                cnc.Close(sendNext: true);
                throw new WebException("Specified Content-Length is less than the number of bytes to write", null, WebExceptionStatus.ServerProtocolViolation, null);
            }
            if (!headersSent)
            {
                string method = request.Method;
                int    num2;
                switch (method)
                {
                default:
                    num2 = ((method == "DELETE") ? 1 : 0);
                    break;

                case "GET":
                case "CONNECT":
                case "HEAD":
                case "TRACE":
                    num2 = 1;
                    break;
                }
                if (num2 == 0)
                {
                    request.InternalContentLength = num;
                }
                request.SendRequestHeaders(propagate_error: true);
            }
            WriteHeaders();
            if (cnc.Data.StatusCode == 0 || cnc.Data.StatusCode == 100)
            {
                IAsyncResult result = null;
                if (num > 0)
                {
                    result = cnc.BeginWrite(request, buffer, 0, num, null, null);
                }
                if (!initRead)
                {
                    initRead = true;
                    WebConnection.InitRead(cnc);
                }
                if (num > 0)
                {
                    complete_request_written = cnc.EndWrite(request, result);
                }
                else
                {
                    complete_request_written = true;
                }
            }
        }