public ReliableChannel(IChannelOption channelOption, ILogger logger, NetStatistic statistic, UdpChannel channel, bool ordered) : base(channelOption, logger, statistic) { _udpChannel = channel; _sendQueue = new Queue <NetPacket>(WindowSize); _pendingPackets = new ReliableSendInfo[WindowSize]; for (int i = 0; i < _pendingPackets.Length; i++) { _pendingPackets[i] = new ReliableSendInfo(); } _ordered = ordered; if (_ordered) { _receivedPackets = new NetPacket[WindowSize]; _deliveryMethod = DeliveryMethod.ReliableOrdered; } else { _earlyReceived = new bool[WindowSize]; _deliveryMethod = DeliveryMethod.ReliableUnordered; } int bytesCount = (WindowSize - 1) / BitsInByte + 2; _ackPacket = new NetPacket(PacketProperty.Ack, bytesCount); _ackPacket.DeliveryMethod = _deliveryMethod; }
public UdpChannel(IChannelOption channelOption, ILogger logger, NetStatistic statistic, ushort relaySessionId) : base(channelOption, logger, statistic) { _relaySessionId = relaySessionId; _sendBuffer = new byte[NetPacket.MaxUdpPacketSize]; _fragments = new PacketFragments(); _pingPacket = new NetPacket(PacketProperty.Ping, 0); _pingPacket.DeliveryMethod = DeliveryMethod.Unreliable; _pingPacket.Sequence = 1; _pongPacket = new NetPacket(PacketProperty.Pong, 0); _pongPacket.DeliveryMethod = DeliveryMethod.Unreliable; _pingTimer = new Stopwatch(); _udpChannels = new ChannelBase[(int)DeliveryMethod.Max]; _udpChannels[(int)DeliveryMethod.Unreliable] = new UnreliableChannel(channelOption, logger, statistic, this); _udpChannels[(int)DeliveryMethod.ReliableOrdered] = new ReliableChannel(channelOption, logger, statistic, this, true); _udpChannels[(int)DeliveryMethod.ReliableUnordered] = new ReliableChannel(channelOption, logger, statistic, this, false); _udpChannels[(int)DeliveryMethod.ReliableSequenced] = new SequencedChannel(channelOption, logger, statistic, this, true); _udpChannels[(int)DeliveryMethod.Sequenced] = new SequencedChannel(channelOption, logger, statistic, this, false); }
public SequencedChannel(IChannelOption channelOption, ILogger logger, NetStatistic statistic, UdpChannel udpChannel, bool reliable) : base(channelOption, logger, statistic) { _sendQueue = new Queue <NetPacket>(64); _udpChannel = udpChannel; _reliable = reliable; if (_reliable) { _deliveryMethod = DeliveryMethod.ReliableSequenced; _ackPacket = new NetPacket(PacketProperty.Ack, 0); _ackPacket.DeliveryMethod = _deliveryMethod; } else { _deliveryMethod = DeliveryMethod.Sequenced; } }
public TcpChannel(IChannelOption channelOption, ILogger logger, NetStatistic statistic) : base(channelOption, logger, statistic) { _asyncEventArgsSend = new SocketAsyncEventArgs(); _asyncEventArgsSend.Completed += OnIoCompleted; _asyncEventArgsSend.UserToken = this; _receivedBuffer = new byte[NetPacket.MaxTcpPacketSize]; _asyncEventArgsReceive = new SocketAsyncEventArgs(); _asyncEventArgsReceive.Completed += OnIoCompleted; _asyncEventArgsReceive.UserToken = this; _asyncEventArgsReceive.SetBuffer(_receivedBuffer, 0, _receivedBuffer.Length); _sendedList = new List <NetPacket>(); _sendWaitQueue = new List <NetPacket>(); _sendedBufferList = new SendingQueue(); _receivedSize = 0; }
public bool TrySend(long currentTime, int disconnectTimeoutMs, UdpChannel udpChannel, NetStatistic statistic) { if (_packet == null) { return(true); } if (_isSent) { if (currentTime >= _createTime + disconnectTimeoutMs * TimeSpan.TicksPerMillisecond) { return(false); } long resendDelay = udpChannel.ResendDelay * TimeSpan.TicksPerMillisecond; long packetHoldTime = currentTime - _lastSentTime; if (packetHoldTime < resendDelay) { return(true); } Interlocked.Increment(ref statistic.UdpResentCount); } _lastSentTime = currentTime; _isSent = true; udpChannel?.SendTo(_packet.RawData, 0, _packet.Size, UdpChannel.SendMode.Buffered); return(true); }
public SessionRequest(ISession session, NetStatistic statistic) { _session = session; _statistic = statistic; }
public ChannelBase(IChannelOption channelOption, ILogger logger, NetStatistic statistic) { _channelOption = channelOption; _logger = logger; _statistic = statistic; }