aboutsummaryrefslogtreecommitdiff
path: root/src/platform/windows/win_impl.h
blob: 85f73bf7e7bb428603da06a3fba71b8368c2de83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// Copyright 2017 Garrett D'Amore <garrett@damore.org>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt).  A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//

#ifndef PLATFORM_WIN_IMPL_H
#define PLATFORM_WIN_IMPL_H

#ifdef PLATFORM_WINDOWS

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <windows.h>
#include <winsock2.h>
#include <mswsock.h>
#include <process.h>
#include <ws2tcpip.h>


// These types are provided for here, to permit them to be directly inlined
// elsewhere.

typedef struct nni_win_event nni_win_event;

// nni_win_event is used with io completion ports.  This allows us to get
// to a specific completion callback without requiring the poller (in the
// completion port) to know anything about the event itself.  We also use
// this to pass back status and counts to the routine, which may not be
// conveyed in the OVERLAPPED directly.
struct nni_win_event {
	OVERLAPPED	olpd;
	void *		ptr;
	nni_cb		cb;
	int		status;
	int		nbytes;
};

struct nni_plat_ipcsock {
	HANDLE			p;

	char			path[256];
	WSAOVERLAPPED		recv_olpd;
	WSAOVERLAPPED		send_olpd;
	WSAOVERLAPPED		conn_olpd; // Use for both connect and accept
	CRITICAL_SECTION	cs;

	int			server;
};

struct nni_plat_thr {
	void	(*func)(void *);
	void *	arg;
	HANDLE	handle;
};

struct nni_plat_mtx {
	CRITICAL_SECTION	cs;
	DWORD			owner;
	int			init;
};

struct nni_plat_cv {
	CONDITION_VARIABLE	cv;
	CRITICAL_SECTION *	cs;
};

extern int nni_win_error(int);
extern int nni_winsock_error(int);

extern int nni_win_iocp_sysinit(void);
extern void nni_win_iocp_sysfini(void);

extern int nni_win_resolv_sysinit(void);
extern void nni_win_resolv_sysfini(void);

#endif  // PLATFORM_WINDOWS

#endif  // PLATFORM_WIN_IMPL_H