Arun,<div><br></div><div>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?</div><div><br></div><div>Brett</div><div><br><div>
<br><div class="gmail_quote">On Fri, Feb 17, 2012 at 6:14 AM, Arun Chandrasekaran <span dir="ltr"><<a href="mailto:visionofarun@gmail.com">visionofarun@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks for reply Alan.<br><br>I modified the amqp_consumer.c sample code to simulate the non-blocking behaviour as you mentioned.<br><br><span style="font-family:courier new,monospace"> /* if (!amqp_frames_enqueued(conn) && !amqp_data_in_buffer(conn)) { */</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> if (1) {</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> int sock = amqp_get_sockfd(conn);</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> printf("socket: %d\n", sock);</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> /* Watch socket fd to see when it has input. */</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> fd_set read_flags;</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> FD_ZERO(&read_flags);</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> FD_SET(sock), &read_flags);</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> int ret = 0;</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> do {</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> struct timeval timeout;</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> /* Wait upto a second. */</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> timeout.tv_sec = 1;</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> timeout.tv_usec = 0;</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> ret = select(sock+1, &read_flags, NULL, NULL, &timeout);</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> if (ret == -1)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> printf("select: %s\n", strerror(errno));</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> else if (ret == 0)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> printf("select timedout\n");</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> if (FD_ISSET(sock, &read_flags)) {</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> printf("Flag is set\n");</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> }</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> } while (ret == 0);</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> }</span><br><br>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().<span class="HOEnZb"><font color="#888888"><br>
<br>-Arun<br>
</font></span></blockquote></div><br></div></div>