h_client.c revision 1.2.2.2 1 1.2.2.2 bouyer /* $NetBSD: h_client.c,v 1.2.2.2 2011/02/17 12:00:54 bouyer Exp $ */
2 1.2.2.2 bouyer
3 1.2.2.2 bouyer /*
4 1.2.2.2 bouyer * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 1.2.2.2 bouyer * All rights reserved.
6 1.2.2.2 bouyer *
7 1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
8 1.2.2.2 bouyer * modification, are permitted provided that the following conditions
9 1.2.2.2 bouyer * are met:
10 1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
11 1.2.2.2 bouyer * notice, this list of conditions and the following disclaimer.
12 1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
14 1.2.2.2 bouyer * documentation and/or other materials provided with the distribution.
15 1.2.2.2 bouyer *
16 1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 1.2.2.2 bouyer * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 1.2.2.2 bouyer * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 1.2.2.2 bouyer * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.2.2.2 bouyer * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 1.2.2.2 bouyer * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 1.2.2.2 bouyer * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 1.2.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 1.2.2.2 bouyer * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 1.2.2.2 bouyer * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 1.2.2.2 bouyer * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.2.2.2 bouyer */
29 1.2.2.2 bouyer
30 1.2.2.2 bouyer #include <sys/types.h>
31 1.2.2.2 bouyer #include <sys/select.h>
32 1.2.2.2 bouyer
33 1.2.2.2 bouyer #include <err.h>
34 1.2.2.2 bouyer #include <errno.h>
35 1.2.2.2 bouyer #include <stdio.h>
36 1.2.2.2 bouyer #include <stdlib.h>
37 1.2.2.2 bouyer #include <string.h>
38 1.2.2.2 bouyer #include <unistd.h>
39 1.2.2.2 bouyer
40 1.2.2.2 bouyer int
41 1.2.2.2 bouyer main(int argc, char *argv[])
42 1.2.2.2 bouyer {
43 1.2.2.2 bouyer
44 1.2.2.2 bouyer if (argc != 2) {
45 1.2.2.2 bouyer errx(1, "need testname as param");
46 1.2.2.2 bouyer }
47 1.2.2.2 bouyer
48 1.2.2.2 bouyer if (strcmp(argv[1], "select_timeout") == 0) {
49 1.2.2.2 bouyer fd_set rfds;
50 1.2.2.2 bouyer struct timeval tv;
51 1.2.2.2 bouyer int rv;
52 1.2.2.2 bouyer
53 1.2.2.2 bouyer tv.tv_sec = 0;
54 1.2.2.2 bouyer tv.tv_usec = 1;
55 1.2.2.2 bouyer
56 1.2.2.2 bouyer FD_ZERO(&rfds);
57 1.2.2.2 bouyer FD_SET(STDIN_FILENO, &rfds);
58 1.2.2.2 bouyer
59 1.2.2.2 bouyer rv = select(STDIN_FILENO+1, &rfds, NULL, NULL, &tv);
60 1.2.2.2 bouyer if (rv == -1)
61 1.2.2.2 bouyer err(1, "select");
62 1.2.2.2 bouyer if (rv != 0)
63 1.2.2.2 bouyer errx(1, "select succesful");
64 1.2.2.2 bouyer
65 1.2.2.2 bouyer if (FD_ISSET(STDIN_FILENO, &rfds))
66 1.2.2.2 bouyer errx(1, "stdin fileno is still set");
67 1.2.2.2 bouyer exit(0);
68 1.2.2.2 bouyer } else if (strcmp(argv[1], "select_allunset") == 0) {
69 1.2.2.2 bouyer fd_set fds;
70 1.2.2.2 bouyer struct timeval tv;
71 1.2.2.2 bouyer int rv;
72 1.2.2.2 bouyer
73 1.2.2.2 bouyer tv.tv_sec = 0;
74 1.2.2.2 bouyer tv.tv_usec = 1;
75 1.2.2.2 bouyer
76 1.2.2.2 bouyer FD_ZERO(&fds);
77 1.2.2.2 bouyer
78 1.2.2.2 bouyer rv = select(100, &fds, &fds, &fds, &tv);
79 1.2.2.2 bouyer if (rv == -1)
80 1.2.2.2 bouyer err(1, "select");
81 1.2.2.2 bouyer if (rv != 0)
82 1.2.2.2 bouyer errx(1, "select succesful");
83 1.2.2.2 bouyer
84 1.2.2.2 bouyer rv = select(0, NULL, NULL, NULL, &tv);
85 1.2.2.2 bouyer if (rv == -1)
86 1.2.2.2 bouyer err(1, "select2");
87 1.2.2.2 bouyer if (rv != 0)
88 1.2.2.2 bouyer errx(1, "select2 succesful");
89 1.2.2.2 bouyer
90 1.2.2.2 bouyer exit(0);
91 1.2.2.2 bouyer } else {
92 1.2.2.2 bouyer return ENOTSUP;
93 1.2.2.2 bouyer }
94 1.2.2.2 bouyer }
95