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

Valentin BERNARD vbernard42 at gmail.com
Fri Dec 9 08:52:08 GMT 2011


Hi,

I don't really understand how your code snippet reassembles the
message frames. I think you're only storing the content of the last
received frame here. Here is my receiving code (for frames 3+):

(...)

size_t bodySize = (size_t) frame.payload.properties.body_size;
size_t bodyReceived = 0;
amqp_bytes_t body = amqp_bytes_malloc(bodySize);

/* Frames 3+ : message content */
while (bodyReceived < bodySize) {
    int result = amqp_simple_wait_frame(connection, &frame);
    if (result < 0) {
        // error
    }

    if (frame.frame_type != AMQP_FRAME_BODY) {
        // error
    }

    memcpy((void *)((int)body.bytes + bodyReceived),
        frame.payload.body_fragment.bytes,
        frame.payload.body_fragment.len);
    bodyReceived += frame.payload.body_fragment.len;
}

// body now contains the message content

Hope that helps.

Cheers,

Valentin.

On 9 déc, 07:46, tang qingxiong <tqx... at gmail.com> wrote:
> 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
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-disc... at lists.rabbitmq.comhttps://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


More information about the rabbitmq-discuss mailing list