예제 #1
0
            public void CreateNewConnection()
            {
                var args = new SocketAsyncEventArgs();

                args.Completed += Completed;

                // Куда подключаться.
                args.RemoteEndPoint = Parent.ConnectTo;

                var socket = new TcpSocket();

                _socket = socket;
                StartConnect(socket, args);
            }
예제 #2
0
            private void StartConnect(TcpSocket socket, SocketAsyncEventArgs e)
            {
                lock (Parent.Connections)
                {
                    Status = ConnectionStatus.Connecting;
                    StatusChanged?.Invoke(this, Status);
                    if (socket.IsDisposed)
                    {
                        e.Dispose();
                        return;
                    }
                }

                if (!socket.ConnectAsync(e))
                {
                    Completed(socket, e);
                }
            }
예제 #3
0
            private void SocketConnection_StartingTunneling(object sender, TcpSocket socket)
            {
                // Сокетом теперь полностью владеет SocketConnection.
                socket.Disposed -= Socket_Disposed;

                Parent.OnTunnelCreated(this);

                lock (Parent.Connections)
                {
                    Parent.Connections.Remove(this);

                    if (Parent.Connections.Count < Parent._maxConnections)
                    {
                        var newCon = new Connection(Parent);
                        Parent.Connections.Add(newCon);
                        Parent.OnNewConnection(newCon);
                        newCon.CreateNewConnection();
                    }
                }
            }