home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / question / 9653 < prev    next >
Encoding:
Internet Message Format  |  1992-07-31  |  1.6 KB

  1. Xref: sparky comp.unix.questions:9653 comp.unix.programmer:4047
  2. Newsgroups: comp.unix.questions,comp.unix.programmer
  3. Path: sparky!uunet!caen!nic.umass.edu!hamp.hampshire.edu!dhirmes
  4. From: dhirmes@hamp.hampshire.edu
  5. Subject: need help with select() problem
  6. Message-ID: <1992Jul31.152219.1@hamp.hampshire.edu>
  7. Lines: 48
  8. Sender: usenet@nic.umass.edu (USENET News System)
  9. Nntp-Posting-Host: hamp.hampshire.edu
  10. Organization: Hampshire College
  11. Date: Fri, 31 Jul 1992 19:22:19 GMT
  12.  
  13.  
  14. I'm trying to write a routine that will send stdin out a stream socket
  15. and receive data coming in from a stream socket at the same time. To
  16. do this, I'm using select(2).  But when I run the following routine
  17. in my program, it just sits there.
  18. After many hours of fiddling, I can't seem to figure out the problem.
  19. Any ideas?
  20.  
  21. dhirmes@hamp.hampshire.edu
  22.  
  23.  
  24.     ear is a fd for a listening socket...
  25.  
  26.     FD_ZERO(&sock_set);
  27.     FD_SET(ear,&sock_set);
  28.     FD_SET(fileno(stdin),&sock_set);
  29.     backup = sock_set;
  30.  
  31.     while(1) {
  32.       wait.tv_sec = A_LONG_TIME;
  33.       wait.tv_usec = 0;
  34.       nb = select(64, &sock_set, 0, 0, &wait);
  35.  
  36.       if (nb < 0) {
  37.         perror("select");
  38.         exit(0);
  39.       }
  40.       if (FD_ISSET(ear,&sock_set) != 0) {
  41.         nb = read(ear, temp2, sizeof temp2);
  42.         if (nb < 0) {
  43.           perror("read");
  44.           exit(0);
  45.         }
  46.         printf("[%s]",temp2);
  47.         sock_set = backup;
  48.       }
  49.       if (FD_ISSET(fileno(stdin),&sock_set) != 0) {
  50.         ioctl(0, FIONREAD, (struct sgttyb *) &nb);
  51.         nb = read(0, temp, nb);
  52.         nb = write(s_talk, temp, nb);
  53.         if (nb < 0) {
  54.           perror("write");
  55.           exit(0);
  56.         }
  57.         sock_set = backup;
  58.       }
  59.     }
  60.  
  61.