public void ClearTest() { SendQueue target = new SendQueue(); // TODO: 初始化为适当的值 target.Clear(); Assert.Inconclusive("无法验证不返回值的方法。"); }
private async Task Sending() { try { IsSendingQueue = true; lock (SendTempQueueLock) { SendQueue.InsertRange(0, SendTempQueue); SendTempQueue.Clear(); } await SendAsync(PacketSerializer.Serialize(SendQueue, Key, Type == GSLiveType.Command)); } catch (Exception e) { e.LogException <GsTcpClient>( Type == GSLiveType.TurnBased ? DebugLocation.TurnBased : DebugLocation.Command, "Sending"); lock (SendTempQueueLock) { SendTempQueue.InsertRange(0, SendQueue); } } finally { IsSendingQueue = false; SendQueue.Clear(); } }
public async Task Stop() { await _group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)); // RecvQueue.Clear(); SendQueue.Clear(); }
internal void Stop() { DhtMessageFactory = new DhtMessageFactory(); SendQueue.Clear(); ReceiveQueue.Clear(); WaitingResponse.Clear(); WaitingResponseTimedOut.Clear(); if (Listener.Status != ListenerStatus.NotListening) { Listener.Stop(); } }
internal override void StopReceiving(bool isGraceful) { try { IsAvailable = false; IsSendingQueue = false; DataBuilder?.Clear(); SendQueue?.Clear(); lock (SendTempQueueLock) { SendTempQueue?.Clear(); } SendQueueTimer?.Stop(); SendQueueTimer?.Close(); OperationCancellationToken?.Cancel(false); OperationCancellationToken?.Dispose(); _client?.Close(); } catch (Exception) { // ignored } finally { Key = null; _client = null; _clientStream = null; OperationCancellationToken = null; DataReceived = null; RecvThread = null; SendQueueTimer = null; try { GC.SuppressFinalize(this); } catch (Exception) { // ignored } DebugUtil.LogNormal <GsTcpClient>( Type == GSLiveType.TurnBased ? DebugLocation.TurnBased : DebugLocation.Command, "StopReceiving", "GsTcpClient -> StopReceiving Done"); } }
internal bool Close() { bool result = !_closed; if (!_closed) { _closed = true; Stream.Close(); Client.Close(); } lock (SendQueue) SendQueue.Clear(); return(result); }
public virtual void Dispose(bool flush) { if (mSocket == null || mDisposing) { return; } mDisposing = true; //##PACKET## Logout Thread.Sleep(100); if (flush) { flush = Flush(); } try { mSocket.Shutdown(SocketShutdown.Both); } catch (SocketException ex) { ExceptionHandler.Trace(ex); } try { mSocket.Close(); SocketPool.ReleaseSocket(mSocket); } catch (SocketException ex) { ExceptionHandler.Trace(ex); } mSocket = null; mBuffer = null; mRecvBuffer = null; mOnReceive = null; mOnSend = null; mRunning = false; mDisposed.Enqueue(this); if (!mSendQueue.IsEmpty) { lock (mSendQueue) mSendQueue.Clear(); } }
private bool HandleSendQueue() { I2NPMessage[] rawdata; lock ( SendRawQueue ) { rawdata = SendRawQueue.ToArray(); SendRawQueue.Clear(); } foreach (var msg in rawdata) { #if LOG_ALL_TUNNEL_TRANSFER if (FilterMessageTypes.Update(new HashedItemGroup((int)msg.MessageType, 0x1701))) { Logging.LogDebug($"OutboundTunnel: Send raw {NextHop.Id32Short} : {msg}"); } #endif Bandwidth.DataSent(msg.Payload.Length); TransportProvider.Send(NextHop, msg); } if (SendQueue.Count == 0) { return(true); } IEnumerable <TunnelMessage> messages; lock ( SendQueue ) { messages = SendQueue.ToArray(); SendQueue.Clear(); } return(CreateTunnelMessageFragments(messages)); }
private async void Start(string serverIp, short serverPort) { Func <RT_MSG_TYPE, CipherContext, ICipher> getCipher = (id, context) => { switch (context) { case CipherContext.RC_CLIENT_SESSION: return(_sessionCipher); case CipherContext.RSA_AUTH: return(AuthKey); default: return(null); } }; _group = new MultithreadEventLoopGroup(); _scertHandler = new ScertServerHandler(); // Initialize on connect _scertHandler.OnChannelActive += async(channel) => { RecvQueue.Clear(); SendQueue.Clear(); State = ClientState.CONNECTED; await OnConnected(channel); }; // _scertHandler.OnChannelInactive += async(channel) => { await OnDisconnected(channel); }; // Queue all incoming messages _scertHandler.OnChannelMessage += (channel, message) => { RecvQueue.Enqueue(message); // Log if id is set if (message.CanLog()) { Logger.Info($"RECV {channel}: {message}"); } }; try { var bootstrap = new Bootstrap(); bootstrap .Group(_group) .Channel <TcpSocketChannel>() .Option(ChannelOption.TcpNodelay, true) .Handler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast(new ScertEncoder()); pipeline.AddLast(new ScertIEnumerableEncoder()); pipeline.AddLast(new ScertTcpFrameDecoder(DotNetty.Buffers.ByteOrder.LittleEndian, Constants.MEDIUS_MESSAGE_MAXLEN, 1, 2, 0, 0, false)); pipeline.AddLast(new ScertDecoder(_sessionCipher, AuthKey)); pipeline.AddLast(_scertHandler); })); try { _boundChannel = await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(serverIp), serverPort)); } catch (Exception e) { Logger.Error($"Failed to connect to server {e}"); State = ClientState.DISCONNECTED; return; } } finally { } }