summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2011-04-08 11:51:45 -0600
committerEric Blake <eblake@redhat.com>2011-04-08 12:52:29 -0600
commit4a1579d7560659ef5723325726eda14490a967f6 (patch)
tree2c79b62e7dc80fac7cd39e68663a8cf32b297d78
parent0568a6e8985cc2ae9c57cb03fc81f5305458b7d2 (diff)
downloadgnulib-4a1579d7560659ef5723325726eda14490a967f6.tar.gz
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>
-rw-r--r--ChangeLog7
-rw-r--r--lib/ioctl.c6
-rw-r--r--modules/nonblocking-tests3
-rw-r--r--modules/pipe2-tests2
-rw-r--r--tests/test-nonblocking.c52
5 files changed, 43 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index a8d45212ff..099dbd7abf 100644
--- 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.
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. */
{