[vox-tech] Driver Question

Jeff Newmiller vox-tech@lists.lugod.org
Mon, 15 Sep 2003 10:26:12 -0700 (PDT)


On Sun, 14 Sep 2003, Mark K. Kim wrote:

> I think I understood it correctly but I wasn't sure exactly how to do it
> so I was just giving you some pointers.  Anyway, I'm sorta interested in
> this too so I poked around a bit some more.  Looks like the easiest
> technique is to:
> 
>    (1) Trap SIGIO signal using signal() system call.
>    (2) fcntl(fd, F_SETFL, O_ASYNC);
>    (3) fcntl(fd, F_SETOWN, getpid());  (might not be necessary)
>    (4) wait for SIGIO signal, handle it in your signal handler.
> 
> I haven't tried it.  If it doesn't work, refer to the "fcntl" man page and
> look for any information on asynchronous I/O (grep for "async").  If that
> doesn't work either, try reading section 12.6 in "Advanced Programming in
> the UNIX Environment" by W. Richard Stevens.

I still think select() is the way to go. (Mark beat me to the punch.)
Signals are an unnecessarily complicated way to approach the problem.

The select() call will block until your driver has data available.  You
can timeout periodically if you want to provide UI updates like clock
displays, but select() lets you block on one or more streams until they
have input, which seems perfect for the application.

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------