I have the following snippet of code in a UDP client I'm knocking
together:

  def await_packet(timeout)
    packet = @recv_queue.shift
    return packet unless packet.nil?
    read_fds = [@sock]
    mylog("selecting..")
    return nil unless (fds = select(read_fds, nil, nil, timeout))
    selected_read_fds, selected_write_fds, selected_error_fds = fds
    return nil unless selected_read_fds.include?(@sock)
    mylog("recvfroming..")
    data, from = @sock.recvfrom(MAX_SIZE)
    mylog("..done recvfroming")
    frame = NA::read_server_frame(ReadBuffer.new(data))
    # TODO: filter stray ACKs?
    frame
  end


When I run my test code in ruby 1.8.2 (2004-12-25) [i386-mswin32], I
see, for example:

  C:\na>ruby -w client_test.rb
  1116865503.777 NA::PhoneSocket: selecting..
  1116865503.777 NA::PhoneSocket: recvfroming..
  1116865518.769 NA::PhoneSocket: ..done recvfroming
  1116865518.779 NA::PhoneSocket: selecting..
  1116865518.779 NA::PhoneSocket: recvfroming..
  1116865538.287 NA::PhoneSocket: ..done recvfroming

I notice that there is a gap of some several seconds between select()
completing, and recvfrom() completing -- I expected that, since select()
reports data can be read, recvfrom() should not block.  Am I wrong?

Also, I am fairly confident that there *is* data that could be read
immediately, as I can see packets arriving (in Ethereal, running on the
same machine as the above Ruby code).


Any help (even a reply that this is off-topic, and that I don't
understand socket programming) much appreciated.

dave

-- 
http://david.holroyd.me.uk/