Re: select() "hangs"



<ralph.schlosser@xxxxxxxxxxxxxx> wrote in message
news:1166467755.699217.184110@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[snip]
Please consider the following code excerpt:
[...]
I have not spotted anything obviously wrong with the code above. How do
you know it is select() which blocks? Have you run the code under a
system call tracer? Are all descriptors set to non-blocking mode?

I definately know it's the select call since I have put a debug
statement directly after the select() line.

Unless you also have one before it, how do you know it got to select()?

I'm not aware of any system call tracers other than strace (under Linux),
which in my case can't be used directly as I have a daemon application.

strace -p should do the job. Running as normal and attaching once the
application gets into this apparent stuck state might be enough.

As to your question if the descriptors are opened non-blocking, no they
are not:

fd = open(fd_dev, O_RDWR | O_NOCTTY | O_SYNC | O_DIRECT);

Could this block select()? Now that you mention it, it seems to me
superfluous, if not wrong, to open the files in a blocking manner...

The operation of select() is not affected by the non-blocking mode of the
descriptors, but the mode will naturally affect read() and write(), which is
where I thought more likely that you were blocking.

O_SYNC and O_DIRECT do not seem to make sense in your application: when
using select() (or poll() for that matter) to multiplex IO, you want
reads/writes to complete as close to instantly as possible and they must not
block. This implies making full use of buffering in the kernel. Therefore, I
would remove O_SYNC and O_DIRECT, and add O_NONBLOCK so you get EAGAIN
instead of blocking.

Alex


.



Relevant Pages

  • Re: recv blocks although socket is ready
    ... I'm not sure if changing to non-blocking mode is really an option. ... code for those members of the interface which have blocking semantics. ... IRIX, IRIX64, Linux, OSF1, SunOS and Windows. ... frequently when there is some UDP traffic on another socket. ...
    (microsoft.public.win32.programmer.networks)
  • Re: select() "hangs"
    ... Are all descriptors set to non-blocking mode? ... Is there any better tool than strace you would suggest? ...
    (comp.unix.programmer)
  • Re: select.select and socket.setblocking
    ... recv (again, assuming that you use TCP as protocol, that is AF_INET, ... which in the blocking case would wait to receive all the ... In non-blocking mode, it will always return immediately, either ...
    (comp.lang.python)
  • Re: Socket comms btwn C# server and unman C++ client
    ... each side know nothing about blocking model of the peer. ... client uses non-blocking mode and the tcplistener in the C# project is ... C# client side even though the sending C++ side signals that the send was ...
    (microsoft.public.win32.programmer.networks)
  • Any benefit to waiting on select vs blocking on I/O?
    ... If you only have a single connection, what benefit is there to use ... non-blocking mode and wait on select compared to just blocking on the ... I/O operation? ...
    (microsoft.public.win32.programmer.networks)