Esempio n. 1
0
 /// <summary>
 /// Handles a buffered frame (variable length). Returns false the underyling connection should stop receiving.
 /// </summary>
 public bool HandleFrame(ByteBuffer buffer)
 {
     lock (stateSyncRoot)
     {
         try
         {
             if (State.IsExpectingProtocolHeader())
             {
                 HandleHeaderNegotiation(buffer);
             }
             if (State.ShouldIgnoreReceivedData())
             {
                 return(true);
             }
             ushort remoteChannelNumber = 0;
             var    frame = AmqpCodec.DecodeFrame(buffer, out remoteChannelNumber);
             LastFrameReceivedDateTime = DateTime.UtcNow;
             if (frame == null)
             {
                 trace.Debug("Received Empty Frame");
                 return(true);
             }
             if (Trace.IsDebugEnabled)
             {
                 var payloadSize = buffer.LengthAvailableToRead > 0 ? "Payload " + buffer.LengthAvailableToRead.ToString() + " Bytes" : "";
                 trace.Debug("RCVD CH({0}) {1} {2}", remoteChannelNumber.ToString(), frame.ToString(), payloadSize);
             }
             HandleConnectionFrame(frame, remoteChannelNumber, buffer);
             return(true);
         }
         catch (AmqpException amqpException)
         {
             trace.Error(amqpException);
             CloseConnection(amqpException.Error);
             return(false);
         }
         catch (Exception fatalException)
         {
             trace.Fatal(fatalException, "Closing Connection due to fatal exception.");
             var error = new Error()
             {
                 Condition   = ErrorCode.InternalError,
                 Description = "Closing Connection due to fatal exception: " + fatalException.Message,
             };
             CloseConnection(error);
             return(false);
         }
     }
 }
Esempio n. 2
0
 protected AmqpFrame DecodeLastFrame(out ushort channelNumber)
 {
     return(AmqpCodec.DecodeFrame(socket.WriteBuffer.Last(), out channelNumber));
 }