On Wed, Apr 19, 2000 at 03:13:40PM +1000, Rodos wrote:
> 
> Here is my problem. There are three things the program does, writes out
> to a serial port. Reads and writes to the parallel port, and
> communicates with a database. The thing is that the serial and database
> stuff might block or timeout for periods of time (say 1 to 10 seconds).
> However I need to constantly poll the serial port for data.
> 
> Therefore I am not sure as to the best way to architect my program.
> First thing that comes to mind is threads, but that sounds to hard for
> me (not that I have looked at it yet). Other things are forking 3 tasks
> and getting them to comminute with each other (how I don't know yet).
> 
> So what do you gals and guys recommend, is there a common way of doing
> such things?

yes, use select(2) [or poll(2)] -- allows you to check on multiple
file descriptors simultaneously to see which are ready for
reading/writing; then you go and deal with whichever ones are ready
at the time; repeat.

Don't use threads if this is the only issue, and don't bother
forking etc. either.

> Is there a good C/Unix book that I should get ASAP. I have
> flipped through my Kernighan "The Unix Programming Environment" and it
> has a bit on forking but not a lot.

"Advanced Programming in the Unix Environment" by W. Richard Stevens,
published by Addison-Wesley and affectionately known as APUE. You
_need_ this book. Stop reading your email and go to a bookstore and
buy it. Do it now, you still have a couple of hours before they
shut.

[Section 12.5 deals with 'I/O Multiplexing', just what you're after.
The other 700 pages are a pretty fine read too.]

Conrad.
--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to [EMAIL PROTECTED] with
unsubscribe in the text

Reply via email to