Date: Mon, 9 Oct 1995 14:12:58 +1000 (EST) From: raoul@cssc-syd.tansu.com.au (Raoul Golan) To: julian@ref.tfs.com (Julian Elischer) Cc: raoul@cssc-syd.tansu.com.au, freebsd-questions@freebsd.org Subject: Re: Question on read syscall on serial port Message-ID: <199510090412.OAA07782@kiwi.cssc-syd.tansu.com.au> In-Reply-To: <199510090318.UAA14415@ref.tfs.com> from "Julian Elischer" at Oct 8, 95 08:18:30 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> > > > > Hello people, > > > > I'm reading from a modem on /dev/cua*. It's a blocking read, > > which means I expect it to wait there until data is available, > > or until the modem loses carrier, or until an error occurs. > > > > At the moment, when the modem loses carrier, the read syscall > > returns a count of 0 data read, but it does not set errno to > > anything (it leaves errno with the same value it had before the > > call). > > > > Is there any way (via an ioctl, a fcntl, an stty(?) or via some > > modem configuration parameter) of having the read syscall put > > some value into errno, such as ENOENT or EIO, when the modem > > loses carrier? > Returning 0 bytes on a blocking call is considered "Notification of EOF" > > This is the logical definition of loss of carrier is it not? > you could arange to get a signal possibly.. (I'd have ot go back and look > again).. Absolutely. I've no problem with that. Except that tip checks errno in order to decide whether to exit or not (in tipout.c) If errno has not been set, it simply loops. Don't know if that's a problem with the tip code, or whether it's something else. That's why I get tip looping after the modem loses its carrier. One way of getting tipout to exit is for it to receive a signal from its parent process - I can do this by hitting any key after carrier is lost, and tipin() in tip.c will send the child a signal. > > > > > I ask this because in the tip code there is a loop > > that exits only once errno is set to these values. This > > means that after the modem's lost carrier my tip session > > fails to exit. > > > > The code is as follows: > > > > /* while some condition */ > > > > cnt = read(FD, buf, BUFSIZ); > > if (cnt <= 0) { > > /* lost carrier */ > > if (cnt < 0 && errno == EIO) { > > sigblock(sigmask(SIGTERM)); > > intTERM(); > > /*NOTREACHED*/ > > } else if (cnt == 0 && errno == ENOENT) { > > kill(getppid(),SIGUSR1); > > sigblock(sigmask(SIGTERM)); > > intTERM(); > > /*NOTREACHED*/ > > } else { > > printf("%d %d\r",cnt,errno); > > fflush(stdout); > > } > > continue; > > } > > /* end */ > > > > Thanks, > > > > Raoul. > > > > hmm interesting.. lemme see what psix says.. (if anything...) > nothing in read() > > hey are you openning cuax or ttyX? > My tip has been configured to open /dev/cuax. I'm assuming that tip isn't doing anything funny, and that FD points to /dev/cuax as well. I've changed the code above to be: /* while some condition */ cnt = read(FD, buf, BUFSIZ); if (cnt <= 0) { /* lost carrier */ if (cnt <= 0) { kill(getppid(),SIGUSR1); sigblock(sigmask(SIGTERM)); intTERM(); /*NOTREACHED*/ } continue; } /* end */ and now tip exits cleanly. But I wonder why it was written as it was in the first place. Raoul
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199510090412.OAA07782>