From d385e41390cef36bc4811cefe285f6243c6da1eb Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 27 Dec 2010 18:53:31 +0100 Subject: [PATCH] select tests: Improve comments. * tests/test-select.c (do_select): Add comments. --- ChangeLog | 5 +++++ tests/test-select.c | 28 ++++++++++++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index f9a3dc7c7..dc5dc401f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 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. * tests/test-select.c (do_select_nowait): Zero-initialize the timeout at every invocation. diff --git a/tests/test-select.c b/tests/test-select.c index 365d1d2b9..ac847ece1 100644 --- a/tests/test-select.c +++ b/tests/test-select.c @@ -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 @@ -165,10 +163,20 @@ connect_to_socket (bool 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; @@ -217,7 +225,7 @@ do_select_wait (int fd, int ev) } -/* Test poll(2) for TTYs. */ +/* Test select(2) for TTYs. */ #ifdef INTERACTIVE static void @@ -238,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) @@ -267,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) @@ -333,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) @@ -354,7 +362,7 @@ test_socket_pair (void) } -/* Test poll(2) on pipes. */ +/* Test select(2) on pipes. */ static void test_pipe (void) -- 2.11.0