os: generic socket layer init function

Reduce the ifdef-zoo a bit by moving win32 specific socket layer init
into a separate function (that's no-op on non-win32).

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-07-30 11:39:38 +02:00 committed by Enrico Weigelt
parent fdf43d4176
commit fe795fa7b8
7 changed files with 40 additions and 27 deletions

View File

@ -46,6 +46,7 @@ from The Open Group.
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <dix-config.h>
#include <ctype.h>
#include <stdlib.h>
@ -54,6 +55,8 @@ from The Open Group.
#include <systemd/sd-daemon.h>
#endif
#include "os/ossock.h"
/*
* The transport table contains a definition for every transport (protocol)
* family. All operations that can be made on the transport go through this
@ -401,13 +404,7 @@ _XSERVTransOpen (int type, const char *address)
prmsg (2,"Open(%d,%s)\n", type, address);
#if defined(WIN32) && defined(TCPCONN)
if (_XSERVTransWSAStartup())
{
prmsg (1,"Open: WSAStartup failed\n");
return NULL;
}
#endif
ossock_init();
/* Parse the Address */

View File

@ -297,8 +297,4 @@ int _XSERVTransGetHostname (
int /* maxlen */
);
#if defined(WIN32) && defined(TCPCONN)
int _XSERVTransWSAStartup(void);
#endif
#endif /* _XTRANS_H_ */

View File

@ -219,19 +219,6 @@ int _XSERVTransConvertAddress(int *familyp, int *addrlenp, Xtransaddr **addrp)
return 0;
}
#if defined(WIN32) && defined(TCPCONN)
int _XSERVTransWSAStartup (void)
{
static WSADATA wsadata;
prmsg (2,"WSAStartup()\n");
if (!wsadata.wVersion && WSAStartup(MAKEWORD(2,2), &wsadata))
return 1;
return 0;
}
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>

View File

@ -13,6 +13,7 @@ srcs_os = [
'mitauth.c',
'osinit.c',
'ospoll.c',
'ossock.c',
'serverlock.c',
'string.c',
'utils.c',

20
os/ossock.c Normal file
View File

@ -0,0 +1,20 @@
/* SPDX-License-Identifier: MIT OR X11
*
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
*/
#include <dix-config.h>
#ifdef WIN32
#include <X11/Xwinsock.h>
#endif
#include "os/ossock.h"
void ossock_init(void)
{
#ifdef WIN32
static WSADATA wsadata;
if (!wsadata.wVersion)
WSAStartup(0x0202, &wsadata);
#endif
}

13
os/ossock.h Normal file
View File

@ -0,0 +1,13 @@
/* SPDX-License-Identifier: MIT OR X11
*
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
*/
#ifndef _XSERVER_OS_OSSOCK_H_
#define _XSERVER_OS_OSSOCK_H_
/*
* os specific initialization of the socket layer
*/
void ossock_init(void);
#endif /* _XSERVER_OS_OSSOCK_H_ */

View File

@ -37,6 +37,7 @@
#include "dix/dix_priv.h"
#include "os/auth.h"
#include "os/ossock.h"
#include "misc.h"
#include "osdep.h"
@ -1412,9 +1413,7 @@ get_addr_by_name(const char *argtype,
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
_Xgethostbynameparams hparams;
#endif
#if defined(WIN32) && defined(TCPCONN)
_XSERVTransWSAStartup();
#endif
ossock_init();
if (!(hep = _XGethostbyname(namestr, hparams))) {
FatalError("Xserver: %s unknown host: %s\n", argtype, namestr);
}