Note that there are some explanatory texts on larger screens.

plurals
  1. POIO#read blocks on non-blocking socket?
    primarykey
    data
    text
    <p>Ruby 1.8.7. I'm calling read on a socket which has been opened and connected with: </p> <pre><code>socket = Socket.new(AF_INET, SOCK_STREAM, 0) sockaddr = Socket.sockaddr_in(mp.port, mp.ip_address.ip) begin socket.connect_nonblock(sockaddr) [...] </code></pre> <p>The connection is confirmed by calling select() and then connecting a second time looking for Errno::EISCONN.</p> <p>I then call select again with a 0 timeout and if the return is not nil I read from the socket, first confirming that it has O_NONBLOCK set:</p> <pre><code> rc = select([socket], nil, nil, 0) puts " select returned: #{rc.pretty_inspect}" if rc begin puts " reading: #{socket} nonblock: #{socket.fcntl(Fcntl::F_GETFL) &amp; Fcntl::O_NONBLOCK}" response = socket.read puts " done reading" [...] </code></pre> <p>This all happens in a loop once per minute. The output the first time through the loop is:</p> <pre><code>select returned: [[#&lt;Socket:0xb6e0dcb8&gt;], [], []] reading: #&lt;Socket:0xb6e0dcb8&gt; nonblock: 2048 done reading </code></pre> <p>However the second time through the loop hangs here:</p> <pre><code>select returned: [[#&lt;Socket:0xb6e0dcb8&gt;], [], []] reading: #&lt;Socket:0xb6e0dcb8&gt; nonblock: 2048 </code></pre> <p>Attaching gdb to the process shows this backtrace:</p> <p>0 0xffffe410 in __kernel_vsyscall ()<br> 1 0xb7e5539d in select () from /lib/tls/i686/cmov/libc.so.6<br> 2 0x08064368 in rb_thread_schedule () at eval.c:11020<br> 3 0x080785bb in io_fread ( </p> <p>Replacing the call to read with a call to rcvfrom_nonblock works, and interestingly it does not get EAGAIN, it actually reads data (as you would expect given the return from select).</p> <p>Any ideas?</p> <p>steve</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload