src: add ws.c and ws.h for winsock-related stuff

This commit is contained in:
Bert Belder 2018-03-08 21:20:38 +01:00
parent cb43cb5c06
commit 002c7f0899
No known key found for this signature in database
GPG Key ID: 7A77887B2E2ED461
3 changed files with 25 additions and 14 deletions

View File

@ -1,27 +1,15 @@
#include <stdbool.h>
#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;

14
src/ws.c Normal file
View File

@ -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;
}

8
src/ws.h Normal file
View File

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