packages feed

io-streams 1.1.0.3 → 1.1.1.0

raw patch · 2 files changed

+28/−5 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ System.IO.Streams.Network: socketToStreamsWithBufferSize :: Int -> Socket -> IO (InputStream ByteString, OutputStream ByteString)

Files

io-streams.cabal view
@@ -1,5 +1,5 @@ Name:                io-streams-Version:             1.1.0.3+Version:             1.1.1.0 License:             BSD3 License-file:        LICENSE Category:            Data, Network, IO-Streams@@ -79,6 +79,10 @@     * support for spawning processes and communicating with them using streams.   .   /ChangeLog/+  .+    [@1.1.1.0@] Added @System.IO.Streams.Network.socketToStreamsWithBufferSize@,+                allowing control over the size of the receive buffers used when+                reading from sockets.   .     [@1.1.0.3@] Fixed an inconsistent version upper bound in the test suite.   .
src/System/IO/Streams/Network.hs view
@@ -2,11 +2,13 @@ module System.IO.Streams.Network   ( -- * Sockets to Streams     socketToStreams+  , socketToStreamsWithBufferSize   ) where  ------------------------------------------------------------------------------ import           Data.ByteString.Char8      (ByteString) import qualified Data.ByteString.Char8      as S+import           Foreign.Storable           (sizeOf) import           Network.Socket             (Socket) import qualified Network.Socket.ByteString  as N import           System.IO.Streams.Internal (InputStream, OutputStream)@@ -14,21 +16,38 @@   ------------------------------------------------------------------------------+bUFSIZ :: Int+bUFSIZ = 8192 - overhead+  where+    overhead = 4 * (sizeOf $! (0 :: Int))+++------------------------------------------------------------------------------ -- | Converts a 'Socket' to an 'InputStream' \/ 'OutputStream' pair. Note that, -- as is usually the case in @io-streams@, writing a 'Nothing' to the generated -- 'OutputStream' does not cause the underlying 'Socket' to be closed. socketToStreams :: Socket                 -> IO (InputStream ByteString, OutputStream ByteString)-socketToStreams socket = do+socketToStreams = socketToStreamsWithBufferSize bUFSIZ+++------------------------------------------------------------------------------+-- | Converts a 'Socket' to an 'InputStream' \/ 'OutputStream' pair, with+-- control over the size of the receive buffers. Note that, as is usually the+-- case in @io-streams@, writing a 'Nothing' to the generated 'OutputStream'+-- does not cause the underlying 'Socket' to be closed.+socketToStreamsWithBufferSize+    :: Int                      -- ^ how large the receive buffer should be+    -> Socket                   -- ^ network socket+    -> IO (InputStream ByteString, OutputStream ByteString)+socketToStreamsWithBufferSize bufsiz socket = do     is <- Streams.makeInputStream input     os <- Streams.makeOutputStream output     return $! (is, os)    where-    bUFSIZ = 32752-     input = do-        s <- N.recv socket bUFSIZ+        s <- N.recv socket bufsiz         return $! if S.null s then Nothing else Just s      output Nothing  = return $! ()