summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--lib/gethostname.c3
-rw-r--r--lib/socket.c10
-rw-r--r--modules/gethostname1
-rw-r--r--modules/socket1
-rw-r--r--tests/test-poll.c5
-rw-r--r--tests/test-select.c5
7 files changed, 29 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 3309b7b672..7c3387eb8a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
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.
* lib/sockets.c (initialized_sockets_version): New variable.
(gl_sockets_startup): Do nothing if already called for this or a higher
diff --git a/lib/gethostname.c b/lib/gethostname.c
index df0bd16e80..35d8206858 100644
--- a/lib/gethostname.c
+++ b/lib/gethostname.c
@@ -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 ();
diff --git a/lib/socket.c b/lib/socket.c
index 1fa6928747..8ce4bae8db 100644
--- a/lib/socket.c
+++ b/lib/socket.c
@@ -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
@@ -26,12 +26,18 @@
/* 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)
{
diff --git a/modules/gethostname b/modules/gethostname
index e21afe6a9c..8c24571276 100644
--- a/modules/gethostname
+++ b/modules/gethostname
@@ -10,6 +10,7 @@ Depends-on:
unistd
sys_socket
errno
+sockets
configure.ac:
gl_FUNC_GETHOSTNAME
diff --git a/modules/socket b/modules/socket
index 070ba3f2f0..b736fd1d33 100644
--- a/modules/socket
+++ b/modules/socket
@@ -8,6 +8,7 @@ lib/w32sock.h
Depends-on:
sys_socket
errno
+sockets
configure.ac:
AC_REQUIRE([gl_HEADER_SYS_SOCKET])
diff --git a/tests/test-poll.c b/tests/test-poll.c
index 77b06d9928..d78698e4a5 100644
--- a/tests/test-poll.c
+++ b/tests/test-poll.c
@@ -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");
diff --git a/tests/test-select.c b/tests/test-select.c
index 4c9cdc02dc..ec82250149 100644
--- a/tests/test-select.c
+++ b/tests/test-select.c
@@ -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");