home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / hp / 12690 < prev    next >
Encoding:
Text File  |  1992-11-09  |  3.3 KB  |  117 lines

  1. Xref: sparky comp.sys.hp:12690 comp.unix.programmer:5216
  2. Newsgroups: comp.sys.hp,comp.unix.programmer
  3. Path: sparky!uunet!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!hobbes.physics.uiowa.edu!news.uiowa.edu!icaen!dsiebert
  4. From: dsiebert@icaen.uiowa.edu (Doug Siebert)
  5. Subject: How does flow control work for pseudo ttys under HP-UX?
  6. Message-ID: <1992Nov9.064654.9997@icaen.uiowa.edu>
  7. Sender: usenet@icaen.uiowa.edu (UseNet News daemon)
  8. Organization: ISCA
  9. Date: Mon, 9 Nov 1992 06:46:54 GMT
  10. Lines: 105
  11.  
  12. Sorry if this is posted twice -- my news server was having problems when I made
  13. the first attempt and so far as I can tell it was never actually posted.
  14.  
  15. I can't seem to figure out how flow control is supposed to work for pseudo
  16. ttys under HP-UX, which uses the termios struct to control pty/tty modes.
  17. According to the man pages, setting IXOFF should turn on input flow control,
  18. but this doesn't seem to work for me.  I wrote a short test program to try to
  19. learn something, but it didn't help much.  Here it is, followed by a sample of
  20. its output.  Can anyone explain to me what is missing to make flow control
  21. work properly?
  22.  
  23. I should be able to select on the master and slave sides, and determine when
  24. the input queue is full by the slave side no longer selecting for write.  This
  25. condition nevers occurs though.  It is obvious characters are being lost,
  26. however!
  27.  
  28.  
  29. ---cut here---
  30.  
  31. #include <sys/file.h>
  32. #include <sys/ioctl.h>
  33. #include <termios.h>
  34.  
  35. char    bufw[256];
  36. char    bufr[128];
  37.  
  38. main()
  39. {
  40.   int     p,
  41.           t;
  42.   int     w,
  43.           r;
  44.   int     i;
  45.   struct termios termbuf;
  46.   fd_set  rf,
  47.           wf;
  48.  
  49.   p = open("/dev/ptym/ptyo0", O_RDWR);
  50.   if (p < 0)
  51.     perror("pty");
  52.   t = open("/dev/pty/ttyo2", O_RDWR);
  53.   if (t < 0)
  54.     perror("tty");
  55.   i = 1;
  56.   ioctl(p, FIOSNBIO, &i);
  57.   i = 1;
  58.   ioctl(t, FIOSNBIO, &i);
  59.   tcgetattr(p, &termbuf);
  60.   termbuf.c_iflag |= IXOFF;
  61.   termbuf.c_lflag &= ~ICANON & ~ECHO;
  62.   tcsetattr(p, &termbuf, TCSADRAIN);
  63.   tcgetattr(t, &termbuf);
  64.   termbuf.c_iflag |= IXOFF;
  65.   termbuf.c_lflag &= ~ICANON & ~ECHO;
  66.   tcsetattr(t, &termbuf, TCSADRAIN);
  67.   for (;;)
  68.   {
  69.     FD_ZERO(&rf);
  70.     FD_ZERO(&wf);
  71.     FD_SET(p, &wf);
  72.     FD_SET(t, &rf);
  73.     i = select(10, &rf, &wf, 0, 0);
  74.     if (i < 1)
  75.       perror("select");
  76.     w = r = -2;
  77.     if (FD_ISSET(p, &wf))
  78.       w = write(p, bufw, sizeof bufw);
  79.     if (FD_ISSET(t, &rf))
  80.       r = read(t, bufr, sizeof bufr);
  81.     printf("wrote %d, read %d\n", w, r);
  82.     sleep(1);
  83.   }
  84. }
  85.  
  86. ---cut here---
  87.  
  88.  
  89. Here is the output of a run of this program:
  90.  
  91. # ./test
  92. wrote 256, read -2
  93. wrote 256, read 128
  94. wrote 256, read 128
  95. wrote 256, read 128
  96. wrote 256, read 126
  97. wrote 256, read -2
  98. wrote 256, read 128
  99. wrote 256, read 128
  100. wrote 256, read 128
  101. wrote 256, read 126
  102. wrote 256, read -2
  103.  
  104. [...and so on...]
  105.  
  106.  
  107. Can anyone tell me what I am missing here?  It *should* work, according to TFM,
  108. but it doesn't.  Any help out there?
  109.  
  110. -- 
  111. /-----------------------------------------------------------------------------\
  112. | Doug Siebert                             | "I don't have to take this abuse |
  113. | Internet:  dsiebert@isca.uiowa.edu       |  from you - I've got hundreds of |
  114. | NeXTMail:  dsiebert@chop.isca.uiowa.edu  |  people waiting in line to abuse |
  115. |     ICBM:  41d 39m 55s N, 91d 30m 43s W  |  me!"  Bill Murray, Ghostbusters |
  116. \-----------------------------------------------------------------------------/
  117.