home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / modem-ctl / line.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-24  |  2.3 KB  |  75 lines

  1. /*
  2.  * line.c: set up the various termio params for the line at various stages.
  3.  * [What I would like for Christmas: System V tty driver code, so I could
  4.  *  find out why it behaves so strangely ... ]
  5.  */
  6.  
  7. #include "modem.h"
  8. #include <termio.h>
  9. #include <fcntl.h>
  10.  
  11. static struct termio term;
  12. static int speed;
  13.  
  14. init_term(device, baud)
  15. int device, baud;
  16. {
  17.     speed = baud;
  18.     if(ioctl(device, TCGETA, &term) == -1) perror("TCGETA");
  19.     term.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK);
  20.     term.c_iflag &= ~(ISTRIP | INPCK);
  21.     term.c_cflag &= ~(CBAUD | CSIZE);
  22.     term.c_cflag |= baud | CS8 | CLOCAL;
  23.     term.c_cc[VMIN] = 1;
  24.     term.c_cc[VTIME] = 0;
  25.      if(ioctl(device, TCSETA, &term) == -1) perror("TCSETA");
  26. /*
  27.  * Since we opened the line with O_NDELAY, reads will return immediately if
  28.  * no chars are ready. We don't really want this, 'cos "dread" will then
  29.  * eat CPU time, so we turn it off.
  30.  * It only seems to be really effective when the device is opened again -
  31.  * otherwise we get strange diagnostics about "wrote 0 of 4". Thanks to
  32.  * the C-KERMIT crew for this tip.
  33.  *
  34.  * The open() here seems to hang sometimes, so a timeout is implemented.
  35.  * [since CLOCAL has been set above, this should never happen. We can't
  36.  *  just open with O_NDELAY, because uucp won't work anyway.]
  37.  */
  38.      fcntl(device, F_SETFL, 0);
  39.      alarm(5);
  40.      if(close(open(dname, O_RDONLY)) == -1 ) {
  41.          printf("** Error: Couldn't reopen device after TCSETA\n");
  42.          exit(1);
  43.      }
  44.      alarm(0);
  45. }
  46. /*
  47.  * Strange things have been known to happen during "login" with incorrect 
  48.  * settings - if it forgets to ask you for a password, check them carefully.
  49.  * Oct 87: Disable CLOCAL, since DCD is now asserted, and we want to be told
  50.  * about hangups.
  51.  */
  52. login_term(device, baud)
  53. int device, baud;
  54. {
  55.     ioctl(device, TCGETA, &term);
  56.     term.c_cc[VEOF] = 04;        /* cntrl-D */
  57.     term.c_iflag = BRKINT | IGNPAR | ISTRIP | ICRNL;
  58.     term.c_oflag = OPOST | ONLCR | TAB3;
  59.     term.c_cflag &= ~(CSIZE | CLOCAL | CBAUD);
  60.     term.c_cflag |= CS7 | HUPCL | CREAD | baud;
  61.     term.c_lflag = ISIG | ICANON;
  62.     ioctl(device, TCSETAW, &term);
  63. }
  64. /*
  65.  * fixline: write failed - redo settings on line.
  66.  */
  67. fixline(){
  68.     ioctl(dev, TCFLSH, 2);        /* flush queues */
  69.     ioctl(dev, TCXONC, 1);        /* restart XON/XOFF */
  70.     fcntl(dev, F_SETFL, 0);        /* poke the flag */
  71.     close(open(dname, O_RDONLY | O_NDELAY));
  72.     init_term(dev, speed);
  73. }
  74.     
  75.