X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-select.c;h=5c1532015da7ddffdf7114c7bffb9592667071b2;hb=ca6143b425589c3a64bd28efd7af14463f96d576;hp=bc5c1a9365bda6b5aabd0f202bbcc7109b3b259b;hpb=c40a9f2f5a7513839f33eac98a362e3f4fd58f5b;p=gnulib.git diff --git a/tests/test-select.c b/tests/test-select.c index bc5c1a936..5c1532015 100644 --- a/tests/test-select.c +++ b/tests/test-select.c @@ -1,5 +1,5 @@ /* Test of select() substitute. - Copyright (C) 2008-2010 Free Software Foundation, Inc. + Copyright (C) 2008-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,8 +51,6 @@ SIGNATURE_CHECK (FD_ZERO, void, (fd_set *)); #include "macros.h" -enum { SEL_IN = 1, SEL_OUT = 2, SEL_EXC = 4 }; - #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ # define WIN32_NATIVE #endif @@ -128,7 +126,7 @@ open_server_socket (void) } static int -connect_to_socket (int blocking) +connect_to_socket (bool blocking) { int s; struct sockaddr_in ia; @@ -165,10 +163,20 @@ connect_to_socket (int blocking) } -/* A slightly more convenient interface to select(2). */ +/* A slightly more convenient interface to select(2). + Waits until a specific event occurs on a file descriptor FD. + EV is a bit mask of events to look for: + SEL_IN - input can be polled without blocking, + SEL_OUT - output can be provided without blocking, + SEL_EXC - an exception occurred, + A maximum wait time is specified by TIMEOUT. + *TIMEOUT = { 0, 0 } means to return immediately, + TIMEOUT = NULL means to wait indefinitely. */ + +enum { SEL_IN = 1, SEL_OUT = 2, SEL_EXC = 4 }; static int -do_select (int fd, int ev, struct timeval *tv) +do_select (int fd, int ev, struct timeval *timeout) { fd_set rfds, wfds, xfds; int r, rev; @@ -182,7 +190,7 @@ do_select (int fd, int ev, struct timeval *tv) FD_SET (fd, &wfds); if (ev & SEL_EXC) FD_SET (fd, &xfds); - r = select (fd + 1, &rfds, &wfds, &xfds, tv); + r = select (fd + 1, &rfds, &wfds, &xfds, timeout); if (r < 0) return r; @@ -204,7 +212,9 @@ do_select (int fd, int ev, struct timeval *tv) static int do_select_nowait (int fd, int ev) { - static struct timeval tv0; + struct timeval tv0; + tv0.tv_sec = 0; + tv0.tv_usec = 0; return do_select (fd, ev, &tv0); } @@ -215,7 +225,7 @@ do_select_wait (int fd, int ev) } -/* Test poll(2) for TTYs. */ +/* Test select(2) for TTYs. */ #ifdef INTERACTIVE static void @@ -236,7 +246,7 @@ test_tty (void) #endif -/* Test poll(2) for unconnected nonblocking sockets. */ +/* Test select(2) for unconnected nonblocking sockets. */ static void test_connect_first (void) @@ -265,7 +275,7 @@ test_connect_first (void) } -/* Test poll(2) for unconnected blocking sockets. */ +/* Test select(2) for unconnected blocking sockets. */ static void test_accept_first (void) @@ -331,7 +341,7 @@ test_pair (int rd, int wd) } -/* Test poll(2) on connected sockets. */ +/* Test select(2) on connected sockets. */ static void test_socket_pair (void) @@ -352,7 +362,7 @@ test_socket_pair (void) } -/* Test poll(2) on pipes. */ +/* Test select(2) on pipes. */ static void test_pipe (void)