Exemplo n.º 1
0
        //TODO handle nagle, protect against OOM by defining a max packet size.
        public EzPacket Read(byte[] data)
        {
            IBuffer  buffer = EzServer.Buffer.Provide(data);
            EzPacket packet = null;

            if (_isFinished)
            {
                buffer.SetPositionStart();
                byte id   = buffer.ReadByte();
                int  size = buffer.ReadInt16(Endianness.Big);

                int desiredSize = size + EzPacket.HeaderSize;

                if (buffer.Size == desiredSize)
                {
                    IBuffer packetBuffer = buffer.Clone(EzPacket.HeaderSize, size);
                    packet = new EzPacket(id, packetBuffer);
                }
                else if (buffer.Size < desiredSize)
                {
                    _currentId           = id;
                    _currentDesiredSize  = desiredSize;
                    _isFinished          = false;
                    _currentPacketBuffer = buffer;
                }
                else
                {
                    _logger.Error("TODO");
                }
            }
            else
            {
                long dataSize = _currentPacketBuffer.Size + buffer.Size;

                if (dataSize == _currentDesiredSize)
                {
                    _isFinished = true;
                    IBuffer packetBuffer = _currentPacketBuffer.Clone(EzPacket.HeaderSize, _currentDesiredSize);
                    packet = new EzPacket(_currentId, packetBuffer);
                }
                else if (dataSize < _currentDesiredSize)
                {
                    _currentPacketBuffer.SetPositionEnd();
                    _currentPacketBuffer.WriteBuffer(buffer);
                }
                else
                {
                    _logger.Error("TODO1");
                }
            }

            return(packet);
        }
Exemplo n.º 2
0
 protected void Send(EzClient client, EzPacket packet)
 {
     Server.Send(client, packet);
 }
Exemplo n.º 3
0
 protected void Send(List <EzClient> clients, EzPacket packet)
 {
     Server.Send(clients, packet);
 }
Exemplo n.º 4
0
 public abstract void Handle(EzClient client, EzPacket packet);