Problem with pseudo ttys on Sun.

Rich Burridge richb at yarra.OZ
Sun Jul 6 10:34:10 AEST 1986


Help is desperately needed with the following "problem".

I am running Sun 3.0 (Generic) on a Sun 3/50 with an 112 Meg shoebox.

I am trying to use the pseudo ttys ttyq0-ttyq6 to transfer data from other
programs into my program.

Inside my program I open say, ptyq5 (the MASTER pty) with:

      int fpty ;

      if (fpty = open("/dev/ptyq5",2)) < 0)
        {
          fprintf(stderr,"can't open pseudo\n") ;
          exit(1) ;
        }

I then set it into RAW mode with:

      struct sgttyb pty ;

      gtty(fpty,&pty) ;
      pty.sg_flags |= RAW ;
      stty(fpty,&pty) ;

Now to test if there is any thing to read on that pty, I use the select call.

      int readmask,nfds ;
      static struct timeval timeout = { 0,0 } ;

      readmask = 1 << fpty ;
      nfds = select(32,&readmask,(int *)0,(int *)0,&timeout) ;

Say I used 'cat' to redirect a small file to /dev/ttyq5, as this was happening
nfds returned a 1 to indicate that there was a file descriptor with 
outstanding data to be read, and the readmask had the appropriate bit set.

So, I read the data from the pseudo tty with:

      #define  MAXDATA  32

      char buffer[MAXDATA] ;
      int nread ;

      if (nfds ==1)
        nread = read(fpty,buffer,MAXDATA) ;

nread normally contains the number of bytes read (which will be MAXDATA, up
until the "last" time which will return a smaller value; the remainder left
to read).
Now what I would expect is that when I come to do the select call again, it
should return 0 and the readmask should also be zero. But no, it tells me
that there is data to be read, and when I use the read call as above, it
returns -1 in nread with errno set to 5 (EIO I/O error).

Where am I going wrong?

Please answer by mail, as I'm about a week behind reading the net.

Thanks in advance.

Rich Burridge            ISD:  +61 3 267-6222
Sun Australia            STD:  (03) 267-6222
14 Queens Rd,            ARPA: richb%yarra.oz at seismo.arpa
Melbourne, VIC 3004.     UUCP: seismo!munnari!yarra.oz!richb
AUSTRALIA.               ACS:  richb at yarra.oz
D



More information about the Comp.unix.wizards mailing list