Exemplo n.º 1
0
        public override bool QueueChunkEx(ChunkFlags flags, int dataSize, byte[] data, int sequence)
        {
            if (ResendQueueConstruct.DataSize +
                dataSize + NetworkCore.PACKET_HEADER_SIZE > NetworkCore.MAX_PAYLOAD)
            {
                Flush();
            }

            var header = new NetworkChunkHeader
            {
                Flags    = flags,
                Size     = dataSize,
                Sequence = sequence
            };

            var chunkDataOffset = ResendQueueConstruct.DataSize;

            chunkDataOffset = header.Pack(ResendQueueConstruct.Data, chunkDataOffset);

            Buffer.BlockCopy(data, 0, ResendQueueConstruct.Data, chunkDataOffset, dataSize);
            chunkDataOffset += dataSize;

            ResendQueueConstruct.NumChunks++;
            ResendQueueConstruct.DataSize = chunkDataOffset;

            if (flags.HasFlag(ChunkFlags.VITAL) && !flags.HasFlag(ChunkFlags.RESEND))
            {
                BufferSize += SIZEOF_NETWORK_CHUNK_RESEND + dataSize;
                if (BufferSize >= BUFFERSIZE)
                {
                    Disconnect("too weak connection (out of buffer)");
                    return(false);
                }

                var resend = new NetworkChunkResend
                {
                    Sequence      = sequence,
                    Flags         = flags,
                    DataSize      = dataSize,
                    Data          = new byte[dataSize],
                    FirstSendTime = Time.Get(),
                    LastSendTime  = Time.Get()
                };

                Buffer.BlockCopy(data, 0, resend.Data, 0, dataSize);
                ResendQueue.Enqueue(resend);
            }

            return(true);
        }
Exemplo n.º 2
0
 protected abstract void ResendChunk(NetworkChunkResend resend);
Exemplo n.º 3
0
 protected override void ResendChunk(NetworkChunkResend resend)
 {
     QueueChunkEx(resend.Flags | ChunkFlags.RESEND, resend.DataSize,
                  resend.Data, resend.Sequence);
     resend.LastSendTime = Time.Get();
 }