[Live-devel] Correct use of 'select' to avoid packet loss in Linux+BSD; correct use of WSAGetLastError and codes
Aurélien Nephtali
aurelien at sitadelle.com
Wed Apr 15 03:03:41 PDT 2009
On Thu, Apr 9, 2009 at 9:52 AM, Ross Finlayson <finlayson at live555.com> wrote:
> Thanks for the suggestion; I like this.
>
> Unless anyone sees a problem with this, I will include it in the next
> release of the software.
Hello,
On Linux, select() is implemented above poll(). In net/core/datagram.c
(linux 2.6.26 sources), in datagram_poll() you can see the lines that
check for readable event on the socket :
/* readable? */
if (!skb_queue_empty(&sk->sk_receive_queue) ||
(sk->sk_shutdown & RCV_SHUTDOWN))
mask |= POLLIN | POLLRDNORM;
The event is set if the socket input buffer is not empty. On FreeBSD
it is the same thing :
sys/kern/uipc_socket.c in sopoll_generic() :
if (events & (POLLIN | POLLRDNORM))
if (soreadable(so))
revents |= events & (POLLIN | POLLRDNORM);
sys/sys/socketvar.h :
#define soreadable(so) \
((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
((so)->so_rcv.sb_state & SBS_CANTRCVMORE) || \
!TAILQ_EMPTY(&(so)->so_comp) || (so)->so_error)
--
Aurélien Nephtali
More information about the live-devel
mailing list