Browse Source

Streamline avoids blocking when receiving 0 bytes

Marcos Dumay de Medeiros 8 years ago
parent
commit
2923365862
1 changed files with 5 additions and 4 deletions
  1. 5 4
      src/System/IO/Uniform/Streamline.hs

+ 5 - 4
src/System/IO/Uniform/Streamline.hs

@@ -284,10 +284,11 @@ recieveN n = LBS.toStrict <$> recieveN' n
 
 -- | Lazy version of recieveN
 recieveN' :: MonadIO m => Int -> Streamline m LBS.ByteString
-recieveN' n = Streamline $ \cl ->
-  do
-    (tt, cl') <- recieve cl n
-    return (LBS.fromChunks tt, cl')
+recieveN' n | n <= 0 = return ""
+            | otherwise = Streamline $ \cl ->
+            do
+              (tt, cl') <- recieve cl n
+              return (LBS.fromChunks tt, cl')
   where
     recieve d b
       | isEOF d = eofError "System.IO.Uniform.Streamline.lazyRecieveN"