git.iko.soy/distributed-process
on master help sign in
strictified network-transport-pipes
commitf5494b327b96493a281b0fb7a39366f1d09fa712 authorAdam Foltzer <acfoltzer@gmail.com> dateThu 23 Feb 2012, 16:36 (15 years ago) parent900dea9
1 file changed+12−13
network-transport-pipes/src/Network/Transport/Pipes.hs+12−13
network-transport-pipes/src/Network/Transport/Pipes.hs+12−13
@@ -25,8 +25,7 @@ import Data.Word
2525import Data.Int
2626import Data.IORef
2727import qualified Data.IntMap as IntMap
28−import qualified Data.ByteString.Char8 as BSS
29−import qualified Data.ByteString.Lazy.Char8 as BS
28+import qualified Data.ByteString.Char8 as BS
3029
3130-- For some STRANGE reason this is not working with Data.Binary [2012.02.20]:
3231#define CEREAL
@@ -54,18 +53,18 @@ import qualified "unix-bytestring" System.Posix.IO.ByteString as PIO
5453import System.Posix.IO as PIO (openFd, closeFd, -- append, exclusive, noctty, nonBlock, trunc,
5554 OpenFileFlags(..), OpenMode(ReadOnly, WriteOnly))
5655-- (fromS,toS) = (BS.pack, BS.unpack)
57−(fromS,toS) = (BSS.pack, BSS.unpack)
56+(fromS,toS) = (BS.pack, BS.unpack)
5857fromBS = id
5958readit fd n = PIO.fdRead fd n
6059#else
6160import qualified System.Posix.IO as PIO
6261(toS,fromS) = (id,id)
63−fromBS = BSS.unpack
62+fromBS = BS.unpack
6463readit fd n = do (s,_) <- PIO.fdRead fd n
65− return (BSS.pack s)
64+ return (BS.pack s)
6665#endif
6766-- readit :: Fd -> Int -> IO BS.ByteString
68−readit :: Fd -> ByteCount -> IO BSS.ByteString
67+readit :: Fd -> ByteCount -> IO BS.ByteString
6968
7069----------------------------------------------------------------------------------------------------
7170
@@ -135,7 +134,7 @@ mkTransport = do
135134 -- Otherwise it's just a simple write:
136135 -- We append the length as a header. TODO - REMOVE EXTRA COPY HERE:
137136
138− let hdrbss :: BSS.ByteString
137+ let hdrbss :: BS.ByteString
139138#ifdef CEREAL
140139 hdrbss = encode msgsize
141140#else
@@ -144,13 +143,13 @@ mkTransport = do
144143#endif
145144
146145-- let finalmsg = BS.concat (encode msgsize : bss)
147− let finalmsg = BSS.concat (hdrbss : concatMap BS.toChunks bsls)
146+ let finalmsg = BS.concat (hdrbss : bsls)
148147
149148 fd <- readMVar mv -- Synchronize with file opening.
150149 ----------------------------------------
151150 cnt <- PIO.fdWrite fd (fromBS finalmsg) -- inefficient to use String here!
152− unless (fromIntegral cnt == BSS.length finalmsg) $
153− error$ "Failed to write message in one go, length: "++ show (BSS.length finalmsg)
151+ unless (fromIntegral cnt == BS.length finalmsg) $
152+ error$ "Failed to write message in one go, length: "++ show (BS.length finalmsg)
154153 ----------------------------------------
155154 return ()
156155 , closeSourceEnd = do
@@ -167,13 +166,13 @@ mkTransport = do
167166 -- happen on multiple threads so we grab a lock.
168167 takeMVar lock
169168
170− let spinread :: Int -> IO BSS.ByteString
169+ let spinread :: Int -> IO BS.ByteString
171170 spinread desired = do
172171
173172 bs <- tryUntilNoIOErr$
174173 readit fd (fromIntegral desired)
175174
176− case BSS.length bs of
175+ case BS.length bs of
177176 n | n == desired -> return bs
178177 0 -> do threadDelay (10*1000)
179178 spinread desired
@@ -193,7 +192,7 @@ mkTransport = do
193192 Left err -> error$ "ERROR: "++ err
194193 Right size -> spinread (fromIntegral (size::Word32))
195194 putMVar lock ()
196− return [BS.fromChunks [payload]] -- How terribly listy.
195+ return [payload] -- How terribly listy.
197196 , closeTargetEnd = do
198197 fd <- readMVar mv
199198 PIO.closeFd fd