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