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 { } }
/// <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; }
/// <summary> /// 서버를 정지 /// </summary> public async Task StopAsync() { var state = _state; if (state != ServerState.Started) { throw new InvalidOperationException($"The server cannot be stopped right now, because its state is {state}."); } _state = ServerState.Stopping; _logger.LogInformation("Stopping... listener"); if (_listener.IsRunning) { await _listener.StopAsync(); } _logger.LogInformation("Stopping... all session"); await _sessionFactory.ShutdownAsync(); _updateThread.Join(); _updateThread = null; if (_udpSocket != null) { _logger.LogInformation("Stopping... udp service"); _udpSocket.Close(false); _udpSocket = null; } _p2pManager?.Clear(); _logger.LogInformation("Stopped!"); _state = ServerState.Stopped; }