Implicitly initialize the sockets library.
authorBruno Haible <bruno@clisp.org>
Sun, 2 Aug 2009 14:43:55 +0000 (16:43 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 3 Aug 2009 20:01:26 +0000 (22:01 +0200)
ChangeLog
lib/gethostname.c
lib/socket.c
modules/gethostname
modules/socket
tests/test-poll.c
tests/test-select.c

index 3309b7b672ec2fb0de3db943b9a7fb72136adf0a..7c3387eb8a316288b33429651865debe395d3674 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-08-02  Bruno Haible  <bruno@clisp.org>
+
+       Implicitly initialize the sockets library.
+       * lib/gethostname.c: Include sockets.h.
+       (rpl_gethostname): Invoke gl_sockets_startup.
+       * lib/socket.c: Include sockets.h.
+       (rpl_socket): Invoke gl_sockets_startup.
+       * modules/gethostname (Depends-on): Add sockets.
+       * modules/socket (Depends-on): Likewise.
+       * tests/test-poll.c: Don't include sockets.h.
+       (main): Don't invoke gl_sockets_startup.
+       * tests/test-select.c: Don't include sockets.h.
+       (main): Don't invoke gl_sockets_startup.
+
 2009-08-02  Bruno Haible  <bruno@clisp.org>
 
        Allow multiple calls to gl_sockets_startup.
index df0bd16e80fc6adc8728b4a98bf14e2207bdd545..35d82068583cb8cb4b096e123477d5d19b265d3c 100644 (file)
@@ -82,6 +82,8 @@ gethostname (char *name, size_t len)
 /* Get set_winsock_errno. */
 #include "w32sock.h"
 
+#include "sockets.h"
+
 #undef gethostname
 
 int
@@ -91,6 +93,7 @@ rpl_gethostname (char *name, size_t len)
 
   if (len > INT_MAX)
     len = INT_MAX;
+  gl_sockets_startup (SOCKETS_1_1);
   r = gethostname (name, (int) len);
   if (r < 0)
     set_winsock_errno ();
index 1fa6928747c2e71eb074bca14fc207e46805ec2a..8ce4bae8db6a5aee728b1689b29ebe032e7d2669 100644 (file)
@@ -1,6 +1,6 @@
 /* socket.c --- wrappers for Windows socket function
 
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 /* Get set_winsock_errno, FD_TO_SOCKET etc. */
 #include "w32sock.h"
 
+#include "sockets.h"
+
 int
 rpl_socket (int domain, int type, int protocol)
 {
+  SOCKET fh;
+
+  gl_sockets_startup (SOCKETS_1_1);
+
   /* We have to use WSASocket() to create non-overlapped IO sockets.
      Overlapped IO sockets cannot be used with read/write.  */
-  SOCKET fh = WSASocket (domain, type, protocol, NULL, 0, 0);
+  fh = WSASocket (domain, type, protocol, NULL, 0, 0);
 
   if (fh == INVALID_SOCKET)
     {
index e21afe6a9c0bec5cbe5651a6e5f1beb185ebe7b7..8c2457127673cd286be007dc63c88b0194f1a13f 100644 (file)
@@ -10,6 +10,7 @@ Depends-on:
 unistd
 sys_socket
 errno
+sockets
 
 configure.ac:
 gl_FUNC_GETHOSTNAME
index 070ba3f2f03b7226645b505369322ea4b94fea72..b736fd1d335d98bedcb89b53fd0b3c7f494b654c 100644 (file)
@@ -8,6 +8,7 @@ lib/w32sock.h
 Depends-on:
 sys_socket
 errno
+sockets
 
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
index 77b06d9928cc57f36db75af51dcc9aa2f859e19e..d78698e4a585bcd4a0c3bd132d1f1043a2c5d572 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of poll() function.
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2009 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -30,7 +30,6 @@
 #include <stdbool.h>
 #include <sys/ioctl.h>
 #include <errno.h>
-#include "sockets.h"
 
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 # define WIN32_NATIVE
@@ -360,8 +359,6 @@ main ()
 {
   int result;
 
-  gl_sockets_startup (SOCKETS_1_1);
-
 #ifdef INTERACTIVE
   printf ("Please press Enter\n");
   test (test_tty, "TTY");
index 4c9cdc02dc1af7435babcd49a8f55a9f24c92644..ec822501494036cbb4aa8712b81b3a7c6c8131f7 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of select() substitute.
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -29,7 +29,6 @@
 #include <stdbool.h>
 #include <sys/ioctl.h>
 #include <errno.h>
-#include "sockets.h"
 
 enum { SEL_IN = 1, SEL_OUT = 2, SEL_EXC = 4 };
 
@@ -360,8 +359,6 @@ main ()
 {
   int result;
 
-  gl_sockets_startup (SOCKETS_1_1);
-
 #ifdef INTERACTIVE
   printf ("Please press Enter\n");
   test (test_tty, "TTY");