[rabbitmq-discuss] rabbitmq-c: Nonblocking recv

Alan Antonuk alan.antonuk at gmail.com
Fri Feb 17 01:37:14 GMT 2012


Brief glance at the code - it looks good to me, except for the FD_SET(...)
line which seems to have an extra ) after the sock variable.

I would uncomment the line you have commented. Its likely that if you run
this program after amqp_producer.c program, that a frame or two is cached
and that the result of amqp_frames_enqueued() is returning true

Also check with the management plugin see if there is a message in the
queue ready to be consumed.

-Alan

On Thu, Feb 16, 2012 at 1:08 PM, Brett Cameron <brett.r.cameron at gmail.com>wrote:

> Arun,
>
> A couple of random early in the morning pre-caffeine thoughts: is sock set
> to non-blocking? What's the errno value after the select() returns?
>
> Brett
>
>
> On Fri, Feb 17, 2012 at 6:14 AM, Arun Chandrasekaran <
> visionofarun at gmail.com> wrote:
>
>> Thanks for reply Alan.
>>
>> I modified the amqp_consumer.c sample code to simulate the non-blocking
>> behaviour as you mentioned.
>>
>>     /* if (!amqp_frames_enqueued(conn) && !amqp_data_in_buffer(conn)) { */
>>     if (1) {
>>        int sock = amqp_get_sockfd(conn);
>>        printf("socket: %d\n", sock);
>>
>>        /* Watch socket fd to see when it has input. */
>>        fd_set read_flags;
>>        FD_ZERO(&read_flags);
>>        FD_SET(sock), &read_flags);
>>        int ret = 0;
>>        do {
>>           struct timeval timeout;
>>
>>           /* Wait upto a second. */
>>           timeout.tv_sec = 1;
>>           timeout.tv_usec = 0;
>>
>>           ret = select(sock+1, &read_flags, NULL, NULL, &timeout);
>>           if (ret == -1)
>>              printf("select: %s\n", strerror(errno));
>>           else if (ret == 0)
>>              printf("select timedout\n");
>>           if (FD_ISSET(sock, &read_flags)) {
>>              printf("Flag is set\n");
>>           }
>>        } while (ret == 0);
>>     }
>>
>> But this always results in a timeout. Any idea where I might be going
>> wrong? I have commented the first two checks that you mentioned just for
>> sake of clarity on select().
>>
>> -Arun
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120216/f17b4030/attachment.htm>


More information about the rabbitmq-discuss mailing list