~singpolyma/network-protocol-xmpp

3f30f380adb4c6eedf3c919590359c9746f5d8b3 — Stephen Paul Weber 4 months ago 25deb6c master
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.
1 files changed, 5 insertions(+), 2 deletions(-)

M lib/Network/Protocol/XMPP/Handle.hs
M lib/Network/Protocol/XMPP/Handle.hs => lib/Network/Protocol/XMPP/Handle.hs +5 -2
@@ 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