[Live-devel] Correct use of 'select' to avoid packet loss in Linux+BSD; correct use of WSAGetLastError and codes

Bryan Moore bmoore at airgain.com
Wed Apr 8 18:09:53 PDT 2009


 

These patches are for:

 

1.	Linux+BSD: Corrected usage of 'select ' to avoid packet loss
2.	Windows: Better use of WSAGetLastError (instead of errno)

      Note: review to add #ifndef _WIN32_WCE if needed

 

Explanation:

 

'select ':

On Linux and FreeBSD and similar operating systems, the buffer would
fill up and lose packets:

 

The 'select' function resets an internal "I/O available" flag after it
returns for each of the sockets that are indicated as having available
I/O.  These internal "I/O available" flags are not set again until _NEW_
I/O is available (specifically, for incoming I/O, another packet
arrives).  In other words, if you call 'select' and 2 new packets are
available for the socket you are testing, select will return
immediately.  But if 'recvfrom' only reads a single packet, the next
call to 'select' will _BLOCK_ until another (3rd) new packet arrives for
this socket.

 

What is _supposed_ to happen is repeated calls to 'recvfrom' until there
is no more data available.  The best way to test for available data is
via the 'FIONREAD' ioctl, which is what the patch is all about.  This is
a relatively fast call, and any performance hits caused by the ioctl are
easily made up for by the greater efficiency of the I/O overall.

 

'WSAGetLastError ':

We observe live555 'getErrno ' in BasicUsageEnvironment attempts to
report the correct Windows socket error code. However if errno is
already 0, the live555 might fail to use the correct error code. Windows
always reports in WSAGetLastError, but will not set errno unless the
compatibility library is also engaged. Therefore we patched this in
several places.

 

 

Regards,

Bryan and Bob

http://www.airgain.com

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20090408/10ed2a13/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-BasicUsageEnvironment_BasicTaskScheduler_cpp
Type: application/octet-stream
Size: 2998 bytes
Desc: patch-BasicUsageEnvironment_BasicTaskScheduler_cpp
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20090408/10ed2a13/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-groupsock_GroupsockHelper_cpp
Type: application/octet-stream
Size: 5647 bytes
Desc: patch-groupsock_GroupsockHelper_cpp
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20090408/10ed2a13/attachment-0003.obj>


More information about the live-devel mailing list