small improvement to packet flushing

This commit is contained in:
Joey Hess 2018-08-10 18:08:54 -04:00
parent 65de44aa13
commit 4649625f04
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 12 additions and 4 deletions

View file

@ -79,7 +79,8 @@ handshake selectrole selectcapability input output =
case selectrole role of
Left e -> return (Left e)
Right myrole -> sendpkt rolePkt myrole $
sendpkt versionPkt (Version "2") $
sendpkt versionPkt (Version "2") $ do
hFlush output
exchangecaps $ \mycaps -> return $
Right (myrole, mycaps)
where
@ -87,13 +88,15 @@ handshake selectrole selectcapability input output =
sendpkt f v cnt = case f v of
Just pkt -> do
hPutBuilder output $ encodePktLine pkt
hFlush output
writePktLine output pkt
cnt
Nothing -> return $ Left $
"failed constructing pkt-line packet for: " ++ show v
sendpkts _ [] cnt = sendpkt Just flushPkt cnt
sendpkts _ [] cnt = do
writePktLine output flushPkt
hFlush output
cnt
sendpkts f (v:vs) cnt = sendpkt f v $ sendpkts f vs cnt
getpkt parser cnt = readPktLine input >>= \case

View file

@ -19,6 +19,7 @@ module Git.Protocol.PktLine (
decodePktLine,
splitPktLine,
readPktLine,
writePktLine,
) where
import qualified Data.ByteString as S
@ -156,3 +157,7 @@ readPktLine h = do
body <- S.hGet h (len - 4)
let parser = parsePktLine' len <* endOfInput
return $ Just $ parseOnly parser body
-- | Sends a packet to the Handle. Does not flush the Handle.
writePktLine :: Handle -> PktLine -> IO ()
writePktLine h = hPutBuilder h . encodePktLine