hookup 0.5 → 0.6
raw patch · 3 files changed
+19/−7 lines, 3 filesdep ~attoparsecdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: attoparsec, base
API changes (from Hackage documentation)
- Hookup: pattern AddrNotSupported :: () => () => CommandReply
+ Hookup: instance GHC.Exception.Type.Exception Hookup.ConnectError
+ Hookup: instance GHC.Show.Show Hookup.ConnectError
+ Hookup: pattern AddrNotSupported :: CommandReply
+ Hookup: pattern CmdNotSupported :: CommandReply
+ Hookup: pattern ConnectionRefused :: CommandReply
+ Hookup: pattern GeneralFailure :: CommandReply
+ Hookup: pattern HostUnreachable :: CommandReply
+ Hookup: pattern NetUnreachable :: CommandReply
+ Hookup: pattern NotAllowed :: CommandReply
+ Hookup: pattern Succeeded :: CommandReply
+ Hookup: pattern TTLExpired :: CommandReply
- Hookup: ConnectionFailure :: [IOError] -> ConnectionFailure
+ Hookup: ConnectionFailure :: [ConnectError] -> ConnectionFailure
Files
- ChangeLog.md +4/−0
- hookup.cabal +2/−2
- src/Hookup.hs +13/−5
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for hookup +## 0.6++* Include SockAddr in connection exceptions+ ## 0.5 * Don't use `AI_ADDRCONFIG` flag
hookup.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: hookup-version: 0.5+version: 0.6 synopsis: Abstraction over creating network connections with SOCKS5 and TLS description: This package provides an abstraction for communicating with line-oriented network services while abstracting over the use of SOCKS5 and TLS (via OpenSSL)@@ -37,7 +37,7 @@ cbits/pem_password_cb.c build-depends:- base >=4.11 && <4.15,+ base >=4.11 && <4.16, async ^>=2.2, stm ^>=2.5, network >=3.0 && <3.2,
src/Hookup.hs view
@@ -73,7 +73,7 @@ import qualified Data.ByteString.Char8 as B8 import Data.Foldable import Data.List (intercalate, partition)-import Data.Maybe (fromMaybe)+import Data.Maybe (fromMaybe, mapMaybe) import Foreign.C.String (withCStringLen) import Foreign.Ptr (nullPtr) import Network.Socket (AddrInfo, HostName, PortNumber, SockAddr, Socket, Family)@@ -136,7 +136,7 @@ -- | Failure during 'getAddrInfo' resolving remote host = HostnameResolutionFailure HostName String -- | Failure during 'connect' to remote host- | ConnectionFailure [IOError]+ | ConnectionFailure [ConnectError] -- | Failure during 'recvLine' | LineTooLong -- | Incomplete line during 'recvLine'@@ -180,6 +180,12 @@ AddrNotSupported -> "address type not supported" CommandReply n -> "unknown reply " ++ show n +data ConnectError = ConnectError SockAddr IOError+ deriving Show++instance Exception ConnectError where+ displayException (ConnectError addr e) = show addr ++ ": " ++ displayException e+ -- | Default values for TLS that use no client certificates, use -- system CA root, @\"HIGH\"@ cipher suite, and which validate hostnames. defaultTlsParams :: TlsParams@@ -267,7 +273,7 @@ (throwIO (HostnameResolutionFailure h "No source/destination address family match")) res <- concurrentAttempts connAttemptDelay Socket.close (uncurry connectToAddrInfo <$> pairs) case res of- Left es -> throwIO (ConnectionFailure [ioe | e <- es, Just ioe <- [fromException e]])+ Left es -> throwIO (ConnectionFailure (mapMaybe fromException es)) Right s -> pure s hints :: AddrInfo@@ -318,10 +324,12 @@ -- by the given 'AddrInfo' and return the connected socket. connectToAddrInfo :: Maybe SockAddr -> AddrInfo -> IO Socket connectToAddrInfo mbSrc info- = bracketOnError (socket' info) Socket.close $ \s ->+ = let addr = Socket.addrAddress info in+ bracketOnError (socket' info) Socket.close $ \s -> do traverse_ (bind' s) mbSrc- Socket.connect s (Socket.addrAddress info)+ Socket.connect s addr pure s+ `catch` (throwIO . ConnectError addr) -- | A version of 'Socket.bind' that doesn't bother binding on the wildcard -- address. The effect of binding on a wildcard address in this library