[rabbitmq-discuss] Need some help on C++ client receive code

tang qingxiong tqxtqx at gmail.com
Fri Dec 9 06:46:19 GMT 2011


Below is a code snippet of my receiving code

      amqp_frame_t frame;
      amqp_maybe_release_buffers(myConnection);
      int result = amqp_simple_wait_frame(myConnection, &frame);

      if (result < 0)
      {
        return -1;
      }
      if (frame.frame_type != AMQP_FRAME_METHOD)
      {
        return 0;
      }
      if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD)
      {
        return 0;
      }
      result = amqp_simple_wait_frame(myConnection, &frame);

      if (result < 0)
      {
        return -1;
      }
      if (frame.frame_type != AMQP_FRAME_HEADER)
      {
        abort();
      }
      uint64_t target = frame.payload.properties.body_size;
      uint64_t received = 0;
      while (received < target)
      {
        result = amqp_simple_wait_frame(myConnection, &frame);
        if (result < 0)
        {
          return -1;
        }
        if (frame.frame_type != AMQP_FRAME_BODY)
        {
          abort();
        }
        received += frame.payload.body_fragment.len;
      }

       char* recvBuffer =new char[RABBIT_BUFFER_SIZE];
       memcpy(recvBuffer, frame.payload.body_fragment.bytes,
frame.payload.body_fragment.len);
int framesize =frame.payload.body_fragment.len;


This code is adapted from the C client example and it is running mostly
fine. However after running it on my server for 19 hours, it crashes. After
tracing. it shows that

frame.payload.body_fragment.len is only 23 while received is over 10k. Am I
doing something wrong? The assumption that I made after looking at the code
is that frame is == message. If it is not , how could I received the entire
message before processing?

Regards,
QX
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20111209/34ebf992/attachment.htm>


More information about the rabbitmq-discuss mailing list