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>

Search Discussions

  • Valentin BERNARD at Dec 9, 2011 at 8:52 am
    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 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprabbitmq-discuss @
categoriesrabbitmq
postedDec 9, '11 at 6:46a
activeDec 9, '11 at 8:52a
posts2
users2
websiterabbitmq.com
irc#rabbitmq

People

Translate

site design / logo © 2022 Grokbase