Beispiel #1
0
 public void WriteCommands()
 {
     if (this.IsConnected && this.socket.CanWrite)
     {
         while (true)
         {
             MemoryStreamData data;
             while (true)
             {
                 if (this.packetQueue.Count != 0)
                 {
                     CommandPacket packet = this.packetQueue.Dequeue();
                     try
                     {
                         data = this.protocolAdapter.Encode(packet);
                         break;
                     }
                     catch (Exception exception)
                     {
                         this.log.DebugFormat("OnSocketProblem {0}", exception.Message);
                         this.OnSocketProblem(ProblemStatus.EncodeError, exception);
                     }
                     finally
                     {
                         ClientNetworkInstancesCache.ReleaseCommandPacketWithCommandsCollection(packet);
                     }
                     return;
                 }
                 else
                 {
                     return;
                 }
                 break;
             }
             try
             {
                 if (this.infoEnabled)
                 {
                     this.log.DebugFormat("WriteCommands {0}", data.Length);
                 }
                 this.socket.Write(data.GetBuffer(), 0, (int)data.Length);
             }
             catch (IOException exception2)
             {
                 this.OnSocketProblem(ProblemStatus.SendError, exception2);
             }
             finally
             {
                 ClientProtocolInstancesCache.ReleaseMemoryStreamData(data);
             }
         }
     }
 }
 private void KeepPartialReceivedData()
 {
     if (this.IsPartialDataEmpty())
     {
         this.partialReceivedData.Position = 0L;
         this.partialReceivedData.SetLength(0L);
     }
     else
     {
         long             position            = this.partialReceivedData.Position;
         long             length              = this.partialReceivedData.Length;
         MemoryStreamData partialReceivedData = this.partialReceivedData;
         this.partialReceivedData = ClientProtocolInstancesCache.GetMemoryStreamDataInstance();
         this.partialReceivedData.Write(partialReceivedData.GetBuffer(), (int)position, (int)(length - position));
         ClientProtocolInstancesCache.ReleaseMemoryStreamData(partialReceivedData);
     }
 }