packages feed

network 3.2.13.0 → 3.2.14.0

raw patch · 10 files changed

+74/−33 lines, 10 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,5 +1,14 @@ # CHANGELOG for network +## Version 3.2.14.0++* dontfrag for WINE+  [#605](https://github.com/haskell/network/pull/605)+* Describe getaddrinfo errors on Windows with the Winsock table+  [#640](https://github.com/haskell/network/pull/640)+* HsNetDef.h: use ccall for aarch64 too+  [#651](https://github.com/haskell/network/pull/651)+ ## Version 3.2.13.0  * Give Winsock errors the IOErrorType of their errno
Network/Socket/Info.hsc view
@@ -11,7 +11,11 @@ import qualified Data.List.NonEmpty as NE import Foreign.Marshal.Alloc (alloca, allocaBytes) import Foreign.Marshal.Utils (maybeWith, with)+#if defined(mingw32_HOST_OS)+import GHC.IO.Exception (IOErrorType(NoSuchThing), IOException(..))+#else import GHC.IO.Exception (IOErrorType(NoSuchThing))+#endif import System.IO.Error (ioeSetErrorString, mkIOError)  import Network.Socket.Imports@@ -281,11 +285,7 @@             ais       <- release (followAddrInfo ptr_addrs) `onException` c_freeaddrinfo ptr_addrs             c_freeaddrinfo ptr_addrs             return ais-          else do-            err <- gai_strerror ret-            ioError $ ioeSetErrorString-                        (mkIOError NoSuchThing message Nothing Nothing)-                        err+          else gaiError message ret     message = concat [         "Network.Socket.getAddrInfo (called with preferred socket type/protocol: "       , maybe "Nothing" show hints@@ -342,15 +342,31 @@ foreign import ccall safe "hsnet_freeaddrinfo"     c_freeaddrinfo :: Ptr AddrInfo -> IO () -gai_strerror :: CInt -> IO String+-- | The error which getaddrinfo(3) or getnameinfo(3) reported as @rc@.+--   On Windows the code is a Winsock code, kept in 'ioe_errno' as for+--   other socket errors.+gaiError :: String -> CInt -> IO a+gaiError loc rc = do+    err <- gai_strerror rc+    let ioe = mkIOError NoSuchThing loc Nothing Nothing+#if defined(mingw32_HOST_OS)+    ioError $ ioeSetErrorString ioe{ioe_errno = Just rc} err+#else+    ioError $ ioeSetErrorString ioe err+#endif -#ifdef HAVE_GAI_STRERROR+gai_strerror :: CInt -> IO String+#if defined(mingw32_HOST_OS)+-- gai_strerror is a macro in mingw, which the configure check misses,+-- and it writes to a static buffer.+gai_strerror = winsockErrorString+#elif defined(HAVE_GAI_STRERROR) gai_strerror n = c_gai_strerror n >>= peekCString  foreign import ccall safe "gai_strerror"     c_gai_strerror :: CInt -> IO CString #else-gai_strerror n = ioError $ userError $ "Network.Socket.gai_strerror not supported: " ++ show n+gai_strerror n = return $ "error " ++ show n #endif  -----------------------------------------------------------------------------@@ -402,11 +418,7 @@             host <- peekIf doHost c_host             serv <- peekIf doService c_serv             return (host, serv)-          else do-            err <- gai_strerror ret-            ioError $ ioeSetErrorString-                        (mkIOError NoSuchThing message Nothing Nothing)-                        err+          else gaiError message ret     message = concat [         "Network.Socket.getNameInfo (called with flags: "       , show flags
Network/Socket/Internal.hs view
@@ -27,6 +27,7 @@     , throwSocketErrorCode #if defined(mingw32_HOST_OS)     , c_getLastError+    , winsockErrorString #endif      -- * Guards for socket operations that may fail@@ -61,9 +62,9 @@ import Control.Exception (evaluate) import System.IO.Unsafe (unsafePerformIO) # if __GLASGOW_HASKELL__ >= 707-import GHC.IO.Exception (IOErrorType(..), IOException(..))+import GHC.IO.Exception (IOException(..)) # else-import GHC.IOBase (IOErrorType(..), IOException(..))+import GHC.IOBase (IOException(..)) # endif import System.IO.Error (ioeSetErrorString, mkIOError) #else@@ -99,8 +100,7 @@ throwSocketErrorCode :: String -> CInt -> IO a #if defined(mingw32_HOST_OS) throwSocketErrorCode name rc = do-    pstr <- c_getWSError rc-    str  <- peekCString pstr+    str <- winsockErrorString rc     let typ = winsockErrorType rc         ioe = (mkIOError typ name Nothing Nothing){ioe_errno = Just rc}     ioError (ioeSetErrorString ioe str)@@ -231,6 +231,14 @@  foreign import ccall unsafe "getWSErrorDescr"   c_getWSError :: CInt -> IO (Ptr CChar)++-- | A description of a Winsock error code.+winsockErrorString :: CInt -> IO String+winsockErrorString rc = do+    pstr <- c_getWSError rc+    if pstr == nullPtr+        then return $ "Unknown WinSock error: " ++ show rc+        else peekCString pstr #endif  -- ---------------------------------------------------------------------
Network/Socket/Posix/HostName.hsc view
@@ -16,7 +16,7 @@  -- | Get name of current host -----   Since: 3.3.0.0+--   @since 3.2.10.0 getHostName :: IO HostName getHostName = allocaArray0 size $ \cstr -> do     throwErrnoIfMinus1_ "getHostName" $ gethostname cstr (fromIntegral size)
Network/Socket/Syscall.hs view
@@ -7,9 +7,7 @@ import Data.Either (isRight) import Foreign.Marshal.Utils (with) import qualified Control.Exception as E-# if defined(mingw32_HOST_OS) import System.IO.Error (catchIOError)-#endif  #if defined(mingw32_HOST_OS) import Control.Exception (bracket)@@ -127,7 +125,7 @@      setDontFragment s = when (family == AF_INET) $ #if HAVE_DECL_IP_DONTFRAG || HAVE_DECL_IP_MTU_DISCOVER-      setSocketOption s DontFragment 1+      setSocketOption s DontFragment 1 `catchIOError` \_ -> return () #else       -- do nothing       return ()
Network/Socket/Win32/HostName.hsc view
@@ -25,7 +25,7 @@  -- | Get name of current host -----   Since: 3.3.0.0+--   @since 3.2.10.0 getHostName :: IO HostName getHostName = with 0 $ \p_charcount -> do     -- On the first run, determine the character count and ignore any error we get
cbits/winSockErr.c view
@@ -2,15 +2,14 @@ #include "HsFFI.h"  #if defined(_WIN32)-#include <stdio.h>  /* to the end */ +/* NULL for a code not in the table, which the caller describes itself:+   formatting it here would need a static buffer, shared between threads. */ const char* getWSErrorDescr(int err) {-  static char  otherErrMsg[256];-   switch (err) {   case WSAEINTR:  return "Interrupted function call (WSAEINTR)";   case WSAEBADF:  return "bad socket descriptor (WSAEBADF)";@@ -67,8 +66,7 @@   case WSANO_RECOVERY:     return "This is a nonrecoverable error (WSANO_RECOVERY)";   case WSANO_DATA:         return "Valid name, no data record of requested type (WSANO_DATA)";   default:-    sprintf(otherErrMsg, "Unknown WinSock error: %u", err);-    return otherErrMsg;+    return NULL;   } } 
include/HsNetDef.h view
@@ -32,7 +32,7 @@ #if defined(mingw32_HOST_OS) # if defined(i386_HOST_ARCH) #  define CALLCONV stdcall-# elif defined(x86_64_HOST_ARCH)+# elif defined(x86_64_HOST_ARCH) || defined(aarch64_HOST_ARCH) #  define CALLCONV ccall # else #  error Unknown mingw32 arch
network.cabal view
@@ -1,6 +1,6 @@ cabal-version:      1.18 name:               network-version:            3.2.13.0+version:            3.2.14.0 license:            BSD3 license-file:       LICENSE maintainer:         Kazu Yamamoto, Tamar Christina
tests/Network/SocketSpec.hs view
@@ -19,8 +19,8 @@ import Network.Socket.ByteString import Network.Test.Common import System.Mem (performGC)-import GHC.IO.Exception (IOErrorType (ResourceVanished))-import System.IO.Error (ioeGetErrorType, tryIOError)+import GHC.IO.Exception (IOErrorType (NoSuchThing, ResourceVanished))+import System.IO.Error (ioeGetErrorString, ioeGetErrorType, tryIOError) import System.IO.Temp (withSystemTempDirectory) import System.Posix.Types (Fd(..)) import Foreign.C.Types ()@@ -214,6 +214,16 @@                 getAddrInfo (Just hints) (Just "127.128.129.130") Nothing             hostAddressToTuple hostAddr `shouldBe` (0x7f, 0x80, 0x81, 0x82) +        -- On Windows this used to be a userError which lost the reason (#636).+        it "throws NoSuchThing with a description for a name it cannot resolve" $ do+            let hints = defaultHints { addrFlags = [AI_NUMERICHOST] }+            r <- tryIOError $ getAddrInfo (Just hints) (Just "no-such-host.invalid") Nothing+            case r :: Either IOError [AddrInfo] of+                Left e -> do+                    ioeGetErrorType e `shouldBe` NoSuchThing+                    ioeGetErrorString e `shouldNotContain` "not supported"+                Right _ -> expectationFailure "resolved a name which is not numeric"+         it "works for IPv6 address" $ do             let hints = defaultHints { addrFlags = [AI_NUMERICHOST, AI_ADDRCONFIG] }                 host = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"@@ -381,10 +391,16 @@      describe "a connection the peer resets" $ do         it "is reported as ResourceVanished" $ do-            let server sock = setSockOpt sock Linger (StructLinger 1 0)+            -- The byte makes the reset follow the connect: an RST which+            -- beat it would fail the connect itself on Linux.+            let server sock = do+                    void $ recv sock 1+                    setSockOpt sock Linger (StructLinger 1 0)                 -- Plain recv on Windows reads through GHC's IO manager,                 -- which does not go by the Winsock code.-                client sock = recvWith sock 1024 retry `shouldThrow` isVanished+                client sock = do+                    sendAll sock "x"+                    recvWith sock 1024 retry `shouldThrow` isVanished                 isVanished e = ioeGetErrorType e == ResourceVanished             tcpTest client server