Exemple #1
0
        /// <summary>Cancels any asychronous operation that is currently active.</summary>
        public IAsyncResult Cancel(IAsyncResult ar)
        {
            ProxyAsyncData async = (ProxyAsyncData)ar;

            async.CancelPending = true;
            return(async);
        }
Exemple #2
0
        /// <summary>Complete an async connection</summary>
        public TcpClient EndConnect(IAsyncResult ar)
        {
            ProxyAsyncData async = (ProxyAsyncData)ar;

            try
            {
                ar.AsyncWaitHandle.WaitOne();
                if (async.Error != null)
                {
                    throw async.Error;                                     //throw new ProxyException(String.Format(CultureInfo.InvariantCulture, "Connection to proxy host {0} on port {1} failed.", Utils.GetHost(m_tcp_client), Utils.GetPort(m_tcp_client)), ex);
                }
                return(async.TcpClient);
            }
            finally
            {
                async.AsyncWaitHandle.Close();
            }
        }
Exemple #3
0
        /// <summary>Begin connecting asynchronously through the proxy server</summary>
        public IAsyncResult BeginConnect(string destination_host, int destination_port)
        {
            // Execute the async operation
            var async = new ProxyAsyncData();

            ThreadPool.QueueUserWorkItem(x =>
            {
                try
                {
                    // Connect to the proxy server
                    async.TcpClient.Connect(ProxyHostname, ProxyPort);

                    // Connect through to the remote host
                    DoConnect(async.TcpClient, destination_host, destination_port);
                }
                catch (Exception ex) { async.Error = ex; }
                finally { ((ManualResetEvent)async.AsyncWaitHandle).Set(); }
            }, async);
            return(async);
        }