ForceCompletion() private method

private ForceCompletion ( ) : void
return void
Ejemplo n.º 1
0
        private static void ReadDone(IAsyncResult result)
        {
            WebConnection     webConnection = (WebConnection)result.AsyncState;
            WebConnectionData data          = webConnection.Data;
            Stream            stream        = webConnection.nstream;

            if (stream == null)
            {
                webConnection.Close(sendNext: true);
                return;
            }
            int num = -1;

            try
            {
                num = stream.EndRead(result);
            }
            catch (Exception e)
            {
                webConnection.HandleError(WebExceptionStatus.ReceiveFailure, e, "ReadDone1");
                return;

                IL_004c :;
            }
            if (num == 0)
            {
                webConnection.HandleError(WebExceptionStatus.ReceiveFailure, null, "ReadDone2");
                return;
            }
            if (num < 0)
            {
                webConnection.HandleError(WebExceptionStatus.ServerProtocolViolation, null, "ReadDone3");
                return;
            }
            int num2 = -1;

            num += webConnection.position;
            if (webConnection.readState == ReadState.None)
            {
                Exception ex = null;
                try
                {
                    num2 = webConnection.GetResponse(webConnection.buffer, num);
                }
                catch (Exception ex2)
                {
                    ex = ex2;
                }
                if (ex != null)
                {
                    webConnection.HandleError(WebExceptionStatus.ServerProtocolViolation, ex, "ReadDone4");
                    return;
                }
            }
            if (webConnection.readState != ReadState.Content)
            {
                int    num3 = num * 2;
                int    num4 = (num3 >= webConnection.buffer.Length) ? num3 : webConnection.buffer.Length;
                byte[] dst  = new byte[num4];
                Buffer.BlockCopy(webConnection.buffer, 0, dst, 0, num);
                webConnection.buffer    = dst;
                webConnection.position  = num;
                webConnection.readState = ReadState.None;
                InitRead(webConnection);
                return;
            }
            webConnection.position = 0;
            WebConnectionStream webConnectionStream = new WebConnectionStream(webConnection);
            string text = data.Headers["Transfer-Encoding"];

            webConnection.chunkedRead = (text != null && text.ToLower().IndexOf("chunked") != -1);
            if (!webConnection.chunkedRead)
            {
                webConnectionStream.ReadBuffer       = webConnection.buffer;
                webConnectionStream.ReadBufferOffset = num2;
                webConnectionStream.ReadBufferSize   = num;
                webConnectionStream.CheckResponseInBuffer();
            }
            else if (webConnection.chunkStream == null)
            {
                try
                {
                    webConnection.chunkStream = new ChunkStream(webConnection.buffer, num2, num, data.Headers);
                }
                catch (Exception e2)
                {
                    webConnection.HandleError(WebExceptionStatus.ServerProtocolViolation, e2, "ReadDone5");
                    return;

                    IL_01ef :;
                }
            }
            else
            {
                webConnection.chunkStream.ResetBuffer();
                try
                {
                    webConnection.chunkStream.Write(webConnection.buffer, num2, num);
                }
                catch (Exception e3)
                {
                    webConnection.HandleError(WebExceptionStatus.ServerProtocolViolation, e3, "ReadDone6");
                    return;

                    IL_0233 :;
                }
            }
            data.stream = webConnectionStream;
            if (!ExpectContent(data.StatusCode) || data.request.Method == "HEAD")
            {
                webConnectionStream.ForceCompletion();
            }
            data.request.SetResponseData(data);
        }
Ejemplo n.º 2
0
        static void ReadDone(IAsyncResult result)
        {
            WebConnection     cnc  = (WebConnection)result.AsyncState;
            WebConnectionData data = cnc.Data;
            Stream            ns   = cnc.nstream;

            if (ns == null)
            {
                cnc.Close(true);
                return;
            }

            int nread = -1;

            try {
                nread = ns.EndRead(result);
            } catch (Exception e) {
                cnc.HandleError(WebExceptionStatus.ReceiveFailure, e, "ReadDone1");
                return;
            }

            if (nread == 0)
            {
                cnc.HandleError(WebExceptionStatus.ReceiveFailure, null, "ReadDone2");
                return;
            }

            if (nread < 0)
            {
                cnc.HandleError(WebExceptionStatus.ServerProtocolViolation, null, "ReadDone3");
                return;
            }

            int pos = -1;

            nread += cnc.position;
            if (cnc.readState == ReadState.None)
            {
                Exception exc = null;
                try {
                    pos = cnc.GetResponse(cnc.buffer, nread);
                } catch (Exception e) {
                    exc = e;
                }

                if (exc != null)
                {
                    cnc.HandleError(WebExceptionStatus.ServerProtocolViolation, exc, "ReadDone4");
                    return;
                }
            }

            if (cnc.readState != ReadState.Content)
            {
                int     est       = nread * 2;
                int     max       = (est < cnc.buffer.Length) ? cnc.buffer.Length : est;
                byte [] newBuffer = new byte [max];
                Buffer.BlockCopy(cnc.buffer, 0, newBuffer, 0, nread);
                cnc.buffer    = newBuffer;
                cnc.position  = nread;
                cnc.readState = ReadState.None;
                InitRead(cnc);
                return;
            }

            cnc.position = 0;

            WebConnectionStream stream = new WebConnectionStream(cnc);

            string contentType = data.Headers ["Transfer-Encoding"];

            cnc.chunkedRead = (contentType != null && contentType.ToLower().IndexOf("chunked") != -1);
            if (!cnc.chunkedRead)
            {
                stream.ReadBuffer       = cnc.buffer;
                stream.ReadBufferOffset = pos;
                stream.ReadBufferSize   = nread;
                stream.CheckResponseInBuffer();
            }
            else if (cnc.chunkStream == null)
            {
                try {
                    cnc.chunkStream = new ChunkStream(cnc.buffer, pos, nread, data.Headers);
                } catch (Exception e) {
                    cnc.HandleError(WebExceptionStatus.ServerProtocolViolation, e, "ReadDone5");
                    return;
                }
            }
            else
            {
                cnc.chunkStream.ResetBuffer();
                try {
                    cnc.chunkStream.Write(cnc.buffer, pos, nread);
                } catch (Exception e) {
                    cnc.HandleError(WebExceptionStatus.ServerProtocolViolation, e, "ReadDone6");
                    return;
                }
            }

            data.stream = stream;

            if (!ExpectContent(data.StatusCode) || data.request.Method == "HEAD")
            {
                stream.ForceCompletion();
            }

            data.request.SetResponseData(data);
        }
Ejemplo n.º 3
0
		static void ReadDone (IAsyncResult result)
		{
			WebConnection cnc = (WebConnection) result.AsyncState;
			WebConnectionData data = cnc.Data;
			Stream ns = cnc.nstream;
			if (ns == null) {
				cnc.Close (true);
				return;
			}

			int nread = -1;
			try {
				nread = ns.EndRead (result);
			} catch (ObjectDisposedException) {
				return;
			} catch (Exception e) {
				if (e.InnerException is ObjectDisposedException)
					return;

				cnc.HandleError (WebExceptionStatus.ReceiveFailure, e, "ReadDone1");
				return;
			}

			if (nread == 0) {
				cnc.HandleError (WebExceptionStatus.ReceiveFailure, null, "ReadDone2");
				return;
			}

			if (nread < 0) {
				cnc.HandleError (WebExceptionStatus.ServerProtocolViolation, null, "ReadDone3");
				return;
			}

			int pos = -1;
			nread += cnc.position;
			if (cnc.readState == ReadState.None) { 
				Exception exc = null;
				try {
					pos = cnc.GetResponse (cnc.buffer, nread);
				} catch (Exception e) {
					exc = e;
				}

				if (exc != null || pos == -1) {
					cnc.HandleError (WebExceptionStatus.ServerProtocolViolation, exc, "ReadDone4");
					return;
				}
			}

			if (cnc.readState != ReadState.Content) {
				int est = nread * 2;
				int max = (est < cnc.buffer.Length) ? cnc.buffer.Length : est;
				byte [] newBuffer = new byte [max];
				Buffer.BlockCopy (cnc.buffer, 0, newBuffer, 0, nread);
				cnc.buffer = newBuffer;
				cnc.position = nread;
				cnc.readState = ReadState.None;
				InitRead (cnc);
				return;
			}

			cnc.position = 0;

			WebConnectionStream stream = new WebConnectionStream (cnc);
			bool expect_content = ExpectContent (data.StatusCode, data.request.Method);
			string tencoding = null;
			if (expect_content)
				tencoding = data.Headers ["Transfer-Encoding"];

			cnc.chunkedRead = (tencoding != null && tencoding.IndexOf ("chunked", StringComparison.OrdinalIgnoreCase) != -1);
			if (!cnc.chunkedRead) {
				stream.ReadBuffer = cnc.buffer;
				stream.ReadBufferOffset = pos;
				stream.ReadBufferSize = nread;
				try {
					stream.CheckResponseInBuffer ();
				} catch (Exception e) {
					cnc.HandleError (WebExceptionStatus.ReceiveFailure, e, "ReadDone7");
				}
			} else if (cnc.chunkStream == null) {
				try {
					cnc.chunkStream = new ChunkStream (cnc.buffer, pos, nread, data.Headers);
				} catch (Exception e) {
					cnc.HandleError (WebExceptionStatus.ServerProtocolViolation, e, "ReadDone5");
					return;
				}
			} else {
				cnc.chunkStream.ResetBuffer ();
				try {
					cnc.chunkStream.Write (cnc.buffer, pos, nread);
				} catch (Exception e) {
					cnc.HandleError (WebExceptionStatus.ServerProtocolViolation, e, "ReadDone6");
					return;
				}
			}

			data.stream = stream;
			
			if (!expect_content)
				stream.ForceCompletion ();

			data.request.SetResponseData (data);
		}
Ejemplo n.º 4
0
        static void ReadDone(IAsyncResult result)
        {
            WebConnection     cnc  = (WebConnection)result.AsyncState;
            WebConnectionData data = cnc.Data;
            Stream            ns   = cnc.nstream;

            if (ns == null)
            {
                cnc.Close(true);
                return;
            }

            int nread = -1;

            try {
                nread = ns.EndRead(result);
            } catch (ObjectDisposedException) {
                return;
            } catch (Exception e) {
                if (e.InnerException is ObjectDisposedException)
                {
                    return;
                }

                cnc.HandleError(WebExceptionStatus.ReceiveFailure, e, "ReadDone1");
                return;
            }

            if (nread == 0)
            {
                cnc.HandleError(WebExceptionStatus.ReceiveFailure, null, "ReadDone2");
                return;
            }

            if (nread < 0)
            {
                cnc.HandleError(WebExceptionStatus.ServerProtocolViolation, null, "ReadDone3");
                return;
            }

            int pos = -1;

            nread += cnc.position;
            if (data.ReadState == ReadState.None)
            {
                Exception exc = null;
                try {
                    pos = GetResponse(data, cnc.sPoint, cnc.buffer, nread);
                } catch (Exception e) {
                    exc = e;
                }

                if (exc != null || pos == -1)
                {
                    cnc.HandleError(WebExceptionStatus.ServerProtocolViolation, exc, "ReadDone4");
                    return;
                }
            }

            if (data.ReadState == ReadState.Aborted)
            {
                cnc.HandleError(WebExceptionStatus.RequestCanceled, null, "ReadDone");
                return;
            }

            if (data.ReadState != ReadState.Content)
            {
                int     est       = nread * 2;
                int     max       = (est < cnc.buffer.Length) ? cnc.buffer.Length : est;
                byte [] newBuffer = new byte [max];
                Buffer.BlockCopy(cnc.buffer, 0, newBuffer, 0, nread);
                cnc.buffer     = newBuffer;
                cnc.position   = nread;
                data.ReadState = ReadState.None;
                InitRead(cnc);
                return;
            }

            cnc.position = 0;

            WebConnectionStream stream = new WebConnectionStream(cnc, data);
            bool   expect_content      = ExpectContent(data.StatusCode, data.request.Method);
            string tencoding           = null;

            if (expect_content)
            {
                tencoding = data.Headers ["Transfer-Encoding"];
            }

            cnc.chunkedRead = (tencoding != null && tencoding.IndexOf("chunked", StringComparison.OrdinalIgnoreCase) != -1);
            if (!cnc.chunkedRead)
            {
                stream.ReadBuffer       = cnc.buffer;
                stream.ReadBufferOffset = pos;
                stream.ReadBufferSize   = nread;
                try {
                    stream.CheckResponseInBuffer();
                } catch (Exception e) {
                    cnc.HandleError(WebExceptionStatus.ReceiveFailure, e, "ReadDone7");
                }
            }
            else if (cnc.chunkStream == null)
            {
                try {
                    cnc.chunkStream = new ChunkStream(cnc.buffer, pos, nread, data.Headers);
                } catch (Exception e) {
                    cnc.HandleError(WebExceptionStatus.ServerProtocolViolation, e, "ReadDone5");
                    return;
                }
            }
            else
            {
                cnc.chunkStream.ResetBuffer();
                try {
                    cnc.chunkStream.Write(cnc.buffer, pos, nread);
                } catch (Exception e) {
                    cnc.HandleError(WebExceptionStatus.ServerProtocolViolation, e, "ReadDone6");
                    return;
                }
            }

            data.stream = stream;

            if (!expect_content)
            {
                stream.ForceCompletion();
            }

            data.request.SetResponseData(data);
        }