Move Windows socket stuff out off posixio.c into w32sockets.c

This is so we can avoid linking utilities with socket libraries (see
commit 8b778634).

When using sockets, we need to replace close(), because Windows'
close() can't cope with socket file descriptors.  But replacing it
always would pull in the socket stuff again.  Define close() to call
function pointer w32_close_function, which is initially _close.
Rename posix_close() to w32_close_maybe_socket().  Make new
w32_socket_init() put it in w32_close_function.

Same for read() and write(): define read(), write() to call function
pointers w32_read_function, w32_write_function, initially _read(),
_write(); rename posix_read(), posix_write() to
w32_read_maybe_socket(), w32_write_maybe_socket(), and put them into
w32_read_function, w32_write_function in w32_socket_init().

Also call WSAStartup() there, and use that from loc_NTInit().
WSACleanup() now belongs next to w32_socket_init().  Don't bother,
just drop it, along with loc_NTTerm().
This commit is contained in:
Markus Armbruster 2009-04-13 19:25:25 +02:00
parent 39398997fe
commit 4c6deb1f98
6 changed files with 380 additions and 330 deletions

View file

@ -32,7 +32,7 @@
* Steve McClure, 1996, 1998
* Doug Hay, 1998
* Ron Koenderink, 2004-2009
* Markus Armbruster, 2005-2008
* Markus Armbruster, 2005-2009
*/
#include <config.h>
@ -48,6 +48,7 @@
#if defined(_WIN32)
#include <process.h>
#include "service.h"
#include "sys/socket.h"
#endif
#include "empio.h"
@ -75,7 +76,6 @@ static void create_pidfile(char *, pid_t);
#if defined(_WIN32)
static void loc_NTInit(void);
static void loc_NTTerm(void);
#endif
/*
@ -385,9 +385,6 @@ void
finish_server(void)
{
ef_fin_srv();
#if defined(_WIN32)
loc_NTTerm();
#endif
journal_shutdown();
remove(pidfname);
}
@ -464,20 +461,11 @@ static void
loc_NTInit(void)
{
int rc;
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(2, 0);
rc = WSAStartup(wVersionRequested, &wsaData);
rc = w32_socket_init();
if (rc != 0) {
logerror("WSAStartup failed. %d", rc);
logerror("WSAStartup Failed, error code %d\n", rc);
exit(1);
}
}
static void
loc_NTTerm(void)
{
WSACleanup();
}
#endif