/// <summary> /// 发送下一个数据包 /// </summary> protected void BeginWrite() { if (_streamQueue.Count > 0) { _currentWriteStreamOp = _streamQueue.Dequeue(); DoWrite(); } }
/// <summary> /// 所有未发送的数据触发发送失败 /// </summary> protected void ErrorSendPackets() { while (_currentWriteStreamOp != null) { Channel.Pipeline.FireChannelWriteErr(_currentWriteStreamOp); _currentWriteStreamOp.Dispose(); _currentWriteStreamOp = null; if (_streamQueue.Count > 0) { _currentWriteStreamOp = _streamQueue.Dequeue(); } } }
/// <summary> /// 异步发送数据 /// </summary> /// <param name="op"></param> public override void WriteAsync(object packet) { WritePacket tpacket = packet as WritePacket; if (tpacket == null) { Common.AgentLogger.Instance.Info("WriteAsync发送的数据包格式错误"); return; } _streamQueue.Enqueue(tpacket); if (_currentWriteStreamOp == null) { BeginWrite(); } }