예제 #1
0
        void OnAccept(SocketAsyncEventArgs asyncArgs)
        {
            if (asyncArgs.SocketError != SocketError.Success)
            {
                OnAcceptError(asyncArgs);
                return;
            }

            Connection connection;

            if (ConnectionPool.TryPop(out connection))
            {
                Connections.Add(connection);
                connection.Socket = asyncArgs.AcceptSocket;

                Receive(connection);

                PushMessage(MetaMessagePool.Pop(MessageType.Connected, connection));
            }
            else
            {
                //TODO: Error
            }

            AcceptAsync();
        }
예제 #2
0
        void AcceptDone(IAsyncResult result)
        {
            var clientSocket = Socket.EndAccept(result);

            Connection connection;

            if (ConnectionPool.TryPop(out connection))
            {
                SlimCommon.Log.Default.Info("[SlimIOCP] Client connected from " + clientSocket.RemoteEndPoint);

                Connections.Add(connection);
                connection.Socket    = clientSocket;
                connection.Connected = true;

                Receive(connection);

                PushMessage(MetaMessagePool.Pop(MessageType.Connected, connection));
            }
            else
            {
                //TODO: Error
            }

            Accept();
        }
예제 #3
0
        public void Disconnect(Connection connection)
        {
            SlimCommon.Log.Default.Info("[SlimIOCP] Disconnected " + connection.RemoteEndPoint);

            lock (connection)
            {
                if (connection.Connected)
                {
                    connection.Connected = false;
                    Connections.Remove(connection);
                    PushMessage(MetaMessagePool.Pop(MessageType.Disconnected, connection));
                    ShutdownSocket(connection.Socket);
                }
            }
        }
예제 #4
0
        public void Connect(IPEndPoint endPoint)
        {
            Socket = null;

            InitSocket(endPoint);
            Socket.Connect(endPoint);
            IsConnected = true;

            var connection = new Connection(this);

            connection.Socket = Socket;

            Receive(connection);

            Connections.Add(connection);

            PushMessage(MetaMessagePool.Pop(MessageType.Connected, connection));
        }