From 002c7f089969e3cf9c7716f25825e7669eaf0a6e Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 8 Mar 2018 21:20:38 +0100 Subject: [PATCH] src: add ws.c and ws.h for winsock-related stuff --- src/init.c | 17 +++-------------- src/ws.c | 14 ++++++++++++++ src/ws.h | 8 ++++++++ 3 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 src/ws.c create mode 100644 src/ws.h diff --git a/src/init.c b/src/init.c index 5f75421..3e03af6 100644 --- a/src/init.c +++ b/src/init.c @@ -1,27 +1,15 @@ #include #include "api.h" -#include "error.h" #include "init.h" #include "nt.h" #include "reflock.h" #include "util.h" -#include "win.h" +#include "ws.h" static bool _initialized = false; static INIT_ONCE _once = INIT_ONCE_STATIC_INIT; -static int _winsock_global_init(void) { - int r; - WSADATA wsa_data; - - r = WSAStartup(MAKEWORD(2, 2), &wsa_data); - if (r != 0) - return_error(-1); - - return 0; -} - static BOOL CALLBACK _init_once_callback(INIT_ONCE* once, void* parameter, void** context) { @@ -29,7 +17,8 @@ static BOOL CALLBACK _init_once_callback(INIT_ONCE* once, unused_var(parameter); unused_var(context); - if (_winsock_global_init() < 0 || nt_global_init() < 0 || + /* N.b. that initialization order matters here. */ + if (ws_global_init() < 0 || nt_global_init() < 0 || reflock_global_init() < 0 || api_global_init() < 0) return FALSE; diff --git a/src/ws.c b/src/ws.c new file mode 100644 index 0000000..4260b28 --- /dev/null +++ b/src/ws.c @@ -0,0 +1,14 @@ +#include "ws.h" +#include "error.h" +#include "win.h" + +int ws_global_init(void) { + int r; + WSADATA wsa_data; + + r = WSAStartup(MAKEWORD(2, 2), &wsa_data); + if (r != 0) + return_error(-1); + + return 0; +} diff --git a/src/ws.h b/src/ws.h new file mode 100644 index 0000000..6be473c --- /dev/null +++ b/src/ws.h @@ -0,0 +1,8 @@ +#ifndef WEPOLL_WS_H_ +#define WEPOLL_WS_H_ + +#include "internal.h" + +WEPOLL_INTERNAL int ws_global_init(void); + +#endif /* WEPOLL_WS_H_ */