Re: poll() returns POLLIN but no data ?

From: William Ahern (william_at_wilbur.25thandClement.com)
Date: 06/27/05


Date: Mon, 27 Jun 2005 12:01:00 -0700

David Schwartz <davids@webmaster.com> wrote:

> "Maxim Yegorushkin" <e-maxim@yandex.ru> wrote in message
> news:op.ss054dzbti5cme@localhost.localdomain...

> > On Mon, 27 Jun 2005 00:17:04 +0400, David Schwartz <davids@webmaster.com>
> > wrote:

> >>> Why can't it be guaranteed?
> >>
> >> Same reason no other function call guarantees the future -- things
> >> can
> >> change. If you 'stat' a file and find it's not there, does that guarantee
> >> that a subsequent creation will succeed? If you check the free space on a
> >> volume, does that guarantee that a subsequent write will not run out of
> >> space?
>
> > Now I see. I did not think of another process dealing with the same
> > socket.
>
> That's far from the only reason. For example, suppose you have a UDP
> socket and you get a read indication. Ten minutes later when you go to read
> the datagram, it may have been discarded due to memory pressure. There are
> *many* reasons you might get a 'poll' indication and have a subsequent
> operation block. (With write, it's even simpler -- the write may be too
> large to fit in the buffer without blocking.)

Forget 10 minutes. I recently had to patch an async DNS library which made
the same mistake; namely, thinking that a read indication guaranteed an
actual read would return immediately. The UDP socket was never set
non-blocking, and under heavy DNS querying the async library--and with it
the whole application--would stall within a few seconds.

Somewhat oddly--though one could guess at the assumptions--the TCP socket
was set non-blocking.



Relevant Pages

  • Re: SetSockOpt with SO_REUSEADDR parameter
    ... no concept that allows you to create multipe sockets with the same port number. ... happening is that you are throwing away the old socket and replacing it with the new ... That is not the same as creating multiple sockets with the same port #. ... Because I will send real-time video frame, I use UDP socket. ...
    (microsoft.public.vc.mfc)
  • Re: Howto find multiple servers using TCP
    ... You will have to create a UDP socket ... When a packet is sent using a UDP socket ... differences between multicast and regular udp packets, ... But if the server program is your program, ...
    (microsoft.public.vc.mfc)
  • Re: UDP source port number when using RAW socket??
    ... the source port in a UDP packet is an *optional* ... If you *do* expect UDP packets in reply to the packets you send out, ... then what you really want to do is open a plain UDP socket and bind ... Use your raw socket to send out packets and your UDP socket to receive ...
    (comp.os.linux.development.system)
  • Re: SetSockOpt with SO_REUSEADDR parameter
    ... When a client logins into server, I will create a UDP socket to send real-time video frame to it. ... This endpoint is described by the local machine's IP address and a local port number. ... When you refer to "connect" here I assume you mean that the client calls a function named Connect. ...
    (microsoft.public.vc.mfc)
  • Re: Losing UDP packets with MFC Sockets
    ... VC++ and the GUI in VB. ... It means that the UDP socket can be open or closed many times during the ... 3.- To open/close the UDP socket the GUI calls a method from the Engine to ...
    (microsoft.public.vc.mfc)