1 #include "HsNet.h"
2 #include "HsFFI.h"
3 
4 #if defined(HAVE_WINSOCK2_H)
5 
6 static int winsock_inited = 0;
7 
8 static void
shutdownHandler(void)9 shutdownHandler(void)
10 {
11   WSACleanup();
12 }
13 
14 /* Initialising WinSock... */
15 int
initWinSock()16 initWinSock ()
17 {
18   WORD wVersionRequested;
19   WSADATA wsaData;
20   int err;
21 
22   if (!winsock_inited) {
23     wVersionRequested = MAKEWORD( 2, 2 );
24 
25     err = WSAStartup ( wVersionRequested, &wsaData );
26 
27     if ( err != 0 ) {
28        return err;
29     }
30 
31     if ( LOBYTE( wsaData.wVersion ) != 2 ||
32        HIBYTE( wsaData.wVersion ) != 2 ) {
33       WSACleanup();
34       return (-1);
35     }
36 
37     atexit(shutdownHandler);
38     winsock_inited = 1;
39   }
40   return 0;
41 }
42 
43 #endif
44