alarm / setitimer question and serial record communication
Peter Dufault
dufault at hda.com
Wed Sep 22 05:05:27 UTC 2004
I have some serial port code that I want to run on both RTEMS and a
POSIX system without change, and preferably, because I want to, without
any ifdefs.
The POSIX termios VMIN / VTIME interface is bizarre in that I can't
(though I've looked at it many times) put together a bullet proof
interface that handles the remote end disappearing and the local end
then recovering while I'm only the termios timeout interface.
If you set an initial timeout, then that timeout corresponds only to
the first received byte, and the read returns after that one byte. If
you set an interbyte timeout, then the first byte timeout has to be
infinite since the interbyte timeout won't come into effect until the
first byte is received.
To work around this I usually set a timeout on the first received byte
to know that the remote end is alive, I then check the received byte
for consistency, and then I set the interbyte timeout for the balance
of the record for the number of bytes I expect. Then, in case the
remote end dies after starting to talk and before finishing talking, I
wrap it the read call with an alarm that will interrupt the read in the
rare case that the remote end dies.
This code doesn't work on RTEMS. It seems to work unless the remote
device disappears after the first byte is received, but that means it
doesn't work. "setitimer" doesn't exist on RTEMS, and "alarm" doesn't
interrupt the thread doing a read even if I brute-force enable SIGALRM.
Am I missing a way to keep this part of my library portable (without
ifdefs)? There is one way I don't like, which is to revert to doing
single byte I/O using the POSIX initial timeout (the timeout that
returns as soon as the timeout elapses or a single byte is received).
That approach is OK on an embedded system but isn't OK for a portable
POSIX library that doesn't like ifdefs.
Is there is a more modern (than alarm for example) POSIX approach that
will work on both RTEMS and modern POSIX systems?
Peter
Peter Dufault
HD Associates, Inc.
More information about the users
mailing list