*BSD News Article 40445


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!yarrina.connect.com.au!warrane.connect.com.au!godzilla.zeta.org.au!not-for-mail
From: bde@zeta.org.au (Bruce Evans)
Newsgroups: comp.os.386bsd.questions
Subject: Re: Serial port blocks on CARRIER
Date: 6 Jan 1995 11:20:30 +1100
Organization: Kralizec Dialup Unix Sydney - +61-2-837-1183, v.32bis v.42bis
Lines: 34
Message-ID: <3ei2ce$tdc@godzilla.zeta.org.au>
References: <3ednr5$nm7@cruella.ee.pdx.edu>
NNTP-Posting-Host: localhost.zeta.org.au
Keywords: serial blocking cd stty ioctl handshake

In article <3ednr5$nm7@cruella.ee.pdx.edu>,
Roland Kwee <rkwee@ee.pdx.edu> wrote:
>
>On my FreeBSD 1.0 system, I am having a problem with using the
>serial port carrier signal. On startup, it is in mode -clocal.
>Before dialing out, the modem has the CARRIER signal on False,
>but this makes the port 'hang'. Even 'stty' hangs when I try
>to set clocal. With the program fragment below, I finally had
>a way to set the port to clocal:
>
>	fd=open(argv[1], O_RDWR|O_NONBLOCK);
>	tcgetattr(fd, &tbuf);
>	tbuf.c_cflag |= CLOCAL;
>	tcsetattr(fd, TCSANOW, &tbuf);
>
>        Note the flags O_NONBLOCK and TCSANOW.
>
>Question: Is this really the best way to do it? Is there no
>way to run stty in non-blocking mode?

Yes, this is the only correct way to avoid waiting for carrier in open()
on POSIX systems.  To continue in non-blocking mode, you need to use
fcntl to turn the O_NONBLOCK flag off.

You may also be able to use a "callout" port.  FreeBSD supports
these, but in 1.0 they required special configuration and had more
bugs than in 2.0.

`stty' has a flag -f that is useful for avoiding the hang when setting
clocal.  However, in 2.0, `stty -f /dev/ttydN clocal' leaves the clocal
flag unchanged because termios flags are restored to defaults for every
open().
-- 
Bruce Evans  bde@zeta.org.au