libfuse: fuse-3.18.1/example/poll_client.c Source File

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
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
34#define FSEL_FILES 16
35
36int main(void)
37{
38 static const char hex_map[FSEL_FILES] = "0123456789ABCDEF";
39 int fds[FSEL_FILES];
40 int i, nfds, tries;
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 < 16; 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("%X:", 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}