@@ -49,7 +49,7 @@ decode = Ser.decode
49import Data.ByteString.Lazy.Char8 (ByteString)
49import Data.ByteString.Lazy.Char8 (ByteString)
50import qualified Data.ByteString.Lazy.Char8 as BS
50import qualified Data.ByteString.Lazy.Char8 as BS
51import qualified Network.Socket.ByteString.Lazy as NBS
51import qualified Network.Socket.ByteString.Lazy as NBS
52−sendNBS sock bs = NBS.sendAll sock $! head bs
52+sendNBS sock = NBS.sendAll sock . BS.concat
53encode = Ser.encodeLazy
53encode = Ser.encodeLazy
54decode = Ser.decodeLazy
54decode = Ser.decodeLazy
@@ -133,7 +133,7 @@ mkSourceEnd host service chanId = withSocketsDo $ do
133 return SourceEnd
133 return SourceEnd
134 { send = {-# SCC "send" #-} \bss -> do
134 { send = {-# SCC "send" #-} \bss -> do
135 let size = fromIntegral (sum . map BS.length $ bss) :: Int32
135 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)
137 | otherwise = BS.cons (toEnum 255) (encode size)
137 | otherwise = BS.cons (toEnum 255) (encode size)
138 sendNBS sock (sizeStr:bss)
138 sendNBS sock (sizeStr:bss)
139 , closeSourceEnd = {-# SCC "closeSourceEnd" #-} sClose sock
139 , closeSourceEnd = {-# SCC "closeSourceEnd" #-} sClose sock
@@ -179,7 +179,7 @@ procConnections chans sock = forever $ do
180-- | This function first extracts a header of type Word8, which determines
180-- | This function first extracts a header of type Word8, which determines
181-- the size of the ByteString that follows. If this size is 0, this indicates
181-- 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
183-- determines the size of the ByteString that follows. The ByteString is then
183-- determines the size of the ByteString that follows. The ByteString is then
184-- extracted from the socket, and then written to the Chan only when
184-- extracted from the socket, and then written to the Chan only when
185-- complete. If either of the first header size is null this indicates the
185-- complete. If either of the first header size is null this indicates the
@@ -221,18 +221,13 @@ procMessages chans chanId chan sock = do
221 writeChan chan [bs]
221 writeChan chan [bs]
222 procMessages chans chanId chan sock
222 procMessages chans chanId chan sock
224−-- | The result of `recvExact sock n` is a `[ByteString]` whose concatenation
224+-- | The normal result of `recvExact sock n` is `Right ByteString`
225−-- is of length `n`, received from `sock`. No more bytes than necessary are
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
226−-- read from the socket.
228+-- bytes than necessary are read from the socket. NB: This uses
227−-- NB: This uses Network.Socket.ByteString.recv, which may *discard*
229+-- Network.Socket.ByteString.recv, which may *discard* superfluous
228−-- superfluous input depending on the socket type. Also note that
230+-- input depending on the socket type.
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.
236#ifndef LAZY
231#ifndef LAZY
237recvExact :: Socket -> Int32 -> IO (Either ByteString ByteString)
232recvExact :: Socket -> Int32 -> IO (Either ByteString ByteString)
238recvExact sock l = do
233recvExact sock l = do