Re: How to properly handle hanging open()s
From: Thomas Richter (thor_at_cleopatra.math.tu-berlin.de)
Date: 14 Jul 2003 12:08:04 GMT
> Now the problem is that the transmission line between the solar heating
> controller and the PC may be down (it's a RS422 line with separately
> powered transmitters/receivers). Then the open hangs.
> In that case I'd like the open() to "time out" so I can report this
> But this does not work. Neither does it work with read() (I could do an
> O_NDELAY, but then the read() returns EAGAIN and I'd have to use other
> means to stop that).
According to "man 2 open", an open with O_NDELAY should never block, so
shouldn't the read. To avoid polling in the read-loop, have a look at
select(2) or poll(2).