Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Oct 1995 11:19:40 +1000 (EST)
From:      raoul@cssc-syd.tansu.com.au (Raoul Golan)
To:        freebsd-questions@freebsd.org
Subject:   Question on read syscall on serial port
Message-ID:  <199510090119.LAA07559@kiwi.cssc-syd.tansu.com.au>

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

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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199510090119.LAA07559>