@@ -25,8 +25,7 @@ import Data.Word
25import Data.Int
25import Data.Int
26import Data.IORef
26import Data.IORef
27import qualified Data.IntMap as IntMap
27import qualified Data.IntMap as IntMap
28−import qualified Data.ByteString.Char8 as BSS
28+import qualified Data.ByteString.Char8 as BS
29−import qualified Data.ByteString.Lazy.Char8 as BS
31-- For some STRANGE reason this is not working with Data.Binary [2012.02.20]:
30-- For some STRANGE reason this is not working with Data.Binary [2012.02.20]:
32#define CEREAL
31#define CEREAL
@@ -54,18 +53,18 @@ import qualified "unix-bytestring" System.Posix.IO.ByteString as PIO
54import System.Posix.IO as PIO (openFd, closeFd, -- append, exclusive, noctty, nonBlock, trunc,
53import System.Posix.IO as PIO (openFd, closeFd, -- append, exclusive, noctty, nonBlock, trunc,
55 OpenFileFlags(..), OpenMode(ReadOnly, WriteOnly))
54 OpenFileFlags(..), OpenMode(ReadOnly, WriteOnly))
56-- (fromS,toS) = (BS.pack, BS.unpack)
55-- (fromS,toS) = (BS.pack, BS.unpack)
57−(fromS,toS) = (BSS.pack, BSS.unpack)
56+(fromS,toS) = (BS.pack, BS.unpack)
58fromBS = id
57fromBS = id
59readit fd n = PIO.fdRead fd n
58readit fd n = PIO.fdRead fd n
61import qualified System.Posix.IO as PIO
60import qualified System.Posix.IO as PIO
62(toS,fromS) = (id,id)
61(toS,fromS) = (id,id)
63−fromBS = BSS.unpack
62+fromBS = BS.unpack
64readit fd n = do (s,_) <- PIO.fdRead fd n
63readit fd n = do (s,_) <- PIO.fdRead fd n
65− return (BSS.pack s)
64+ return (BS.pack s)
67-- readit :: Fd -> Int -> IO BS.ByteString
66-- readit :: Fd -> Int -> IO BS.ByteString
68−readit :: Fd -> ByteCount -> IO BSS.ByteString
67+readit :: Fd -> ByteCount -> IO BS.ByteString
70----------------------------------------------------------------------------------------------------
69----------------------------------------------------------------------------------------------------
@@ -135,7 +134,7 @@ mkTransport = do
135 -- Otherwise it's just a simple write:
134 -- Otherwise it's just a simple write:
136 -- We append the length as a header. TODO - REMOVE EXTRA COPY HERE:
135 -- We append the length as a header. TODO - REMOVE EXTRA COPY HERE:
138− let hdrbss :: BSS.ByteString
137+ let hdrbss :: BS.ByteString
139#ifdef CEREAL
138#ifdef CEREAL
140 hdrbss = encode msgsize
139 hdrbss = encode msgsize
@@ -144,13 +143,13 @@ mkTransport = do
146-- let finalmsg = BS.concat (encode msgsize : bss)
145-- let finalmsg = BS.concat (encode msgsize : bss)
147− let finalmsg = BSS.concat (hdrbss : concatMap BS.toChunks bsls)
146+ let finalmsg = BS.concat (hdrbss : bsls)
149 fd <- readMVar mv -- Synchronize with file opening.
148 fd <- readMVar mv -- Synchronize with file opening.
150 ----------------------------------------
149 ----------------------------------------
151 cnt <- PIO.fdWrite fd (fromBS finalmsg) -- inefficient to use String here!
150 cnt <- PIO.fdWrite fd (fromBS finalmsg) -- inefficient to use String here!
152− unless (fromIntegral cnt == BSS.length finalmsg) $
151+ unless (fromIntegral cnt == BS.length finalmsg) $
153− error$ "Failed to write message in one go, length: "++ show (BSS.length finalmsg)
152+ error$ "Failed to write message in one go, length: "++ show (BS.length finalmsg)
154 ----------------------------------------
153 ----------------------------------------
155 return ()
154 return ()
156 , closeSourceEnd = do
155 , closeSourceEnd = do
@@ -167,13 +166,13 @@ mkTransport = do
167 -- happen on multiple threads so we grab a lock.
166 -- happen on multiple threads so we grab a lock.
168 takeMVar lock
167 takeMVar lock
170− let spinread :: Int -> IO BSS.ByteString
169+ let spinread :: Int -> IO BS.ByteString
171 spinread desired = do
170 spinread desired = do
173 bs <- tryUntilNoIOErr$
172 bs <- tryUntilNoIOErr$
174 readit fd (fromIntegral desired)
173 readit fd (fromIntegral desired)
176− case BSS.length bs of
175+ case BS.length bs of
177 n | n == desired -> return bs
176 n | n == desired -> return bs
178 0 -> do threadDelay (10*1000)
177 0 -> do threadDelay (10*1000)
179 spinread desired
178 spinread desired
@@ -193,7 +192,7 @@ mkTransport = do
193 Left err -> error$ "ERROR: "++ err
192 Left err -> error$ "ERROR: "++ err
194 Right size -> spinread (fromIntegral (size::Word32))
193 Right size -> spinread (fromIntegral (size::Word32))
195 putMVar lock ()
194 putMVar lock ()
196− return [BS.fromChunks [payload]] -- How terribly listy.
195+ return [payload] -- How terribly listy.
197 , closeTargetEnd = do
196 , closeTargetEnd = do
198 fd <- readMVar mv
197 fd <- readMVar mv
199 PIO.closeFd fd
198 PIO.closeFd fd