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 GPLv2.
7 See the file GPL2.txt.
8*/
9
21
22
23#include <sys/select.h>
24#include <sys/time.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <fcntl.h>
28#include <unistd.h>
29#include <ctype.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <errno.h>
33
34int main(void)
35{
36 static const char hex_map[] = "0123456789ABCDEF";
37 const size_t fsel_files = sizeof(hex_map) - 1;
38 int fds[sizeof(hex_map) - 1];
39 size_t i, tries;
40 int nfds;
41
42 for (i = 0; i < fsel_files; i++) {
43 char name[] = { hex_map[i], '\0' };
44 fds[i] = open(name, O_RDONLY);
45 if (fds[i] < 0) {
46 perror("open");
47 return 1;
48 }
49 }
50 nfds = fds[fsel_files - 1] + 1;
51
52 for (tries = 0; tries < fsel_files; tries++) {
53 static char buf[4096];
54 fd_set rfds;
55 int rc;
56
57 FD_ZERO(&rfds);
58 for (i = 0; i < fsel_files; i++)
59 FD_SET(fds[i], &rfds);
60
61 rc = select(nfds, &rfds, NULL, NULL, NULL);
62
63 if (rc < 0) {
64 perror("select");
65 return 1;
66 }
67
68 for (i = 0; i < fsel_files; i++) {
69 if (!FD_ISSET(fds[i], &rfds)) {
70 printf("_: ");
71 continue;
72 }
73 printf("%zX:", i);
74 rc = read(fds[i], buf, sizeof(buf));
75 if (rc < 0) {
76 perror("read");
77 return 1;
78 }
79 printf("%02d ", rc);
80 }
81 printf("\n");
82 }
83 return 0;
84}