Mercurial > hg > octave-nkf > gnulib-hg
changeset 14536:388a32f36b2c
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 <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Fri, 08 Apr 2011 11:51:45 -0600 |
parents | 7ba508565384 |
children | 10946c7debf8 |
files | ChangeLog lib/ioctl.c modules/nonblocking-tests modules/pipe2-tests tests/test-nonblocking.c |
diffstat | 5 files changed, 42 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2011-04-08 Eric Blake <eblake@redhat.com> + 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.
--- a/lib/ioctl.c +++ b/lib/ioctl.c @@ -54,6 +54,7 @@ int ioctl (int fd, int req, ...) { +# if GNULIB_SOCKET void *buf; va_list args; SOCKET sock; @@ -73,6 +74,11 @@ set_winsock_errno (); return r; + +# else + errno = ENOSYS; + return -1; +# endif } #endif
--- a/modules/nonblocking-tests +++ b/modules/nonblocking-tests @@ -5,11 +5,10 @@ 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)
--- a/modules/pipe2-tests +++ b/modules/pipe2-tests @@ -11,4 +11,4 @@ Makefile.am: TESTS += test-pipe2 check_PROGRAMS += test-pipe2 -test_pipe2_LDADD = $(LDADD) @LIBSOCKET@ +test_pipe2_LDADD = $(LDADD) $(LIBSOCKET)
--- a/tests/test-nonblocking.c +++ b/tests/test-nonblocking.c @@ -33,13 +33,6 @@ 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 @@ 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 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 -#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 */ + 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. */ {