From: Eric Blake Date: Fri, 8 Apr 2011 17:51:45 +0000 (-0600) Subject: nonblocking: reduce dependency X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a1579d7560659ef5723325726eda14490a967f6;p=pspp nonblocking: reduce dependency No need to make nonblocking drag in sockets just for a test; test them if they are present and skip them otherwise. * tests/test-nonblocking.c: Only test sockets when in use. * modules/nonblocking-tests (Depends-on): Drop socket. (Makefile.am): Link even if sockets are not present. * modules/pipe2-tests (Makefile.am): Likewise. * lib/ioctl.c (ioctl) [WIN32]: Fail if sockets are not also in use. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index a8d45212ff..099dbd7abf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2011-04-08 Eric Blake + nonblocking: reduce dependency + * tests/test-nonblocking.c: Only test sockets when in use. + * modules/nonblocking-tests (Depends-on): Drop socket. + (Makefile.am): Link even if sockets are not present. + * modules/pipe2-tests (Makefile.am): Likewise. + * lib/ioctl.c (ioctl) [WIN32]: Fail if sockets are not also in use. + pipe2: fix O_NONBLOCK support on mingw * modules/pipe2 (Depends-on): Add nonblocking. * lib/pipe2.c (pipe2) [WIN32]: Add O_NONBLOCK support. diff --git a/lib/ioctl.c b/lib/ioctl.c index 4bbed7653d..00caf3b187 100644 --- a/lib/ioctl.c +++ b/lib/ioctl.c @@ -54,6 +54,7 @@ rpl_ioctl (int fd, int request, ... /* {void *,char *} arg */) int ioctl (int fd, int req, ...) { +# if GNULIB_SOCKET void *buf; va_list args; SOCKET sock; @@ -73,6 +74,11 @@ ioctl (int fd, int req, ...) set_winsock_errno (); return r; + +# else + errno = ENOSYS; + return -1; +# endif } #endif diff --git a/modules/nonblocking-tests b/modules/nonblocking-tests index 34d206d779..a1e5e7c03c 100644 --- a/modules/nonblocking-tests +++ b/modules/nonblocking-tests @@ -5,11 +5,10 @@ tests/macros.h Depends-on: close pipe-posix -socket configure.ac: Makefile.am: TESTS += test-nonblocking check_PROGRAMS += test-nonblocking -test_nonblocking_LDADD = $(LDADD) @LIBSOCKET@ +test_nonblocking_LDADD = $(LDADD) $(LIBSOCKET) diff --git a/modules/pipe2-tests b/modules/pipe2-tests index 9e751dc327..2e6c3f78a7 100644 --- a/modules/pipe2-tests +++ b/modules/pipe2-tests @@ -11,4 +11,4 @@ configure.ac: Makefile.am: TESTS += test-pipe2 check_PROGRAMS += test-pipe2 -test_pipe2_LDADD = $(LDADD) @LIBSOCKET@ +test_pipe2_LDADD = $(LDADD) $(LIBSOCKET) diff --git a/tests/test-nonblocking.c b/tests/test-nonblocking.c index f1b7610543..bfeef7bf71 100644 --- a/tests/test-nonblocking.c +++ b/tests/test-nonblocking.c @@ -33,13 +33,6 @@ main (void) const char *file = "test-nonblock.tmp"; int fd_file; int fd_pipe[2]; - int fd_sock; - bool sock_works = true; - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* For now, we can't get nonblocking status of windows sockets. */ - sock_works = false; -#endif fd_file = creat (file, 0600); @@ -79,28 +72,39 @@ main (void) ASSERT (close (fd_pipe[1]) == 0); #if GNULIB_TEST_PIPE2 - /* mingw still lacks O_NONBLOCK replacement. */ ASSERT (pipe2 (fd_pipe, O_NONBLOCK) == 0); - ASSERT (get_nonblocking_flag (fd_pipe[0]) == !!O_NONBLOCK); - ASSERT (get_nonblocking_flag (fd_pipe[1]) == !!O_NONBLOCK); + ASSERT (get_nonblocking_flag (fd_pipe[0]) == 1); + ASSERT (get_nonblocking_flag (fd_pipe[1]) == 1); ASSERT (close (fd_pipe[0]) == 0); ASSERT (close (fd_pipe[1]) == 0); #endif /* GNULIB_TEST_PIPE2 */ - /* Test sockets. */ - fd_sock = socket (AF_INET, SOCK_STREAM, 0); - ASSERT (get_nonblocking_flag (fd_sock) == (sock_works ? 0 : -1)); - ASSERT (set_nonblocking_flag (fd_sock, true) == 0); - ASSERT (get_nonblocking_flag (fd_sock) == (sock_works ? 1 : -1)); - ASSERT (set_nonblocking_flag (fd_sock, false) == 0); - ASSERT (get_nonblocking_flag (fd_sock) == (sock_works ? 0 : -1)); - ASSERT (close (fd_sock) == 0); - -#if SOCK_NONBLOCK - fd_sock = socket (AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); - ASSERT (get_nonblocking_flag (fd_sock) == (sock_works ? 1 : -1)); - ASSERT (close (fd_sock) == 0); -#endif /* SOCK_NONBLOCK */ +#if GNULIB_SOCKET + { + /* Test sockets. */ + bool sock_works = true; + int fd_sock; + +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + /* For now, we can't get nonblocking status of windows sockets. */ + sock_works = false; +# endif + + fd_sock = socket (AF_INET, SOCK_STREAM, 0); + ASSERT (get_nonblocking_flag (fd_sock) == (sock_works ? 0 : -1)); + ASSERT (set_nonblocking_flag (fd_sock, true) == 0); + ASSERT (get_nonblocking_flag (fd_sock) == (sock_works ? 1 : -1)); + ASSERT (set_nonblocking_flag (fd_sock, false) == 0); + ASSERT (get_nonblocking_flag (fd_sock) == (sock_works ? 0 : -1)); + ASSERT (close (fd_sock) == 0); + +# if SOCK_NONBLOCK + fd_sock = socket (AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); + ASSERT (get_nonblocking_flag (fd_sock) == (sock_works ? 1 : -1)); + ASSERT (close (fd_sock) == 0); +# endif /* SOCK_NONBLOCK */ + } +#endif /* GNULIB_SOCKET */ /* Test error handling. */ {