From 3f30f380adb4c6eedf3c919590359c9746f5d8b3 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sun, 8 Mar 2020 23:01:55 -0500 Subject: [PATCH] Call TLS.getBytes again on EAGAIN Since that's what the manpage says to do, and without it we sometimes end up crashing when calling again would have worked. --- lib/Network/Protocol/XMPP/Handle.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Network/Protocol/XMPP/Handle.hs b/lib/Network/Protocol/XMPP/Handle.hs index 1e0eafb..509e796 100644 --- a/lib/Network/Protocol/XMPP/Handle.hs +++ b/lib/Network/Protocol/XMPP/Handle.hs @@ -66,8 +66,11 @@ hGetBytes (SecureHandle h session) n = liftTLS session $ do pending <- TLS.checkPending let wait = void $ IO.hWaitForInput h (- 1) when (pending == 0) (liftIO wait) - lazy <- TLS.getBytes n - return (Data.ByteString.concat (Data.ByteString.Lazy.toChunks lazy)) + Data.ByteString.concat . Data.ByteString.Lazy.toChunks <$> getBytes + where + getBytes = TLS.getBytes n `E.catchError` handleGetBytesErr + handleGetBytesErr (TLS.Error (-28)) = getBytes + handleGetBytesErr e = E.throwError e handleIsSecure :: Handle -> Bool handleIsSecure PlainHandle{} = False -- 2.45.2