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_ */