network-simple 0.3.0 → 0.3.1
raw patch · 4 files changed
+63/−12 lines, 4 filesdep ~exceptions
Dependency ranges changed: exceptions
Files
- LICENSE +1/−1
- changelog.md +44/−0
- network-simple.cabal +5/−4
- src/Network/Simple/TCP.hs +13/−7
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2013, Renzo Carbonara <renzocarbonaraλgmail.com>+Copyright (c) 2013-2014, Renzo Carbonara <renzocarbonaraλgmail.com> All rights reserved.
+ changelog.md view
@@ -0,0 +1,44 @@+# Version 0.3.1++* Bumped upper-bounds on `exceptions` dependency.+++# Version 0.3.0++* Re-export `Network.Socket.close` at `Network.Simple.TCP`, except+ called `closeSock`.++* Re-export `Socket`, `SockAddr`, `HostName` and `ServiceName` from+ `Network.Socket` at `Network.Simple.TCP`.++* Generalize the `IO` monad by using `MonadIO` and `MonadCatch` (from+ the `exceptions` library).+++# Version 0.2.1.0++* Export `send` and `recv` from `Network.Simple.TCP`.++* Re-export `Network.Socket.withSocketsDo` from `Network.Simple.TCP`.+++# Version 0.2.0.1++* FIX: `acceptFork` now properly closes the connection socket, even in+ case of asynchronous exceptions.+++# Version 0.2.0.0++* `Network.Simple.TCP.serveFork` was renamed to `serve`, and the previous+ function named `serve` was removed.+++# Version 0.1.0.1++* Fixed typos, including the maintainer email.+++# Version 0.1.0.0++* First release.
network-simple.cabal view
@@ -1,12 +1,12 @@ name: network-simple-version: 0.3.0+version: 0.3.1 homepage: https://github.com/k0001/network-simple bug-reports: https://github.com/k0001/network-simple/issues license: BSD3 license-file: LICENSE author: Renzo Carbonara maintainer: renzocarbonaraλgmail.com-copyright: Copyright (c) Renzo Carbonara 2013+copyright: Copyright (c) Renzo Carbonara 2013-2014 category: Network build-type: Simple cabal-version: >=1.8@@ -15,9 +15,10 @@ This module exports functions that abstract simple network socket usage patterns. .- See the @NEWS@ file in the source distribution to learn about any+ See the @changelog.md@ file in the source distribution to learn about any important changes between version. extra-source-files:+ changelog.md README.md PEOPLE examples/echo-tcp.hs@@ -37,4 +38,4 @@ , bytestring (>=0.9.2.1 && <0.11) , transformers (>=0.2 && <0.4) -- Packages not in The Haskell Platform- , exceptions (>=0.3 && <0.4)+ , exceptions (>=0.3 && <0.6)
src/Network/Simple/TCP.hs view
@@ -124,7 +124,7 @@ -- and the server address. -> m r connect host port = C.bracket (connectSock host port)- (closeSock . fst)+ (silentCloseSock . fst) -------------------------------------------------------------------------------- @@ -187,7 +187,7 @@ -- ^Computation taking the listening socket and -- the address it's bound to. -> m r-listen hp port = C.bracket listen' (closeSock . fst)+listen hp port = C.bracket listen' (silentCloseSock . fst) where listen' = do x@(bsock,_) <- bindSock hp port liftIO . NS.listen bsock $ max 2048 NS.maxListenQueue@@ -208,7 +208,7 @@ -> m r accept lsock k = do conn@(csock,_) <- liftIO (NS.accept lsock)- C.finally (k conn) (closeSock csock)+ C.finally (k conn) (silentCloseSock csock) {-# INLINABLE accept #-} -- | Accept a single incoming connection and use it in a different thread.@@ -225,7 +225,7 @@ acceptFork lsock k = liftIO $ do conn@(csock,_) <- NS.accept lsock forkFinally (k conn)- (\ea -> do closeSock csock+ (\ea -> do silentCloseSock csock either E.throwIO return ea) {-# INLINABLE acceptFork #-} @@ -276,7 +276,7 @@ tryAddrs [] = error "bindSock: no addresses available" tryAddrs [x] = useAddr x tryAddrs (x:xs) = E.catch (useAddr x)- (\e -> let _ = e :: E.IOException in tryAddrs xs)+ (\e -> let _ = e :: IOError in tryAddrs xs) useAddr addr = E.bracketOnError (newSocket addr) closeSock $ \sock -> do let sockAddr = NS.addrAddress addr@@ -309,12 +309,12 @@ if BS.null bs then return Nothing else return (Just bs)-{-# INLINE recv #-}+{-# INLINABLE recv #-} -- | Writes the given bytes to the socket. send :: MonadIO m => NS.Socket -> BS.ByteString -> m () send sock = \bs -> liftIO (NSB.sendAll sock bs)-{-# INLINE send #-}+{-# INLINABLE send #-} -------------------------------------------------------------------------------- @@ -344,4 +344,10 @@ E.mask $ \restore -> forkIO $ E.try (restore action) >>= and_then ++-- | Like 'closeSock', except it swallows all 'IOError' exceptions.+silentCloseSock :: MonadIO m => NS.Socket -> m ()+silentCloseSock sock = liftIO $ do+ E.catch (closeSock sock)+ (\e -> let _ = e :: IOError in return ())