streaming-commons 0.1.13 → 0.1.14
raw patch · 4 files changed
+79/−1 lines, 4 files
Files
- ChangeLog.md +4/−0
- Data/Streaming/Network.hs +14/−0
- streaming-commons.cabal +2/−1
- test/Data/Streaming/ProcessSpec.hs +59/−0
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.1.14++* Exporting HasReadBufferSize; instance for ClientSettingsUnix [#24](https://github.com/fpco/streaming-commons/pull/24)+ ## 0.1.13 * Make size of read buffer configurable, change default size to 32 kiB [#23](https://github.com/fpco/streaming-commons/pull/23)
Data/Streaming/Network.hs view
@@ -28,6 +28,7 @@ , HasPort (..) , HasAfterBind (..) , HasReadWrite (..)+ , HasReadBufferSize (..) #if !WINDOWS , HasPath (..) #endif@@ -535,20 +536,33 @@ setAfterBind :: HasAfterBind a => (Socket -> IO ()) -> a -> a setAfterBind p = runIdentity . afterBindLens (const (Identity p)) +-- | Since 0.1.13 class HasReadBufferSize a where readBufferSizeLens :: Functor f => (Int -> f Int) -> a -> f a+-- | Since 0.1.13 instance HasReadBufferSize ServerSettings where readBufferSizeLens f ss = fmap (\p -> ss { serverReadBufferSize = p }) (f (serverReadBufferSize ss))+-- | Since 0.1.13 instance HasReadBufferSize ClientSettings where readBufferSizeLens f cs = fmap (\p -> cs { clientReadBufferSize = p }) (f (clientReadBufferSize cs)) #if !WINDOWS+-- | Since 0.1.13 instance HasReadBufferSize ServerSettingsUnix where readBufferSizeLens f ss = fmap (\p -> ss { serverReadBufferSizeUnix = p }) (f (serverReadBufferSizeUnix ss))+-- | Since 0.1.14+instance HasReadBufferSize ClientSettingsUnix where+ readBufferSizeLens f ss = fmap (\p -> ss { clientReadBufferSizeUnix = p }) (f (clientReadBufferSizeUnix ss)) #endif +-- | Get buffer size used when reading from socket.+--+-- Since 0.1.13 getReadBufferSize :: HasReadBufferSize a => a -> Int getReadBufferSize = getConstant . readBufferSizeLens Constant +-- | Set buffer size used when reading from socket.+--+-- Since 0.1.13 setReadBufferSize :: HasReadBufferSize a => Int -> a -> a setReadBufferSize p = runIdentity . readBufferSizeLens (const (Identity p))
streaming-commons.cabal view
@@ -1,5 +1,5 @@ name: streaming-commons-version: 0.1.13+version: 0.1.14 synopsis: Common lower-level functions needed by various streaming data libraries description: Provides low-dependency functionality commonly needed by various streaming data libraries, such as conduit and pipes. homepage: https://github.com/fpco/streaming-commons@@ -88,6 +88,7 @@ Data.Streaming.FileReadSpec Data.Streaming.FilesystemSpec Data.Streaming.NetworkSpec+ Data.Streaming.ProcessSpec Data.Streaming.TextSpec Data.Streaming.ZlibSpec build-depends: base
+ test/Data/Streaming/ProcessSpec.hs view
@@ -0,0 +1,59 @@+{-# LANGUAGE CPP #-}+module Data.Streaming.ProcessSpec (spec, main) where++import Test.Hspec+import Test.Hspec.QuickCheck (prop)+import Control.Concurrent.Async (concurrently)+import qualified Data.ByteString.Lazy as L+import qualified Data.ByteString as S+import System.Exit+import Control.Concurrent (threadDelay)+import Data.Streaming.Process+import System.IO (hClose)++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+#ifndef WINDOWS+ prop "cat" $ \wss -> do+ let lbs = L.fromChunks $ map S.pack wss+ (sink, source, Inherited, cph) <- streamingProcess (shell "cat")+ ((), bs) <- concurrently+ (do+ L.hPut sink lbs+ hClose sink)+ (S.hGetContents source)+ L.fromChunks [bs] `shouldBe` lbs+ ec <- waitForStreamingProcess cph+ ec `shouldBe` ExitSuccess++ it "closed stream" $ do+ (ClosedStream, source, Inherited, cph) <- streamingProcess (shell "cat")+ bss <- S.hGetContents source+ bss `shouldBe` S.empty++ ec <- waitForStreamingProcess cph+ ec `shouldBe` ExitSuccess++ it "checked process" $ do+ let isRightException ProcessExitedUnsuccessfully {} = True+ withCheckedProcess (proc "false" [])+ (\Inherited Inherited Inherited -> return ())+ `shouldThrow` isRightException++#endif+ it "blocking vs non-blocking" $ do+ (ClosedStream, ClosedStream, ClosedStream, cph) <- streamingProcess (shell "sleep 1")++ mec1 <- getStreamingProcessExitCode cph+ mec1 `shouldBe` Nothing++ threadDelay 1500000++ mec2 <- getStreamingProcessExitCode cph+ mec2 `shouldBe` Just ExitSuccess++ ec <- waitForStreamingProcess cph+ ec `shouldBe` ExitSuccess