diff options
-rw-r--r-- | ghc/lib/misc/cbits/Makefile | 4 | ||||
-rw-r--r-- | ghc/lib/misc/cbits/ghcSockets.h | 13 | ||||
-rw-r--r-- | ghc/lib/misc/cbits/initWinSock.c | 41 | ||||
-rw-r--r-- | ghc/lib/misc/cbits/regex.c | 2 | ||||
-rw-r--r-- | ghc/lib/misc/cbits/socketOpt.c | 12 |
5 files changed, 68 insertions, 4 deletions
diff --git a/ghc/lib/misc/cbits/Makefile b/ghc/lib/misc/cbits/Makefile index 76bf2d64c9..379073f2ed 100644 --- a/ghc/lib/misc/cbits/Makefile +++ b/ghc/lib/misc/cbits/Makefile @@ -21,4 +21,8 @@ LIBRARY=libHSmisc_cbits.a LIBOBJS=$(C_OBJS) INSTALL_LIBS += $(LIBRARY) +DLL_NAME = HSmisc_cbits.dll +SRC_BLD_DLL_OPTS += --export-all --output-def=HSmisc_cbits.def +SRC_BLD_DLL_OPTS += -lwinmm -lwsock32 -lHSrts_imp -lHS_cbits_imp -lgmp -L. -L../../../rts/gmp -L../../../rts -L../../std/cbits + include $(TOP)/mk/target.mk diff --git a/ghc/lib/misc/cbits/ghcSockets.h b/ghc/lib/misc/cbits/ghcSockets.h index 482930fd08..175f8b8868 100644 --- a/ghc/lib/misc/cbits/ghcSockets.h +++ b/ghc/lib/misc/cbits/ghcSockets.h @@ -1,6 +1,10 @@ #ifndef GHC_SOCKETS_H #define GHC_SOCKETS_H +#ifdef HAVE_WINSOCK_H +#include <winsock.h> +#else + #include <ctype.h> #include <netdb.h> #include <netinet/in.h> @@ -39,7 +43,7 @@ #include <sys/uio.h> /* ToDo: featurise this */ -#ifndef cygwin32_TARGET_OS +#if !defined(cygwin32_TARGET_OS) && !defined(mingw32_TARGET_OS) #include <sys/un.h> #endif @@ -47,6 +51,8 @@ # include <unistd.h> #endif +#endif /* !HAVE_WINSOCK_H */ + /* acceptSocket.lc */ StgInt acceptSocket (StgInt, StgAddr, StgAddr); @@ -87,5 +93,10 @@ StgInt setSocketOption__ (StgInt, StgInt, StgInt); /* writeDescriptor.lc */ StgInt writeDescriptor (StgInt, StgAddr, StgInt); +/* initWinSock.c */ +#ifdef _WIN32 +StgInt initWinSock(); +void shutdownWinSock(); +#endif #endif /* !GHC_SOCKETS_H */ diff --git a/ghc/lib/misc/cbits/initWinSock.c b/ghc/lib/misc/cbits/initWinSock.c new file mode 100644 index 0000000000..7ea4de6a9f --- /dev/null +++ b/ghc/lib/misc/cbits/initWinSock.c @@ -0,0 +1,41 @@ + +#define NON_POSIX_SOURCE +#include "Rts.h" +#include "ghcSockets.h" +#include "stgio.h" + + +#ifdef _WIN32 + +/* Initialising WinSock... */ + +StgInt +initWinSock () +{ + WORD wVersionRequested; + WSADATA wsaData; + int err; + + 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); + } + return 0; +} + +void +shutdownWinSock() +{ + WSACleanup(); +} + +#endif diff --git a/ghc/lib/misc/cbits/regex.c b/ghc/lib/misc/cbits/regex.c index 72125642c6..761cb767b0 100644 --- a/ghc/lib/misc/cbits/regex.c +++ b/ghc/lib/misc/cbits/regex.c @@ -94,7 +94,7 @@ char *realloc (); This is used in most programs--a few other programs avoid this by defining INHIBIT_STRING_HEADER. */ #ifndef INHIBIT_STRING_HEADER -#if defined (HAVE_STRING_H) || defined (STDC_HEADERS) || defined (_LIBC) +#if defined (HAVE_STRING_H) || defined (STDC_HEADERS) || defined (_LIBC) || defined(_WIN32) #include <string.h> #ifndef bcmp #define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) diff --git a/ghc/lib/misc/cbits/socketOpt.c b/ghc/lib/misc/cbits/socketOpt.c index ddda6c18b9..69e1fa1214 100644 --- a/ghc/lib/misc/cbits/socketOpt.c +++ b/ghc/lib/misc/cbits/socketOpt.c @@ -19,7 +19,11 @@ StgInt opt; { int level,optval, sz_optval,rc; - if ( opt == TCP_MAXSEG || opt == TCP_NODELAY ) { + if ( +#ifndef _WIN32 + opt == TCP_MAXSEG || +#endif + opt == TCP_NODELAY ) { level = IPPROTO_TCP; } else { level = SOL_SOCKET; @@ -45,7 +49,11 @@ StgInt val; { int level, optval,rc; - if ( opt == TCP_MAXSEG || opt == TCP_NODELAY ) { + if ( +#ifndef _WIN32 + opt == TCP_MAXSEG || +#endif + opt == TCP_NODELAY ) { level = IPPROTO_TCP; } else { level = SOL_SOCKET; |