コード例 #1
0
ファイル: TcpServerEntity.cs プロジェクト: Etamiin/Inertia
        public sealed override void Close(NetworkDisconnectReason reason)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(nameof(TcpServerEntity));
            }

            if (IsRunning)
            {
                _socket?.Close();
            }
            if (!_closeNotified)
            {
                TcpConnectionEntity[] entities;
                lock (_connections)
                {
                    entities = _connections.Values.ToArray();
                    _connections.Clear();
                }

                foreach (var connection in entities)
                {
                    connection.Dispose();
                }

                _closeNotified = true;
                OnClosed(reason);
            }
        }
コード例 #2
0
        public void Disconnect(NetworkDisconnectReason reason)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(nameof(TcpConnectionEntity));
            }

            if (IsConnected)
            {
                try
                {
                    _socket.Shutdown(SocketShutdown.Both);
                }
                catch { }

                _socket?.Disconnect(false);
                _reader?.Dispose();
            }

            if (!_disconnectionNotified)
            {
                _disconnectionNotified = true;
                Disconnected?.Invoke(reason);

                _buffer      = null;
                _socket      = null;
                Disconnected = null;
            }
        }
コード例 #3
0
ファイル: UdpClientEntity.cs プロジェクト: Etamiin/Inertia
        public sealed override void Disconnect(NetworkDisconnectReason reason)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(nameof(UdpClientEntity));
            }

            if (IsConnected)
            {
                _client?.Close();
            }
            if (!_disconnectNotified)
            {
                _disconnectNotified = true;
                OnDisconnected(reason);
            }
        }
コード例 #4
0
ファイル: UdpServerEntity.cs プロジェクト: Etamiin/Inertia
        public sealed override void Close(NetworkDisconnectReason reason)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(nameof(UdpServerEntity));
            }

            if (IsInitialized)
            {
                _client?.Close();
                _client = null;
            }
            if (!_closeNotified)
            {
                _connections.Clear();
                _closeNotified = true;

                OnClosed(reason);
            }
        }
コード例 #5
0
ファイル: TcpClientEntity.cs プロジェクト: Etamiin/Inertia
        public sealed override void Disconnect(NetworkDisconnectReason reason)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(nameof(TcpClientEntity));
            }

            if (IsConnected)
            {
                try
                {
                    _socket?.Shutdown(SocketShutdown.Both);
                }
                catch { }

                _socket?.Disconnect(false);
            }
            if (!_disconnectNotified)
            {
                _reader.Clear();
                _disconnectNotified = true;
                OnDisconnected(reason);
            }
        }
コード例 #6
0
 protected virtual void OnClosed(NetworkDisconnectReason reason)
 {
 }
コード例 #7
0
 public abstract void Close(NetworkDisconnectReason reason);
コード例 #8
0
 public abstract void Disconnect(NetworkDisconnectReason reason);
コード例 #9
0
ファイル: TcpServerEntity.cs プロジェクト: Etamiin/Inertia
 protected virtual void OnClientDisconnected(TcpConnectionEntity connection, NetworkDisconnectReason reason)
 {
 }