From 0f8a0bf2c0dce27cb832896731e2047e07310ebc Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Thu, 12 Jun 2025 21:56:22 -0400 Subject: fig-bus: Properly handle bus close, wait longer between restarts --- fig-bus/src/Fig/Bus/Binary/Utils.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'fig-bus/src/Fig/Bus') diff --git a/fig-bus/src/Fig/Bus/Binary/Utils.hs b/fig-bus/src/Fig/Bus/Binary/Utils.hs index a270fcc..8add010 100644 --- a/fig-bus/src/Fig/Bus/Binary/Utils.hs +++ b/fig-bus/src/Fig/Bus/Binary/Utils.hs @@ -15,13 +15,14 @@ intFromLEBytes [] = 0 intFromLEBytes (x:xs) = shiftL (intFromLEBytes xs) 8 .|. fromIntegral x readLengthPrefixed :: Handle -> IO (Maybe ByteString) -readLengthPrefixed h = do - n <- hGet h 4 - case intFromLEBytes (BS.unpack n) of - 0 -> pure $ Just "" - len -> do - x <- hGet h len - pure $ Just x +readLengthPrefixed h = hGet h 4 >>= \case + n | BS.null n -> pure Nothing + n -> + case intFromLEBytes (BS.unpack n) of + 0 -> pure $ Just "" + len -> do + x <- hGet h len + pure $ Just x readEvent :: Handle -> IO (Maybe EventType) readEvent h = do -- cgit v1.2.3