[project @ 1999-05-05 10:34:53 by sof]
authorsof <unknown>
Wed, 5 May 1999 10:34:55 +0000 (10:34 +0000)
committersof <unknown>
Wed, 5 May 1999 10:34:55 +0000 (10:34 +0000)
stubs for starting & stopping Winsock

ghc/lib/misc/cbits/Makefile
ghc/lib/misc/cbits/ghcSockets.h
ghc/lib/misc/cbits/initWinSock.c [new file with mode: 0644]
ghc/lib/misc/cbits/regex.c
ghc/lib/misc/cbits/socketOpt.c

index 76bf2d6..379073f 100644 (file)
@@ -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
index 482930f..175f8b8 100644 (file)
@@ -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 (file)
index 0000000..7ea4de6
--- /dev/null
@@ -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
index 7212564..761cb76 100644 (file)
@@ -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))
index ddda6c1..69e1fa1 100644 (file)
@@ -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;