~singpolyma/network-protocol-xmpp

507375d377bd6053b91955744de0736d63f082c2 — John Millikin 12 years ago 8aaab57
Better error handling for unexpected EOF in 'hGetChar'.
1 files changed, 11 insertions(+), 8 deletions(-)

M Network/Protocol/XMPP/Handle.hs
M Network/Protocol/XMPP/Handle.hs => Network/Protocol/XMPP/Handle.hs +11 -8
@@ 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"