示例#1
0
 public void SendCommandPacket(CommandPacket packet)
 {
     this.packetQueue.Enqueue(packet);
 }
 public void FinalizeDecodedCommandPacket(CommandPacket commandPacket)
 {
     ClientNetworkInstancesCache.ReleaseCommandPacketWithCommandsCollection(commandPacket);
 }
示例#3
0
        public void ReadAndExecuteCommands(long maxTimeMillis, long networkMaxDelayTime)
        {
            this.infoEnabled = this.log.IsInfoEnabled;
            long now        = CurrentTimeMillis();
            long timeToStop = (maxTimeMillis <= 0L) ? 0x7fffffffffffffffL : (now + maxTimeMillis);

            if (this.ExecuteDelayedCommands(now, timeToStop) && (this.IsConnected && this.socket.CanRead))
            {
                if (this.socket.AvailableLength == 0)
                {
                    this.Disconnect(ProblemStatus.ClosedByServer);
                }
                else
                {
                    int num3;
                    try
                    {
                        int availableLength = this.socket.AvailableLength;
                        this.readBuffer = BufferUtils.GetBufferWithValidSize(this.readBuffer, availableLength);
                        num3            = this.socket.Read(this.readBuffer, 0, availableLength);
                        if (this.infoEnabled)
                        {
                            this.log.InfoFormat("Received {0} byte(s).", num3);
                        }
                    }
                    catch (IOException exception)
                    {
                        this.OnSocketProblem(ProblemStatus.ReceiveError, exception);
                        return;
                    }
                    if (this.infoEnabled)
                    {
                        this.log.Info("Processing new commands");
                    }
                    try
                    {
                        CommandPacket packet;
                        this.protocolAdapter.AddChunk(this.readBuffer, num3);
                        while (this.TryDecode(out packet))
                        {
                            CommandPacket packet2;
                            bool          flag = this.ExecuteCommands(packet, timeToStop, out packet2);
                            this.protocolAdapter.FinalizeDecodedCommandPacket(packet);
                            if (!flag)
                            {
                                if (this.delayedCommands == null)
                                {
                                    this.delayedCommands = packet2;
                                    this.delayUntilTime  = now + networkMaxDelayTime;
                                    continue;
                                }
                                this.delayedCommands.Append(packet2);
                                this.protocolAdapter.FinalizeDecodedCommandPacket(packet2);
                            }
                        }
                    }
                    catch (Exception exception2)
                    {
                        this.OnSocketProblem(ProblemStatus.DecodePacketError, exception2);
                    }
                }
            }
        }