Re: select() "hangs"
- From: "Alex Fraser" <me@xxxxxxxxxxx>
- Date: Tue, 19 Dec 2006 18:04:43 -0000
<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
.
- References:
- select() "hangs"
- From: ralph . schlosser
- Re: select() "hangs"
- From: Alex Fraser
- Re: select() "hangs"
- From: ralph . schlosser
- select() "hangs"
- Prev by Date: Re: Strange behavior with Make dependencies...
- Next by Date: Re: question on passed values and pointer assignments
- Previous by thread: Re: select() "hangs"
- Next by thread: Re: select() "hangs"
- Index(es):
Relevant Pages
|