packages feed

conduit-extra 1.1.3.4 → 1.1.4

raw patch · 3 files changed

+65/−9 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Data.Conduit.Network: forkTCPServer :: MonadBaseControl IO m => ServerSettings -> (AppData -> m ()) -> m ThreadId
- Data.Conduit.Network.UDP: Message :: !ByteString -> !SockAddr -> Message
+ Data.Conduit.Network.UDP: Message :: SrictNotUnpackedByteString -> SrictNotUnpackedSockAddr -> Message
- Data.Conduit.Network.UDP: msgData :: Message -> !ByteString
+ Data.Conduit.Network.UDP: msgData :: Message -> SrictNotUnpackedByteString
- Data.Conduit.Network.UDP: msgSender :: Message -> !SockAddr
+ Data.Conduit.Network.UDP: msgSender :: Message -> SrictNotUnpackedSockAddr

Files

Data/Conduit/Network.hs view
@@ -17,6 +17,7 @@     , serverSettings     , SN.runTCPServer     , SN.runTCPServerWithHandle+    , forkTCPServer     , runGeneralTCPServer       -- ** Client     , SN.ClientSettings@@ -48,10 +49,10 @@ import qualified Data.ByteString.Char8 as S8 import Control.Monad.IO.Class (MonadIO (liftIO)) import Control.Exception (throwIO, SomeException, try, finally, bracket, IOException, catch)-import Control.Monad (forever, unless, void)+import Control.Monad (unless, void) import Control.Monad.Trans.Control (MonadBaseControl, control, liftBaseWith) import Control.Monad.Trans.Class (lift)-import Control.Concurrent (forkIO, threadDelay, newEmptyMVar, putMVar, takeMVar)+import Control.Concurrent (forkIO, newEmptyMVar, putMVar, takeMVar, MVar, ThreadId) import qualified Data.Streaming.Network as SN  -- | Stream data from the socket.@@ -96,6 +97,34 @@  appSink :: (SN.HasReadWrite ad, MonadIO m) => ad -> Consumer ByteString m () appSink ad = awaitForever $ \d -> liftIO $ SN.appWrite ad d >> Conc.yield++addBoundSignal::MVar ()-> SN.ServerSettings -> SN.ServerSettings+addBoundSignal isBound set = SN.setAfterBind ( \socket -> originalAfterBind socket >>  signalBound socket) set+                             where originalAfterBind :: Socket -> IO ()+                                   originalAfterBind = SN.getAfterBind set+                                   signalBound :: Socket -> IO ()+                                   signalBound _socket = putMVar isBound ()++-- | Fork a TCP Server+--+-- Will fork the runGeneralTCPServer function but will only return from+-- this call when the server is bound to the port and accepting incoming+-- connections. Will return the thread id of the server+--+-- Since 1.1.4+forkTCPServer :: MonadBaseControl IO m+                    => SN.ServerSettings+                    -> (SN.AppData -> m ())+                    -> m ThreadId+forkTCPServer set f =+       liftBaseWith $ \run -> do+         isBound <- newEmptyMVar+         let setWithWaitForBind = addBoundSignal isBound set+         threadId <- forkIO . void . run $ runGeneralTCPServer setWithWaitForBind f+         takeMVar isBound+         return threadId++  -- | Run a general TCP server --
conduit-extra.cabal view
@@ -1,5 +1,5 @@ Name:                conduit-extra-Version:             1.1.3.4+Version:             1.1.4 Synopsis:            Batteries included conduit: adapters for common libraries. Description:     The conduit package itself maintains relative small dependencies. The purpose of this package is to collect commonly used utility functions wrapping other library dependencies, without depending on heavier-weight dependencies. The basic idea is that this package should only depend on haskell-platform packages and conduit.
test/Data/Conduit/NetworkSpec.hs view
@@ -3,16 +3,43 @@  import Data.Conduit import Data.Conduit.Network-import Control.Concurrent (forkIO, threadDelay)+import Control.Concurrent (forkIO, threadDelay, putMVar, newEmptyMVar, takeMVar, killThread) import Control.Monad (replicateM_) import Test.Hspec  spec :: Spec-spec = it "Data.Conduit.Network" $ do-    _ <- forkIO $ runTCPServer (serverSettings 4009 "*4") echo-    threadDelay 1000000-    replicateM_ 10000-        $ runTCPClient (clientSettings 4009 "127.0.0.1") doNothing+spec = describe "Data.Conduit.Network" $ do+    describe "run general server" $ do+        it "running tcp server" $ do+            _ <- forkIO $ runTCPServer (serverSettings 4009 "*4") echo+            threadDelay 1000000+            replicateM_ 100+                $ runTCPClient (clientSettings 4009 "127.0.0.1") doNothing+    describe "fork server" $ do+        it "can connect to server" $ do+            let set = serverSettings 4010 "*4"+            threadId <- forkTCPServer set echo+            replicateM_ 100+                $ runTCPClient (clientSettings 4010 "127.0.0.1") doNothing+            killThread threadId++        it "fork server also executes custom afterBind" $ do+            assertMVar <- newEmptyMVar+            let set = serverSettings 4010 "*4"+                setWithAfterBind = setAfterBind (\_ -> putMVar assertMVar ()) set+            threadId <- forkTCPServer setWithAfterBind echo+            takeMVar assertMVar+            killThread threadId++        it "fork server really waits for server to be finalized before returning" $ do+            let set = serverSettings 4010 "*4"+                setWithAfterBind = setAfterBind (\_ -> threadDelay 1000000) set+            threadId <- forkTCPServer setWithAfterBind echo+            replicateM_ 100+                $ runTCPClient (clientSettings 4010 "127.0.0.1") doNothing+            killThread threadId++  echo :: AppData -> IO () echo ad = appSource ad $$ appSink ad