Exemple #1
0
 public int Execute(ISession session, Sinan.Collections.BytesSegment data)
 {
     List<Tuple<int, List<object>>> results = new List<Tuple<int, List<object>>>();
     int offset = data.Offset;
     int maxIndex = offset + data.Count;
     byte[] buffer = data.Array;
     while (maxIndex >= offset + 2)
     {
         // 取包长,前两字节表示
         int packetLen = buffer[offset] + (buffer[offset + 1] << 8);
         if (packetLen < m_capacity)
         {
             if (maxIndex < offset + packetLen)
             {
                 break;
             }
             try
             {
                 if (!session.Decode(buffer, offset, packetLen))
                 {
                     session.Close();
                     return -1;
                 }
                 // 取命令,第3/4字节
                 int command = buffer[offset + 2] + (buffer[offset + 3] << 8);
                 var param = AmfCodec.Decode(buffer, offset, packetLen);
                 results.Add(new Tuple<int, List<object>>(command, param));
     #if FlowLog
                 // 写流量接收记录
                 FlowLog.AddIn(command, packetLen);
     #endif
             }
             catch (AmfException ex)
             {
                 LogWrapper.Warn(session.ToString(), ex);
                 session.Close();
                 return -1;
             }
         }
         foreach (var v in results)
         {
             if (!this.Execute(session, v))
             {
                 break;
             }
         }
         offset += packetLen;
     }
     return maxIndex - offset;
 }