Gerhard Fuernkranz wrote:
you can use pass the O_NONBLOCK flag to open() in order to avoid that it blocks.
Hi Gerhard, yes I think I'll add that to the code as a simple fix for Martin's problem.
Using O_NONBLOCK is also a prerequisite for turning turn on the CLOCAL flag, because tcsetattr() requires an open file descriptor. Take care however, that subsequent read() and write() calls will be non-blocking too, when the tty was opened with O_NONBLOCK (e.g. read() would then immediately return -1, with errno==EAGAIN, if no buffered received data are available for immediate retrieval, and not wait for data).
At the moment I'm simply seeing if the port can be opened as a way to filter out all the non-existent or unusable /dev/tty's.
can't be locked). IMO most program accessing serial ports use UCCP-style lock files (residing in the directory /var/lock/ on Linux, e.g. /var/lock/LCK..tty<XX>). See http://docs.freebsd.org/info/uucp/uucp.info.UUCP_Lock_Files.html.
Hmm. A complication I'm not dealing with at the moment. Thanks for pointing it out. Graeme.