[rabbitmq-discuss] rabbitmq-c: Nonblocking recv
Brett Cameron
brett.r.cameron at gmail.com
Thu Feb 16 18:08:08 GMT 2012
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/20120217/a024cdc1/attachment.htm>
More information about the rabbitmq-discuss
mailing list