Hi Rodos,

Read about the 'select()' system call. This allows you to wait on mutiple
blocked activities at one time.

Select() can also be told to return after 'timeout' seconds if nothing
happens.

Each activity needs to be associated with a Posix file descriptor. As you
probably know, these can be TCP sockets, UDP sockets, comms ports,
*anything* which can be opened as a file.

In your case, I would have select() wait on incoming comms characters and on
a tcp socket to/from your database.

I would advise you against forking() left, right and centre. Select is
simple and elegant and controllable, you just need one loop which waits on
select() and makes decisions based on what select() returns.

I suggest you get your hands on two great books by Richard Stevens:

1) Advanced Programming in the UNIX environment
2) UNIX Network programming

I would love to see your code for ODBC access to an NT/SQL box from a bit of
C on a Linux box!!!


BTW - What has happened to TEMP.RODOS.NET !!!!!!!!!!!!!!!!!!!!!!

I used to watch it regularly.


Cheers,

Barrie







----- Original Message -----
From: Rodos <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, 19 April 2000 15:13
Subject: [SLUG] All you C/Posix gurus.


> I am writing an application in C on Linux.
>
> 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? 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.
>
> Thanks for the advise.
>
> Rodos
>
> P.S. I have ODBC working straight to an NT machine from my C program.
> Way cool. I will be able to turf out more NT machines on this projects
> and future ones when it is mandated that MS SQL is the database
> platform. I am planning on writing a very small howto type thing on it.
>
> --
> If the box says "Windows 95 or better", it should run on Linux, right?
> - anon
> --
> SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
> To unsubscribe send email to [EMAIL PROTECTED] with
> unsubscribe in the text
>

--
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