diff options
| author | LLLL Colonq <llll@colonq> | 2025-06-12 21:56:22 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2025-06-12 21:56:22 -0400 |
| commit | 0f8a0bf2c0dce27cb832896731e2047e07310ebc (patch) | |
| tree | 063e068dca876db0375b02ae6d3e4fbe89785ff7 /fig-bus | |
| parent | c45abd29a5e4a9146cbe94789b7b3787eb02e5a5 (diff) | |
fig-bus: Properly handle bus close, wait longer between restarts
Diffstat (limited to 'fig-bus')
| -rw-r--r-- | fig-bus/src/Fig/Bus/Binary/Utils.hs | 15 |
1 files changed, 8 insertions, 7 deletions
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 |
