Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 64 lines (52 sloc) 1.166 kb
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
#include "HsNet.h"
#include "HsFFI.h"

#if defined(HAVE_WINSOCK2_H) && !defined(__CYGWIN__)

static int winsock_inited = 0;
static int winsock_uninited = 0;

/* Initialising WinSock... */
int
initWinSock ()
{
  WORD wVersionRequested;
  WSADATA wsaData;
  int err;
#ifdef __HUGS__
  int optval = SO_SYNCHRONOUS_NONALERT;
#endif

  if (!winsock_inited) {
    wVersionRequested = MAKEWORD( 1, 1 );

    err = WSAStartup ( wVersionRequested, &wsaData );
    
    if ( err != 0 ) {
       return err;
    }

    if ( LOBYTE( wsaData.wVersion ) != 1 ||
       HIBYTE( wsaData.wVersion ) != 1 ) {
      WSACleanup();
      return (-1);
    }
#ifdef __HUGS__
    /* By default, socket() creates sockets in overlapped mode
* (so that async I/O is possible). The CRT can only handle
* non-overlapped sockets, so turn off overlap mode here.
*/
    setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
&optval, sizeof(optval));
#endif

    winsock_inited = 1;
  }
  return 0;
}

static void
shutdownHandler(void)
{
  WSACleanup();
}

void
shutdownWinSock()
{
    if (!winsock_uninited) {
atexit(shutdownHandler);
winsock_uninited = 1;
    }
}

#endif
Something went wrong with that request. Please try again.