[rabbitmq-discuss] rabbitmq-c: Nonblocking recv

Arun Chandrasekaran visionofarun at gmail.com
Thu Feb 16 17:14:04 GMT 2012


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/086d94ad/attachment.htm>


More information about the rabbitmq-discuss mailing list