network 2.1.0.0 → 2.2.0.0
raw patch · 8 files changed
+217/−145 lines, 8 filesnew-uploader
Files
- Network.hs +2/−1
- Network/Socket.hsc +52/−15
- configure +122/−2
- configure.ac +35/−1
- include/HsNetworkConfig.h +0/−123
- include/HsNetworkConfig.h.in +3/−0
- network.buildinfo.in +2/−2
- network.cabal +1/−1
Network.hs view
@@ -222,6 +222,7 @@ listen' serv = do proto <- getProtocolNumber "tcp" let hints = defaultHints { addrFlags = [AI_ADDRCONFIG, AI_PASSIVE]+ , addrSocketType = Stream , addrProtocol = proto } addrs <- getAddrInfo (Just hints) Nothing (Just serv) let addr = head addrs@@ -240,7 +241,7 @@ -- accept -- | Accept a connection on a socket created by 'listenOn'. Normal--- I\/O opertaions (see "System.IO") can be used on the 'Handle'+-- I\/O operations (see "System.IO") can be used on the 'Handle' -- returned to communicate with the client. -- Notice that although you can pass any Socket to Network.accept, -- only sockets of either AF_UNIX, AF_INET, or AF_INET6 will work
Network/Socket.hsc view
@@ -95,7 +95,7 @@ getPeerName, -- :: Socket -> IO SockAddr getSocketName, -- :: Socket -> IO SockAddr -#ifdef SO_PEERCRED+#ifdef HAVE_STRUCT_UCRED -- get the credentials of our domain socket peer. getPeerCred, -- :: Socket -> IO (CUInt{-pid-}, CUInt{-uid-}, CUInt{-gid-}) #endif@@ -201,7 +201,7 @@ import Foreign.C.String ( CString, withCString, peekCString, peekCStringLen, castCharToCChar ) import Foreign.C.Types ( CInt, CUInt, CChar, CSize ) import Foreign.Marshal.Alloc ( alloca, allocaBytes )-import Foreign.Marshal.Array ( peekArray, pokeArray0 )+import Foreign.Marshal.Array ( peekArray, pokeArray, pokeArray0 ) import Foreign.Marshal.Utils ( maybeWith, with ) import System.IO@@ -228,6 +228,26 @@ type HostName = String type ServiceName = String +-- ----------------------------------------------------------------------------+-- On Windows, our sockets are not put in non-blocking mode (non-blocking+-- is not supported for regular file descriptors on Windows, and it would+-- be a pain to support it only for sockets). So there are two cases:+--+-- - the threaded RTS uses safe calls for socket operations to get+-- non-blocking I/O, just like the rest of the I/O library+--+-- - with the non-threaded RTS, only some operations on sockets will be+-- non-blocking. Reads and writes go through the normal async I/O+-- system. accept() uses asyncDoProc so is non-blocking. A handful+-- of others (recvFrom, sendFd, recvFd) will block all threads - if this+-- is a problem, -threaded is the workaround.+--+##if defined(mingw32_HOST_OS)+##define SAFE_ON_WIN safe+##else+##define SAFE_ON_WIN unsafe+##endif+ ----------------------------------------------------------------------------- -- Socket types @@ -428,6 +448,7 @@ -- don't require 32-bit-wide address fields to be present. We can -- only portably rely on an 8-bit field, s6_addr. +s6_addr_offset :: Int s6_addr_offset = (#offset struct in6_addr, s6_addr) peek32 :: Ptr a -> Int -> IO Word32@@ -480,14 +501,21 @@ #if defined(darwin_TARGET_OS) zeroMemory p (#const sizeof(struct sockaddr_un)) #endif+#if defined(netbsd_TARGET_OS)+ (#poke struct sockaddr_un, sun_len) p ((#const sizeof(struct sockaddr_un)) :: Word8)+#endif (#poke struct sockaddr_un, sun_family) p ((#const AF_UNIX) :: CSaFamily) let pathC = map castCharToCChar path- pokeArray0 0 ((#ptr struct sockaddr_un, sun_path) p) pathC+ poker = case path of ('\0':_) -> pokeArray; _ -> pokeArray0 0+ poker ((#ptr struct sockaddr_un, sun_path) p) pathC #endif pokeSockAddr p (SockAddrInet (PortNum port) addr) = do #if defined(darwin_TARGET_OS) zeroMemory p (#const sizeof(struct sockaddr_in)) #endif+#if defined(netbsd_TARGET_OS)+ (#poke struct sockaddr_in, sin_len) p ((#const sizeof(struct sockaddr_in)) :: Word8)+#endif (#poke struct sockaddr_in, sin_family) p ((#const AF_INET) :: CSaFamily) (#poke struct sockaddr_in, sin_port) p port (#poke struct sockaddr_in, sin_addr) p addr @@ -496,6 +524,9 @@ #if defined(darwin_TARGET_OS) zeroMemory p (#const sizeof(struct sockaddr_in6)) #endif+#if defined(netbsd_TARGET_OS)+ (#poke struct sockaddr_in6, sin6_len) p ((#const sizeof(struct sockaddr_in6)) :: Word8)+#endif (#poke struct sockaddr_in6, sin6_family) p ((#const AF_INET6) :: CSaFamily) (#poke struct sockaddr_in6, sin6_port) p port (#poke struct sockaddr_in6, sin6_flowinfo) p flow@@ -542,7 +573,10 @@ -- size of struct sockaddr by SockAddr #if defined(DOMAIN_SOCKET_SUPPORT)-sizeOfSockAddr (SockAddrUnix _) = #const sizeof(struct sockaddr_un)+sizeOfSockAddr (SockAddrUnix path) =+ case path of+ '\0':_ -> (#const sizeof(sa_family_t)) + length path+ _ -> #const sizeof(struct sockaddr_un) #endif sizeOfSockAddr (SockAddrInet _ _) = #const sizeof(struct sockaddr_in) #if defined(IPV6_SOCKET_SUPPORT)@@ -812,6 +846,8 @@ ----------------------------------------------------------------------------- -- sendTo & recvFrom +-- | NOTE: blocking on Windows unless you compile with -threaded (see+-- GHC ticket #1129) sendTo :: Socket -- (possibly) bound/connected Socket -> String -- Data to send -> SockAddr@@ -836,6 +872,8 @@ c_sendto s ptr (fromIntegral $ nbytes) 0{-flags-} p_addr (fromIntegral sz) +-- | NOTE: blocking on Windows unless you compile with -threaded (see+-- GHC ticket #1129) recvFrom :: Socket -> Int -> IO (String, Int, SockAddr) recvFrom sock nbytes = allocaBytes nbytes $ \ptr -> do@@ -1133,7 +1171,7 @@ fromIntegral `liftM` peek ptr_v -#ifdef SO_PEERCRED+#ifdef HAVE_STRUCT_UCRED -- | Returns the processID, userID and groupID of the socket's peer. -- -- Only available on platforms that support SO_PEERCRED on domain sockets.@@ -1222,14 +1260,14 @@ ty <- fromIntegral `liftM` peek ptr_ty pD <- peek ptr_pData return (lev,ty,pD, len)-foreign import ccall unsafe "sendAncillary"+foreign import ccall SAFE_ON_WIN "sendAncillary" c_sendAncillary :: CInt -> CInt -> CInt -> CInt -> Ptr a -> CInt -> IO CInt -foreign import ccall unsafe "recvAncillary"+foreign import ccall SAFE_ON_WIN "recvAncillary" c_recvAncillary :: CInt -> Ptr CInt -> Ptr CInt -> CInt -> Ptr (Ptr a) -> Ptr CInt -> IO CInt -foreign import ccall unsafe "sendFd" c_sendFd :: CInt -> CInt -> IO CInt-foreign import ccall unsafe "recvFd" c_recvFd :: CInt -> IO CInt+foreign import ccall SAFE_ON_WIN "sendFd" c_sendFd :: CInt -> CInt -> IO CInt+foreign import ccall SAFE_ON_WIN "recvFd" c_recvFd :: CInt -> IO CInt #endif @@ -1762,7 +1800,7 @@ #ifdef AF_GOSSIP (#const AF_GOSSIP) -> AF_GOSSIP #endif-#ifdef AF_IPX+#if defined(AF_IPX) && (!defined(AF_NS) || AF_NS != AF_IPX) (#const AF_IPX) -> AF_IPX #endif #ifdef Pseudo_AF_XTP@@ -2068,10 +2106,9 @@ else do # if __GLASGOW_HASKELL__ >= 608 h <- fdToHandle' (fromIntegral fd) (Just System.Posix.Internals.Stream) True (show s) mode True{-bin-}-# elif __GLASGOW_HASKELL__ < 608+# elif __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ < 608 h <- openFd (fromIntegral fd) (Just System.Posix.Internals.Stream) True (show s) mode True{-bin-}-# endif-# ifdef __HUGS__+# elif defined(__HUGS__) h <- openFd (fromIntegral fd) True{-is a socket-} mode True{-bin-} # endif return (ConvertedToHandle, h)@@ -2518,11 +2555,11 @@ foreign import CALLCONV unsafe "send" c_send :: CInt -> Ptr a -> CSize -> CInt -> IO CInt-foreign import CALLCONV unsafe "sendto"+foreign import CALLCONV SAFE_ON_WIN "sendto" c_sendto :: CInt -> Ptr a -> CSize -> CInt -> Ptr SockAddr -> CInt -> IO CInt foreign import CALLCONV unsafe "recv" c_recv :: CInt -> Ptr CChar -> CSize -> CInt -> IO CInt-foreign import CALLCONV unsafe "recvfrom"+foreign import CALLCONV SAFE_ON_WIN "recvfrom" c_recvfrom :: CInt -> Ptr a -> CSize -> CInt -> Ptr SockAddr -> Ptr CInt -> IO CInt foreign import CALLCONV unsafe "getpeername" c_getpeername :: CInt -> Ptr SockAddr -> Ptr CInt -> IO CInt
configure view
@@ -671,6 +671,7 @@ GREP EGREP CALLCONV+EXTRA_CPPFLAGS EXTRA_LIBS EXTRA_SRCS LIBOBJS@@ -4158,7 +4159,124 @@ rm -f conftest* +{ echo "$as_me:$LINENO: checking for SO_PEERCRED and struct ucred in sys/socket.h" >&5+echo $ECHO_N "checking for SO_PEERCRED and struct ucred in sys/socket.h... $ECHO_C" >&6; }+cat >conftest.$ac_ext <<_ACEOF+/* confdefs.h. */+_ACEOF+cat confdefs.h >>conftest.$ac_ext+cat >>conftest.$ac_ext <<_ACEOF+/* end confdefs.h. */+#include <sys/types.h>+#include <sys/socket.h>+#ifndef SO_PEERCRED+# error no SO_PEERCRED+#endif+struct ucred u;+int+main ()+{ + ;+ return 0;+}+_ACEOF+rm -f conftest.$ac_objext+if { (ac_try="$ac_compile"+case "(($ac_try" in+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;+ *) ac_try_echo=$ac_try;;+esac+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5+ (eval "$ac_compile") 2>conftest.er1+ ac_status=$?+ grep -v '^ *+' conftest.er1 >conftest.err+ rm -f conftest.er1+ cat conftest.err >&5+ echo "$as_me:$LINENO: \$? = $ac_status" >&5+ (exit $ac_status); } && {+ test -z "$ac_c_werror_flag" ||+ test ! -s conftest.err+ } && test -s conftest.$ac_objext; then+ ac_cv_ucred=yes+else+ echo "$as_me: failed program was:" >&5+sed 's/^/| /' conftest.$ac_ext >&5++ ac_cv_ucred=no+fi++rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext+if test "x$ac_cv_ucred" = xno; then+ old_CFLAGS="$CFLAGS"+ CFLAGS="-D_GNU_SOURCE $CFLAGS"+ cat >conftest.$ac_ext <<_ACEOF+/* confdefs.h. */+_ACEOF+cat confdefs.h >>conftest.$ac_ext+cat >>conftest.$ac_ext <<_ACEOF+/* end confdefs.h. */+#include <sys/types.h>+#include <sys/socket.h>+#ifndef SO_PEERCRED+# error no SO_PEERCRED+#endif+struct ucred u;+int+main ()+{++ ;+ return 0;+}+_ACEOF+rm -f conftest.$ac_objext+if { (ac_try="$ac_compile"+case "(($ac_try" in+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;+ *) ac_try_echo=$ac_try;;+esac+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5+ (eval "$ac_compile") 2>conftest.er1+ ac_status=$?+ grep -v '^ *+' conftest.er1 >conftest.err+ rm -f conftest.er1+ cat conftest.err >&5+ echo "$as_me:$LINENO: \$? = $ac_status" >&5+ (exit $ac_status); } && {+ test -z "$ac_c_werror_flag" ||+ test ! -s conftest.err+ } && test -s conftest.$ac_objext; then+ ac_cv_ucred=yes+else+ echo "$as_me: failed program was:" >&5+sed 's/^/| /' conftest.$ac_ext >&5++ ac_cv_ucred=no+fi++rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext+ if test "x$ac_cv_ucred" = xyes; then+ EXTRA_CPPFLAGS=-D_GNU_SOURCE+ fi+else+ old_CFLAGS="$CFLAGS"+fi+if test "x$ac_cv_ucred" = xno; then+ CFLAGS="$old_CFLAGS"+ { echo "$as_me:$LINENO: result: no" >&5+echo "${ECHO_T}no" >&6; }+else++cat >>confdefs.h <<\_ACEOF+#define HAVE_STRUCT_UCRED 1+_ACEOF++ { echo "$as_me:$LINENO: result: yes" >&5+echo "${ECHO_T}yes" >&6; }+fi++ for ac_func in getaddrinfo do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`@@ -4676,7 +4794,7 @@ EXTRA_SRCS="cbits/initWinSock.c, cbits/winSockErr.c, cbits/asyncAccept.c" EXTRA_LIBS=wsock32 CALLCONV=stdcall ;;-*-solaris2)+*-solaris2*) EXTRA_SRCS="cbits/ancilData.c" EXTRA_LIBS="nsl, socket" CALLCONV=ccall ;;@@ -4689,6 +4807,7 @@ + ac_config_files="$ac_config_files network.buildinfo" @@ -5363,13 +5482,14 @@ GREP!$GREP$ac_delim EGREP!$EGREP$ac_delim CALLCONV!$CALLCONV$ac_delim+EXTRA_CPPFLAGS!$EXTRA_CPPFLAGS$ac_delim EXTRA_LIBS!$EXTRA_LIBS$ac_delim EXTRA_SRCS!$EXTRA_SRCS$ac_delim LIBOBJS!$LIBOBJS$ac_delim LTLIBOBJS!$LTLIBOBJS$ac_delim _ACEOF - if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 60; then+ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 61; then break elif $ac_last_try; then { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
configure.ac view
@@ -40,6 +40,39 @@ AC_MSG_RESULT(no)) dnl --------------------------------------------------+dnl * test for SO_PEERCRED and struct ucred+dnl --------------------------------------------------+AC_MSG_CHECKING(for SO_PEERCRED and struct ucred in sys/socket.h)+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>+#include <sys/socket.h>+#ifndef SO_PEERCRED+# error no SO_PEERCRED+#endif+struct ucred u;]])],ac_cv_ucred=yes,ac_cv_ucred=no)+if test "x$ac_cv_ucred" = xno; then+ old_CFLAGS="$CFLAGS"+ CFLAGS="-D_GNU_SOURCE $CFLAGS"+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>+#include <sys/socket.h>+#ifndef SO_PEERCRED+# error no SO_PEERCRED+#endif+struct ucred u;]])],ac_cv_ucred=yes,ac_cv_ucred=no)+ if test "x$ac_cv_ucred" = xyes; then+ EXTRA_CPPFLAGS=-D_GNU_SOURCE+ fi+else+ old_CFLAGS="$CFLAGS"+fi+if test "x$ac_cv_ucred" = xno; then+ CFLAGS="$old_CFLAGS"+ AC_MSG_RESULT(no)+else+ AC_DEFINE([HAVE_STRUCT_UCRED], [1], [Define to 1 if you have both SO_PEERCRED and struct ucred.])+ AC_MSG_RESULT(yes)+fi++dnl -------------------------------------------------- dnl * test for getaddrinfo as proxy for IPv6 support dnl -------------------------------------------------- AC_CHECK_FUNCS(getaddrinfo)@@ -73,7 +106,7 @@ EXTRA_SRCS="cbits/initWinSock.c, cbits/winSockErr.c, cbits/asyncAccept.c" EXTRA_LIBS=wsock32 CALLCONV=stdcall ;;-*-solaris2)+*-solaris2*) EXTRA_SRCS="cbits/ancilData.c" EXTRA_LIBS="nsl, socket" CALLCONV=ccall ;;@@ -83,6 +116,7 @@ CALLCONV=ccall ;; esac AC_SUBST([CALLCONV])+AC_SUBST([EXTRA_CPPFLAGS]) AC_SUBST([EXTRA_LIBS]) AC_SUBST([EXTRA_SRCS])
include/HsNetworkConfig.h view
@@ -1,123 +0,0 @@-/* include/HsNetworkConfig.h. Generated from HsNetworkConfig.h.in by configure. */-/* include/HsNetworkConfig.h.in. Generated from configure.ac by autoheader. */--/* Define to 1 if you have the <arpa/inet.h> header file. */-#define HAVE_ARPA_INET_H 1--/* Define to 1 if you have a BSDish sendfile(2) implementation. */-/* #undef HAVE_BSD_SENDFILE */--/* Define to 1 if you have the declaration of `AI_ADDRCONFIG', and to 0 if you- don't. */-#define HAVE_DECL_AI_ADDRCONFIG 1--/* Define to 1 if you have the declaration of `AI_ALL', and to 0 if you don't.- */-#define HAVE_DECL_AI_ALL 1--/* Define to 1 if you have the declaration of `AI_NUMERICSERV', and to 0 if- you don't. */-#define HAVE_DECL_AI_NUMERICSERV 1--/* Define to 1 if you have the declaration of `AI_V4MAPPED', and to 0 if you- don't. */-#define HAVE_DECL_AI_V4MAPPED 1--/* Define to 1 if you have the <fcntl.h> header file. */-#define HAVE_FCNTL_H 1--/* Define to 1 if you have the `getaddrinfo' function. */-#define HAVE_GETADDRINFO 1--/* Define to 1 if you have the `gethostent' function. */-#define HAVE_GETHOSTENT 1--/* Define to 1 if you have the <inttypes.h> header file. */-#define HAVE_INTTYPES_H 1--/* Define to 1 if in_addr_t is available. */-#define HAVE_IN_ADDR_T 1--/* Define to 1 if you have the <limits.h> header file. */-#define HAVE_LIMITS_H 1--/* Define to 1 if you have a Linux sendfile(2) implementation. */-#define HAVE_LINUX_SENDFILE 1--/* Define to 1 if you have the <memory.h> header file. */-#define HAVE_MEMORY_H 1--/* Define to 1 if you have the <netdb.h> header file. */-#define HAVE_NETDB_H 1--/* Define to 1 if you have the <netinet/in.h> header file. */-#define HAVE_NETINET_IN_H 1--/* Define to 1 if you have the <netinet/tcp.h> header file. */-#define HAVE_NETINET_TCP_H 1--/* Define to 1 if you have the `readlink' function. */-#define HAVE_READLINK 1--/* Define to 1 if you have the <stdint.h> header file. */-#define HAVE_STDINT_H 1--/* Define to 1 if you have the <stdlib.h> header file. */-#define HAVE_STDLIB_H 1--/* Define to 1 if you have the <strings.h> header file. */-#define HAVE_STRINGS_H 1--/* Define to 1 if you have the <string.h> header file. */-#define HAVE_STRING_H 1--/* Define to 1 if `msg_accrights' is member of `struct msghdr'. */-/* #undef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */--/* Define to 1 if `msg_control' is member of `struct msghdr'. */-#define HAVE_STRUCT_MSGHDR_MSG_CONTROL 1--/* Define to 1 if you have the `symlink' function. */-#define HAVE_SYMLINK 1--/* Define to 1 if you have the <sys/socket.h> header file. */-#define HAVE_SYS_SOCKET_H 1--/* Define to 1 if you have the <sys/stat.h> header file. */-#define HAVE_SYS_STAT_H 1--/* Define to 1 if you have the <sys/types.h> header file. */-#define HAVE_SYS_TYPES_H 1--/* Define to 1 if you have the <sys/uio.h> header file. */-#define HAVE_SYS_UIO_H 1--/* Define to 1 if you have the <sys/un.h> header file. */-#define HAVE_SYS_UN_H 1--/* Define to 1 if you have the <unistd.h> header file. */-#define HAVE_UNISTD_H 1--/* Define to 1 if you have the <winsock.h> header file. */-/* #undef HAVE_WINSOCK_H */--/* Define to the address where bug reports for this package should be sent. */-#define PACKAGE_BUGREPORT "libraries@haskell.org"--/* Define to the full name of this package. */-#define PACKAGE_NAME "Haskell network package"--/* Define to the full name and version of this package. */-#define PACKAGE_STRING "Haskell network package 1.0"--/* Define to the one symbol short name of this package. */-#define PACKAGE_TARNAME "network"--/* Define to the version of this package. */-#define PACKAGE_VERSION "1.0"--/* Define to 1 if you have the ANSI C header files. */-#define STDC_HEADERS 1--/* Define to empty if `const' does not conform to ANSI C. */-/* #undef const */
include/HsNetworkConfig.h.in view
@@ -76,6 +76,9 @@ /* Define to 1 if `msg_control' is member of `struct msghdr'. */ #undef HAVE_STRUCT_MSGHDR_MSG_CONTROL +/* Define to 1 if you have both SO_PEERCRED and struct ucred. */+#undef HAVE_STRUCT_UCRED+ /* Define to 1 if you have the `symlink' function. */ #undef HAVE_SYMLINK
network.buildinfo.in view
@@ -1,4 +1,4 @@-ghc-options: -DCALLCONV=@CALLCONV@-cc-options: -DCALLCONV=@CALLCONV@+ghc-options: -DCALLCONV=@CALLCONV@ @EXTRA_CPPFLAGS@+cc-options: -DCALLCONV=@CALLCONV@ @EXTRA_CPPFLAGS@ c-sources: @EXTRA_SRCS@ extra-libraries: @EXTRA_LIBS@
network.cabal view
@@ -1,5 +1,5 @@ name: network-version: 2.1.0.0+version: 2.2.0.0 license: BSD3 license-file: LICENSE maintainer: libraries@haskell.org