@@ -49,7 +49,7 @@ decode = Ser.decode
4949import Data.ByteString.Lazy.Char8 (ByteString)
5050import qualified Data.ByteString.Lazy.Char8 as BS
5151import qualified Network.Socket.ByteString.Lazy as NBS
52−sendNBS sock bs = NBS.sendAll sock $! head bs
52+sendNBS sock = NBS.sendAll sock . BS.concat
5353encode = Ser.encodeLazy
5454decode = Ser.decodeLazy
5555#endif
@@ -133,7 +133,7 @@ mkSourceEnd host service chanId = withSocketsDo $ do
133133 return SourceEnd
134134 { send = {-# SCC "send" #-} \bss -> do
135135 let size = fromIntegral (sum . map BS.length $ bss) :: Int32
136− sizeStr | size < 255 = encode (fromIntegral size :: Word8)
136+ sizeStr | size < 255 = BS.singleton (toEnum $ fromEnum size)
137137 | otherwise = BS.cons (toEnum 255) (encode size)
138138 sendNBS sock (sizeStr:bss)
139139 , closeSourceEnd = {-# SCC "closeSourceEnd" #-} sClose sock
@@ -179,7 +179,7 @@ procConnections chans sock = forever $ do
179179
180180-- | This function first extracts a header of type Word8, which determines
181181-- the size of the ByteString that follows. If this size is 0, this indicates
182−-- that the ByteString is large, so the next value is an Int64, which
182+-- that the ByteString is large, so the next value is an Int32, which
183183-- determines the size of the ByteString that follows. The ByteString is then
184184-- extracted from the socket, and then written to the Chan only when
185185-- complete. If either of the first header size is null this indicates the
@@ -221,18 +221,13 @@ procMessages chans chanId chan sock = do
221221 writeChan chan [bs]
222222 procMessages chans chanId chan sock
223223
224−-- | The result of `recvExact sock n` is a `[ByteString]` whose concatenation
225−-- is of length `n`, received from `sock`. No more bytes than necessary are
226−-- read from the socket.
227−-- NB: This uses Network.Socket.ByteString.recv, which may *discard*
228−-- superfluous input depending on the socket type. Also note that
229−-- if `recv` returns an empty `ByteString` then this means that the socket
230−-- was closed: in this case, we return an empty list.
231−-- NB: It may be appropriate to change the return type to
232−-- IO (Either ByteString ByteString), where `return Left bs` indicates
233−-- a partial retrieval since the socket was closed, and `return Right bs`
234−-- indicates success. This hasn't been implemented, since a Transport `receive`
235−-- represents an atomic receipt of a message.
224+-- | The normal result of `recvExact sock n` is `Right ByteString`
225+-- whose string of length `n`, received from `sock`. If fewer than `n`
226+-- bytes are read from `sock` before it closes, the result is `Left
227+-- ByteString` whose string is those bytes that were received. No more
228+-- bytes than necessary are read from the socket. NB: This uses
229+-- Network.Socket.ByteString.recv, which may *discard* superfluous
230+-- input depending on the socket type.
236231#ifndef LAZY
237232recvExact :: Socket -> Int32 -> IO (Either ByteString ByteString)
238233recvExact sock l = do