예제 #1
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;
            }
        }
예제 #2
0
        public void Dispose()
        {
            if (!IsDisposed)
            {
                BeforeDispose();
                Disconnect(NetworkDisconnectReason.Manual);
                _reader.Dispose();
                _socket?.Dispose();

                IsDisposed = true;
            }
        }