[Linux-parport] getting read(2) to timeout

Robert Heller heller at deepsoft.com
Fri Aug 13 13:35:19 EDT 2004

In message <Pine.LNX.4.53.0408130949010.8406 at knuth.amplepower.com>, "Theodore A
. Roth" writes:
>I'm writing a user-space application for communicating with a home made
>device via ppdev using EPP mode. If my device is present and powered up,
>read(2) works fine, otherwise read(2) blocks.
>Is there any way to have read(2) timeout so I can have the application
>either give up or try something else? I have tried using the PPSETTIME
>ioctl command, but obviously that is not doing what I want.
>The only thing I can think of doing is to open(2) the device with
>O_NONBLOCK, then catch the read(2) failure and retry a few times before
>giving up.

open(2) w/O_NONBLOCK is the proper way to go.  Then you use select(2)
with a timeout.  See 'man 2 select' for how to do this. There is an
example code fragment (at least on my system -- WBL 3.0).  There is also
a select_tut man page in section 2 (man 2 select_tut), which is a
tutorial for select(2).

read(2) does not really have a timeout option itself (the is the nature
of how UNIX does I/O) -- this is what select is for (or at least one of
the things select is for).

>I'm developing this on a debian system with a 2.6.6-1-686 kernel.
>Ted Roth
>PGP Key ID: 0x18F846E9
>Jabber ID: troth at jabber.org
>Linux-parport mailing list
>Linux-parport at lists.infradead.org
Robert Heller                        ||InterNet:   heller at cs.umass.edu
http://vis-www.cs.umass.edu/~heller  ||            heller at deepsoft.com
http://www.deepsoft.com              /\FidoNet:    1:321/153

More information about the Linux-parport mailing list