示例#1
0
            public Channel(Direction direction, Socket source, Socket target, ProxyClient client)
            {
                this.direction = direction;
                this.source    = source;
                this.target    = target;
                this.client    = client;

                eventArgs = client.eventArgsManager.Take();
                eventArgs.Send.Completed    += SendEventArgs_Completed;
                eventArgs.Receive.Completed += ReceiveEventArgs_Completed;
            }
示例#2
0
        private void EndAccept()
        {
            var eventArgs = acceptEventArgs;

            if (eventArgs == null)
            {
                return;
            }

            var client = eventArgs.AcceptSocket;

            if (client.Connected)
            {
                try
                {
                    var result = connector.Connect(out var endpoint, out var listener);
                    if (result == ConnectResult.Accept)
                    {
                        var proxyClient = new ProxyClient(client, endpoint, listener, bufferSize, eventArgsManager);

                        lock (syncRoot)
                        {
                            clients.Add(proxyClient);
                        }

                        proxyClient.ExceptionOccured += (s, e) => OnExceptionOccured(e);
                        proxyClient.Closed           += ProxyClient_Closed;
                        proxyClient.Start();
                    }
                    else
                    {
                        client.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    OnExceptionOccured(new ExceptionEventArgs(ex));
                }
            }

            StartAccept();
        }