示例#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);
        }
示例#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;
 }
示例#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;
 }
示例#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();
            }
        }
示例#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();
            });
        }
示例#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();
        }
示例#7
0
 public ClientWorker(Socket workerSocket, ProxySettings settings)
     : base(settings)
 {
     this.workerSocket = new SocketWrapper(workerSocket, settings);
 }
示例#8
0
 public ClientWorker(Socket workerSocket, ProxySettings settings)
     : base(settings)
 {
     this.workerSocket = new SocketWrapper(workerSocket, settings);
 }
示例#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;
        }
示例#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();
            });
        }
示例#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();
            }
        }
示例#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();
        }