title: missing messages when reading with non-blocking udp
body: <p>I have problem with missing messages when using nonblocking read in udp between two hosts. The sender is on linux and the reader is on winxp. This example in python shows the problem.<br>
  Here are three scripts used to show the problem.<br>
  <strong>send.py</strong>:</p>
  
  <pre><code>import socket, sys
  s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
  host = sys.argv[1]
  s.sendto('A'*10,   (host,8888))
  s.sendto('B'*9000, (host,8888))
  s.sendto('C'*9000, (host,8888))
  s.sendto('D'*10,   (host,8888))
  s.sendto('E'*9000, (host,8888))
  s.sendto('F'*9000, (host,8888))
  s.sendto('G'*10,   (host,8888))
  </code></pre>
  
  <p><strong>read.py</strong></p>
  
  <pre><code>import socket
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.bind(('',8888))
  while True:
      data,address = s.recvfrom(10000)
      print "recv:", data[0],"times",len(data) 
  </code></pre>
  
  <p><strong>read_nb.py</strong></p>
  
  <pre><code>import socket
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.bind(('',8888))
  s.setblocking(0)
  data =''
  address = ''
  while True:
      try:
          data,address = s.recvfrom(10000)
      except socket.error:
          pass
      else: 
          print "recv:", data[0],"times",len(data) 
  </code></pre>
  
  <p>Example 1 (works ok):</p>
  
  <p>ubuntu> <strong>python send.py</strong><br>
  winxp > <strong>read.py</strong>  </p>
  
  <p>give this ok result from read.py:</p>
  
  <p>recv: A times 10<br>
  recv: B times 9000<br>
  recv: C times 9000<br>
  recv: D times 10<br>
  recv: E times 9000<br>
  recv: F times 9000<br>
  recv: G times 10  </p>
  
  <p>Example 2 (<strong>missing messages</strong>):<br>
  in this case the short messages will often not be catched by read_nb.py
  I give two examples of how it can look like.</p>
  
  <p>ubuntu> <strong>python send.py</strong><br>
  winxp > <strong>read_nb.py</strong>  </p>
  
  <p>give this result from read_nb.py:</p>
  
  <p>recv: A times 10<br>
  recv: B times 9000<br>
  recv: C times 9000<br>
  recv: D times 10<br>
  recv: E times 9000<br>
  recv: F times 9000  </p>
  
  <p>above is the last 10 byte message missing</p>
  
  <p>below is a 10 byte message in the middle missing</p>
  
  <p>recv: A times 10<br>
  recv: B times 9000<br>
  recv: C times 9000<br>
  recv: E times 9000<br>
  recv: F times 9000<br>
  recv: G times 10  </p>
  
  <p>I have checked with wireshark on windows and every time all messages is captured so they reach the host interface but is not captured by read_nb.py. What is the explanation?  </p>
  
  <p>I have also tried with read_nb.py on linux and send.py on windows and then it works. 
  So I figure that this problem has something to do with winsock2</p>
  
  <p>Or maybe I am using nonblocking udp the wrong way?</p>