multiplexing.c
00001 #include <sys/time.h>
00002 #include <sys/types.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include <unistd.h>
00007
00008 #undef max
00009 #define max(x,y) ((x) > (y) ? (x) : (y)) // Calcul du maximum.
00010
00011 void error(char * msg);
00012 int main()
00013 {
00014 struct timeval delai = { 3, 500000 };
00015 fd_set desclecture;
00016 int max_desc = 0;
00017 int desc_sock;
00018
00019
00020 FD_ZERO(&desclecture);
00021 FD_SET(STDIN_FILENO, &desclecture);
00022 max_desc = max(max_desc, STDIN_FILENO);
00023
00024 FD_SET(desc_sock, &desclecture);
00025 max_desc = max(max_desc, desc_sock);
00026
00027 int r = select(max_desc+1, &desclecture, NULL, NULL, &delai);
00028 if (r < 0) error("[select]");
00029 if (r == 0) printf("Aucune activité pendant la durée du délai.\n");
00030 if (FD_ISSET(STDIN_FILENO, &desclecture))
00031 printf("La touche ENTREE a été pressée.\n");
00032 if (FD_ISSET(desc_sock, &desclecture)) {
00033
00034 }
00035 return 0;
00036 }
00037
00038 void error(char * msg) {
00039 perror(msg);
00040 exit(1);
00041 }