예제 #1
0
 private void WriteRequestData(Stream requestBody)
 {
     if (requestBody.Length > 0L)
     {
         InitProgress(requestBody.Position, requestBody.Length);
         TcpClientConnection connection = base.Connection;
         connection.Progress =
             (SocketProgressEventHandler)
             Delegate.Combine(connection.Progress, new SocketProgressEventHandler(DoDataSendProgress));
         try
         {
             base.Connection.WriteData(requestBody);
             if (!progressHandled)
             {
                 OnSendProgress(new SocketProgressEventArgs(requestBody.Length, requestBody.Length));
             }
         }
         finally
         {
             TcpClientConnection connection2 = base.Connection;
             connection2.Progress =
                 (SocketProgressEventHandler)
                 Delegate.Remove(connection2.Progress, new SocketProgressEventHandler(DoDataSendProgress));
         }
     }
 }
예제 #2
0
        protected TcpClient()
        {
            string str = (Environment.Version.Major > 1) ? "2.0.0.0" : "1.0.3300.0";

            connection = new TcpClientConnection();
            BatchSize  = 0x2000;
            TimeOut    = 0xea60;
            BitsPerSec = 0;
            port       = GetDefaultPort();
            server     = string.Empty;
        }
예제 #3
0
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (connection != null)
         {
             Close();
             connection.Dispose();
             connection = null;
         }
         base.Dispose(disposing);
     }
     catch { }
 }
예제 #4
0
        private void ReadResponseBody(StringCollectionEx responseHeader, long extraSize, Stream extraData,
                                      Stream responseBody)
        {
            Stream stream = null;
            TcpClientConnection connection = base.Connection;

            connection.Progress =
                (SocketProgressEventHandler)
                Delegate.Combine(connection.Progress, new SocketProgressEventHandler(DoDataReceiveProgress));
            try
            {
                Stream destination = responseBody;
                if (string.Compare("chunked", ResponseHeader.TransferEncoding, true, CultureInfo.InvariantCulture) == 0)
                {
                    using (var stream3 = new ChunkedStream(destination))
                    {
                        if (extraSize > 0L)
                        {
                            StreamUtils.Copy(extraData, stream3, extraSize);
                        }
                        InitProgress(extraSize, -1L);
                        if (base.Active)
                        {
                            while (!stream3.IsCompleted)
                            {
                                base.Connection.ReadData(stream3);
                            }
                        }
                        if (!progressHandled)
                        {
                            OnReceiveProgress(new SocketProgressEventArgs(base.Connection.BytesProceed, -1L));
                        }
                        goto Label_01AC;
                    }
                }
                if (extraSize > 0L)
                {
                    StreamUtils.Copy(extraData, destination, extraSize);
                }
                long responseLength = GetResponseLength();
                long totalBytes     = responseLength;
                InitProgress(extraSize, totalBytes);
                if (responseLength < 0L)
                {
                    if (base.Active)
                    {
                        base.Connection.IsReadUntilClose = true;
                        base.Connection.ReadData(destination);
                    }
                }
                else
                {
                    long bytesProceed = base.Connection.BytesProceed;
                    responseLength -= extraSize;
                    if (base.Active)
                    {
                        while ((base.Connection.BytesProceed - bytesProceed) < responseLength)
                        {
                            base.Connection.ReadData(destination);
                        }
                    }
                }
                if (!progressHandled)
                {
                    OnReceiveProgress(new SocketProgressEventArgs(totalBytes, totalBytes));
                }
            }
            finally
            {
                TcpClientConnection connection2 = base.Connection;
                connection2.Progress =
                    (SocketProgressEventHandler)
                    Delegate.Remove(connection2.Progress, new SocketProgressEventHandler(DoDataReceiveProgress));
                if (stream != null)
                {
                    stream.Close();
                }
                stream = null;
            }
Label_01AC:
            ReadCookies(responseHeader);
        }