Example #1
0
        protected int EndSocketReceive(SocketWrapper socket, IAsyncResult result)
        {
            int bytesReceived = 0;

            if (this.finishScheduled)
            {
                this.FinishReceive();
            }
            else
            {
                try
                {
                    bytesReceived = socket.EndReceive(result);
                    if (bytesReceived == 0)
                    {
                        this.FinishReceive();
                    }
                }
                catch (SocketException)
                {
                    this.FinishReceive();
                }
                catch (IOException)
                {
                    this.FinishReceive();
                }
            }

            return(bytesReceived);
        }
Example #2
0
 public ServerWorker(ProxySettings settings, string remoteHost, ClientWorker clientWorker, SocketWrapper clientSocket)
     : base(settings)
 {
     this.remoteHost = remoteHost;
     this.clientWorker = clientWorker;
     this.clientSocket = clientSocket;
     this.inspectorFactory = settings.InspectorFactory;
 }
Example #3
0
 public ServerWorker(ProxySettings settings, string remoteHost, ClientWorker clientWorker, SocketWrapper clientSocket)
     : base(settings)
 {
     this.remoteHost       = remoteHost;
     this.clientWorker     = clientWorker;
     this.clientSocket     = clientSocket;
     this.inspectorFactory = settings.InspectorFactory;
 }
Example #4
0
        protected void SocketReceive(SocketWrapper socket, byte[] buffer, AsyncCallback callback)
        {
            if (this.finishScheduled)
            {
                this.FinishReceive();
                return;
            }

            try
            {
                socket.BeginReceive(buffer, 0, buffer.Length, callback);
            }
            catch (SocketException)
            {
                this.FinishReceive();
            }
            catch (IOException)
            {
                this.FinishReceive();
            }
        }
Example #5
0
        protected void StartSendDataTask(SocketWrapper targetSocket, BlockingCollection <byte[]> sourceDataQueue)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    foreach (var dataBlock in sourceDataQueue.GetConsumingEnumerable())
                    {
                        targetSocket.Send(dataBlock);
                    }
                }
                catch (SocketException)
                {
                }
                catch (IOException)
                {
                }

                this.sendFinished = true;
                this.ScheduleFinish();
            });
        }
Example #6
0
        private void OnConnectedToServer(Socket workerSocket)
        {
            this.workerSocket = new SocketWrapper(workerSocket, this.Settings);

            if (this.finishScheduled)
            {
                this.ScheduleFinish();
                return;
            }

            if (this.clientSocket.IsSecure)
            {
                try
                {
                    this.workerSocket.TransferToSecureServer(this.remoteHost);
                    this.clientSocket.FinishTransferToSecureClient(this.remoteHost);
                }
                catch (AuthenticationException)
                {
                    this.ScheduleFinish();
                    return;
                }
                catch (SocketException)
                {
                    this.ScheduleFinish();
                    return;
                }
                catch (IOException)
                {
                    this.ScheduleFinish();
                    return;
                }
            }

            this.StartSendToServerTask();
            this.ServerReceive();
        }
Example #7
0
 public ClientWorker(Socket workerSocket, ProxySettings settings)
     : base(settings)
 {
     this.workerSocket = new SocketWrapper(workerSocket, settings);
 }
Example #8
0
 public ClientWorker(Socket workerSocket, ProxySettings settings)
     : base(settings)
 {
     this.workerSocket = new SocketWrapper(workerSocket, settings);
 }
Example #9
0
        protected int EndSocketReceive(SocketWrapper socket, IAsyncResult result)
        {
            int bytesReceived = 0;

            if (this.finishScheduled)
            {
                this.FinishReceive();
            }
            else
            {
                try
                {
                    bytesReceived = socket.EndReceive(result);
                    if (bytesReceived == 0)
                    {
                        this.FinishReceive();
                    }
                }
                catch (SocketException)
                {
                    this.FinishReceive();
                }
                catch (IOException)
                {
                    this.FinishReceive();
                }
            }

            return bytesReceived;
        }
Example #10
0
        protected void StartSendDataTask(SocketWrapper targetSocket, BlockingCollection<byte[]> sourceDataQueue)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    foreach (var dataBlock in sourceDataQueue.GetConsumingEnumerable())
                    {
                        targetSocket.Send(dataBlock);
                    }
                }
                catch (SocketException)
                {
                }
                catch (IOException)
                {
                }

                this.sendFinished = true;
                this.ScheduleFinish();
            });
        }
Example #11
0
        protected void SocketReceive(SocketWrapper socket, byte[] buffer, AsyncCallback callback)
        {
            if (this.finishScheduled)
            {
                this.FinishReceive();
                return;
            }

            try
            {
                socket.BeginReceive(buffer, 0, buffer.Length, callback);
            }
            catch (SocketException)
            {
                this.FinishReceive();
            }
            catch (IOException)
            {
                this.FinishReceive();
            }
        }
Example #12
0
        private void OnConnectedToServer(Socket workerSocket)
        {
            this.workerSocket = new SocketWrapper(workerSocket, this.Settings);

            if (this.finishScheduled)
            {
                this.ScheduleFinish();
                return;
            }

            if (this.clientSocket.IsSecure)
            {
                try
                {
                    this.workerSocket.TransferToSecureServer(this.remoteHost);
                    this.clientSocket.FinishTransferToSecureClient(this.remoteHost);
                }
                catch (AuthenticationException)
                {
                    this.ScheduleFinish();
                    return;
                }
                catch (SocketException)
                {
                    this.ScheduleFinish();
                    return;
                }
                catch (IOException)
                {
                    this.ScheduleFinish();
                    return;
                }
            }

            this.StartSendToServerTask();
            this.ServerReceive();
        }