You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
The docs for connectionGetLine are reproduced here:
--| Get the next line, using ASCII LF as the line terminator.---- This throws an 'isEOFError' exception on end of input, and LineTooLong when-- the number of bytes gathered is over the limit without a line terminator.---- The actual line returned can be bigger than the limit specified, provided-- that the last chunk returned by the underlaying backend contains a LF.-- In another world only when we need more input and limit is reached that the-- LineTooLong exception will be raised.---- An end of file will be considered as a line terminator too, if line is-- not empty.
When I read this initially, I was confused about what happens if the input ends. Reading the source, I see that there's an throwEOF conn loc that is passed to more, but this is never actually called. Instead, the throwEOF invocation that could happen here happens from connectionGetChunkBase, which occurs when the connectionBuffer connMVar value is a Nothing. The comment on that field says:
, connectionBuffer ::MVar (MaybeByteString) --^ this is set to 'Nothing' on EOF
If that's Just, then we check if it is empty. If it is, then we try to get more data. If it's still empty after getting more data, we close the connection and return f applied to the empty bytestring. If it's got more data, then you update the buffer with the remainder.
So, as far as I can tell:
If Connection is already done (eg hit EOF), then connectionGetLine throws an EOF error.
If Connection encounters an EOF condition (no more bytes from upstream, even after requesting more) then it returns the ByteString as if it found a \n and closes the MVar.
If Connection encounters a \n it returns the bytestring accumulated so far.
If Connection gets too many bytes then it throws the line error.
I'll try to come up with a patch to make the docs easier to understand and maybe remove the unused throwEOF parameter to more.
The text was updated successfully, but these errors were encountered:
The docs for
connectionGetLine
are reproduced here:When I read this initially, I was confused about what happens if the input ends. Reading the source, I see that there's an
throwEOF conn loc
that is passed tomore
, but this is never actually called. Instead, thethrowEOF
invocation that could happen here happens fromconnectionGetChunkBase
, which occurs when theconnectionBuffer conn
MVar
value is aNothing
. The comment on that field says:If that's
Just
, then we check if it is empty. If it is, then we try to get more data. If it's still empty after getting more data, we close the connection and returnf
applied to the empty bytestring. If it's got more data, then you update the buffer with the remainder.So, as far as I can tell:
Connection
is already done (eg hit EOF), thenconnectionGetLine
throws anEOF
error.Connection
encounters anEOF
condition (no more bytes from upstream, even after requesting more) then it returns theByteString
as if it found a\n
and closes theMVar
.Connection
encounters a\n
it returns the bytestring accumulated so far.Connection
gets too many bytes then it throws the line error.I'll try to come up with a patch to make the docs easier to understand and maybe remove the unused
throwEOF
parameter tomore
.The text was updated successfully, but these errors were encountered: