From: htoaster@yabbs To: xenon@yabbs Subject: re: Loop until keypress Date: Tue Nov 9 16:05:12 1993 In message re: Loop until keypress, xenon said: > well, ive hacked on select() fer a bit, looked at the man page and wrote > sum test programs, but havent figured it out yet...since its non-ANSI, i > havent had much luck in the couple of ANSI-C texts i have. anywayz, do > you know of any books i could look at that might give a better description > than the man pages (i hate tryin to decypher those damn things). want some demo code? Here is the rthe yabbs client: while (!readkey) { FD_ZERO(&fds); /* zero bitfields for select */ FD_SET(STDIN, &fds); /* check standard input */ FD_SET(s, &fds); /* check server socket */ if (select(s+1, &fds, (fd_set *)NULL, (fd_set *)NULL, NULL) == -1) { perror("readc:select"); } /* if our message is from stdin handle it, otherwise it is from * the server, so let handlemsg() take care of it */ if (FD_ISSET(s, &fds)) { handlemsg(); /* read and deal with packet */ } else if (FD_ISSET(STDIN, &fds)) { line = 1; ch = fgetc(stdin); if ((ch == 4) && (och <= 127)) killconnection(K_USER); else if ((ch != 8) && (ch != 10) && (ch != 13) && (ch != '\t') && (ch != 21) && (ch < 32) && (ch > 127)) readkey = FALSE; else if ((ch == '\n') && (och == '\r')) readkey = FALSE; else { och = ch; readkey = TRUE; return ch; } } } this doesn't use the timeout stuff (last parameter to select), but I could explain that as well. Also, for those hackers of you out there, this is the code that causes problems with reading passwords (double return), I think, so if you see anything stupid in here yell at me. I haven't looked at the code in ages, since it hasn't changed much since the first day that I started yabbs. alex