示例#1
0
        public void Close()
        {
            _cts.Cancel();

            NetPacket poolingPacket;

            while (_receivedPacketQueue.TryDequeue(out poolingPacket) == true &&
                   poolingPacket != null)
            {
                NetPool.PacketPool.Free(poolingPacket);
            }

            try
            {
                _udpChannel?.Close();
                _udpChannel?.OnClosed();

                _udpSocket?.Close(false);
                _udpSocket = null;

                _request.Close();
            }
            catch
            {
            }
        }
示例#2
0
        /// <summary>
        /// 세션이 닫혔음
        /// </summary>
        protected virtual Task OnClosed()
        {
            NetPacket poolingPacket;

            while (_receivedPacketQueue.TryReceive(out poolingPacket) == true &&
                   poolingPacket != null)
            {
                NetPool.PacketPool.Free(poolingPacket);
            }

            _cts?.Dispose();
            _cts = null;

            try
            {
                _tcpChannel?.OnClosed();
                _udpChannel?.OnClosed();
                _request.Close();
            }
            catch
            {
            }

            return(Task.CompletedTask);
        }
示例#3
0
        /// <summary>
        /// 서버와 접속을 해제하고 리소스를 해제한다
        /// </summary>
        public void Close()
        {
            OnSessionClosed();

            try
            {
                _cts.Cancel();
            }
            catch
            {
            }

            NetPacket poolingPacket = null;

            while (_receivedPacketQueue.TryDequeue(out poolingPacket) == true &&
                   poolingPacket != null)
            {
                NetPool.PacketPool.Free(poolingPacket);
            }

            try
            {
                _tcpChannel?.Close();
                _udpChannel?.Close();

                _p2pGroup?.Close();
                _p2pGroup = null;

                if (_connectUdpLoopTask != null)
                {
                    _connectUdpLoopTask = null;
                }

                _udpSocket?.Close(false);
                _udpSocket = null;

                _request.Close();
            }
            catch
            {
            }

            _socket         = null;
            _isUdpConnected = false;
        }