diff options
Diffstat (limited to 'crypto/compat/b_win.c')
-rw-r--r-- | crypto/compat/b_win.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/crypto/compat/b_win.c b/crypto/compat/b_win.c new file mode 100644 index 0000000..b8d01ae --- /dev/null +++ b/crypto/compat/b_win.c | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | * Public domain | ||
3 | * | ||
4 | * Dongsheng Song <dongsheng.song@gmail.com> | ||
5 | * Brent Cook <bcook@openbsd.org> | ||
6 | */ | ||
7 | |||
8 | #include <ws2tcpip.h> | ||
9 | |||
10 | #include <openssl/bio.h> | ||
11 | #include <openssl/err.h> | ||
12 | |||
13 | int | ||
14 | BIO_sock_init(void) | ||
15 | { | ||
16 | /* | ||
17 | * WSAStartup loads the winsock .dll and initializes the networking | ||
18 | * stack on Windows, or simply increases the reference count. | ||
19 | */ | ||
20 | static struct WSAData wsa_state = {0}; | ||
21 | WORD version_requested = MAKEWORD(2, 2); | ||
22 | static int wsa_init_done = 0; | ||
23 | if (!wsa_init_done) { | ||
24 | if (WSAStartup(version_requested, &wsa_state) != 0) { | ||
25 | int err = WSAGetLastError(); | ||
26 | SYSerr(SYS_F_WSASTARTUP, err); | ||
27 | BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP); | ||
28 | return (-1); | ||
29 | } | ||
30 | wsa_init_done = 1; | ||
31 | } | ||
32 | return (1); | ||
33 | } | ||
34 | |||
35 | void | ||
36 | BIO_sock_cleanup(void) | ||
37 | { | ||
38 | /* | ||
39 | * We could call WSACleanup here, but it is easy to get it wrong. Since | ||
40 | * this API provides no way to even tell if it failed, there is no safe | ||
41 | * way to expose that functionality here. | ||
42 | * | ||
43 | * The cost of leaving the networking DLLs loaded may have been large | ||
44 | * during the Windows 3.1/win32s era, but it is small in modern | ||
45 | * contexts, so don't bother. | ||
46 | */ | ||
47 | } | ||
48 | |||
49 | int | ||
50 | BIO_socket_nbio(int s, int mode) | ||
51 | { | ||
52 | u_long value = mode; | ||
53 | return ioctlsocket(s, FIONBIO, &value) != SOCKET_ERROR; | ||
54 | } | ||