From 507375d377bd6053b91955744de0736d63f082c2 Mon Sep 17 00:00:00 2001 From: John Millikin Date: Mon, 26 Apr 2010 04:14:51 +0000 Subject: [PATCH] Better error handling for unexpected EOF in 'hGetChar'. --- Network/Protocol/XMPP/Handle.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Network/Protocol/XMPP/Handle.hs b/Network/Protocol/XMPP/Handle.hs index eb71a60..f39c1b7 100644 --- a/Network/Protocol/XMPP/Handle.hs +++ b/Network/Protocol/XMPP/Handle.hs @@ -59,11 +59,14 @@ hPutBytes (SecureHandle _ s) = liftTLS s . TLS.putBytes hGetChar :: Handle -> ErrorT T.Text IO Char hGetChar (PlainHandle h) = liftIO $ IO.hGetChar h -hGetChar (SecureHandle h s) = liftTLS s $ do - pending <- TLS.checkPending - when (pending == 0) $ do - liftIO $ IO.hWaitForInput h (- 1) - return () - - bytes <- TLS.getBytes 1 - return . head . B.unpack $ bytes +hGetChar (SecureHandle h s) = do + bytes <- liftTLS s $ do + pending <- TLS.checkPending + when (pending == 0) $ do + liftIO $ IO.hWaitForInput h (- 1) + return () + + TLS.getBytes 1 + case B.unpack bytes of + (c:_) -> return c + _ -> E.throwError "hGetChar: not enough bytes" -- 2.38.4