Example #1
0
        internal bool SendRawAndRecycle(NetPacket packet, NetEndPoint remoteEndPoint)
        {
            var result = SendRaw(packet.RawData, 0, packet.Size, remoteEndPoint);

            _netPacketPool.Recycle(packet);
            return(result);
        }
Example #2
0
        //from user thread, our thread, or recv?
        private void SendPacket(NetPacket packet)
        {
            NetUtils.DebugWrite("[RS]Packet: " + packet.Property);
            switch (packet.Property)
            {
            case PacketProperty.Reliable:
                _reliableUnorderedChannel.AddToQueue(packet);
                break;

            case PacketProperty.Sequenced:
                _sequencedChannel.AddToQueue(packet);
                break;

            case PacketProperty.ReliableOrdered:
                _reliableOrderedChannel.AddToQueue(packet);
                break;

            case PacketProperty.Unreliable:
                _simpleChannel.AddToQueue(packet);
                break;

            case PacketProperty.MtuCheck:
                //Must check result for MTU fix
                if (!_peerListener.SendRawAndRecycle(packet, _remoteEndPoint))
                {
                    _finishMtu = true;
                }
                break;

            case PacketProperty.AckReliable:
            case PacketProperty.AckReliableOrdered:
            case PacketProperty.Ping:
            case PacketProperty.Pong:
            case PacketProperty.Disconnect:
            case PacketProperty.MtuOk:
                SendRawData(packet);
                _packetPool.Recycle(packet);
                break;

            default:
                throw new Exception("Unknown packet property: " + packet.Property);
            }
        }