libfuse
poll_client.c
Go to the documentation of this file.
1 /*
2  FUSE fselclient: FUSE select example client
3  Copyright (C) 2008 SUSE Linux Products GmbH
4  Copyright (C) 2008 Tejun Heo <teheo@suse.de>
5 
6  This program can be distributed under the terms of the GNU GPL.
7  See the file COPYING.
8 */
9 
22 #include <config.h>
23 
24 #include <sys/select.h>
25 #include <sys/time.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <fcntl.h>
29 #include <unistd.h>
30 #include <ctype.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <errno.h>
34 
35 #define FSEL_FILES 16
36 
37 int main(void)
38 {
39  static const char hex_map[FSEL_FILES] = "0123456789ABCDEF";
40  int fds[FSEL_FILES];
41  int i, nfds, tries;
42 
43  for (i = 0; i < FSEL_FILES; i++) {
44  char name[] = { hex_map[i], '\0' };
45  fds[i] = open(name, O_RDONLY);
46  if (fds[i] < 0) {
47  perror("open");
48  return 1;
49  }
50  }
51  nfds = fds[FSEL_FILES - 1] + 1;
52 
53  for(tries=0; tries < 16; tries++) {
54  static char buf[4096];
55  fd_set rfds;
56  int rc;
57 
58  FD_ZERO(&rfds);
59  for (i = 0; i < FSEL_FILES; i++)
60  FD_SET(fds[i], &rfds);
61 
62  rc = select(nfds, &rfds, NULL, NULL, NULL);
63 
64  if (rc < 0) {
65  perror("select");
66  return 1;
67  }
68 
69  for (i = 0; i < FSEL_FILES; i++) {
70  if (!FD_ISSET(fds[i], &rfds)) {
71  printf("_: ");
72  continue;
73  }
74  printf("%X:", i);
75  rc = read(fds[i], buf, sizeof(buf));
76  if (rc < 0) {
77  perror("read");
78  return 1;
79  }
80  printf("%02d ", rc);
81  }
82  printf("\n");
83  }
84  return 0;
85 }