# HG changeset patch # User Bruno Haible # Date 1293472411 -3600 # Node ID 483bac6e8bce0988903c7b16d749030e5f3c28cc # Parent eb1a951e4f56be16bfbcfe9e249b4bd674788c85 select tests: Improve comments. * tests/test-select.c (do_select): Add comments. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-12-27 Bruno Haible + + select tests: Improve comments. + * tests/test-select.c (do_select): Add comments. + 2010-12-27 Bruno Haible select tests: Safer way of handling timeout. diff --git a/tests/test-select.c b/tests/test-select.c --- a/tests/test-select.c +++ b/tests/test-select.c @@ -51,8 +51,6 @@ #include "macros.h" -enum { SEL_IN = 1, SEL_OUT = 2, SEL_EXC = 4 }; - #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ # define WIN32_NATIVE #endif @@ -165,10 +163,20 @@ } -/* 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 @@ 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; @@ -217,7 +225,7 @@ } -/* Test poll(2) for TTYs. */ +/* Test select(2) for TTYs. */ #ifdef INTERACTIVE static void @@ -238,7 +246,7 @@ #endif -/* Test poll(2) for unconnected nonblocking sockets. */ +/* Test select(2) for unconnected nonblocking sockets. */ static void test_connect_first (void) @@ -267,7 +275,7 @@ } -/* Test poll(2) for unconnected blocking sockets. */ +/* Test select(2) for unconnected blocking sockets. */ static void test_accept_first (void) @@ -333,7 +341,7 @@ } -/* Test poll(2) on connected sockets. */ +/* Test select(2) on connected sockets. */ static void test_socket_pair (void) @@ -354,7 +362,7 @@ } -/* Test poll(2) on pipes. */ +/* Test select(2) on pipes. */ static void test_pipe (void)