home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.questions:9653 comp.unix.programmer:4047
- Newsgroups: comp.unix.questions,comp.unix.programmer
- Path: sparky!uunet!caen!nic.umass.edu!hamp.hampshire.edu!dhirmes
- From: dhirmes@hamp.hampshire.edu
- Subject: need help with select() problem
- Message-ID: <1992Jul31.152219.1@hamp.hampshire.edu>
- Lines: 48
- Sender: usenet@nic.umass.edu (USENET News System)
- Nntp-Posting-Host: hamp.hampshire.edu
- Organization: Hampshire College
- Date: Fri, 31 Jul 1992 19:22:19 GMT
-
-
- I'm trying to write a routine that will send stdin out a stream socket
- and receive data coming in from a stream socket at the same time. To
- do this, I'm using select(2). But when I run the following routine
- in my program, it just sits there.
- After many hours of fiddling, I can't seem to figure out the problem.
- Any ideas?
-
- dhirmes@hamp.hampshire.edu
-
-
- ear is a fd for a listening socket...
-
- FD_ZERO(&sock_set);
- FD_SET(ear,&sock_set);
- FD_SET(fileno(stdin),&sock_set);
- backup = sock_set;
-
- while(1) {
- wait.tv_sec = A_LONG_TIME;
- wait.tv_usec = 0;
- nb = select(64, &sock_set, 0, 0, &wait);
-
- if (nb < 0) {
- perror("select");
- exit(0);
- }
- if (FD_ISSET(ear,&sock_set) != 0) {
- nb = read(ear, temp2, sizeof temp2);
- if (nb < 0) {
- perror("read");
- exit(0);
- }
- printf("[%s]",temp2);
- sock_set = backup;
- }
- if (FD_ISSET(fileno(stdin),&sock_set) != 0) {
- ioctl(0, FIONREAD, (struct sgttyb *) &nb);
- nb = read(0, temp, nb);
- nb = write(s_talk, temp, nb);
- if (nb < 0) {
- perror("write");
- exit(0);
- }
- sock_set = backup;
- }
- }
-
-