Readline for Sockets not guaranteed to actually read a line

Gerhard R. gerd.r.devel at googlemail.com
Mon Mar 11 20:45:01 UTC 2013


This is the mail I received by whiteknight, which I assume he just
forgot to address to parrot-dev:

On Sun, Mar 10, 2013 at 11:01 PM, Andrew Whitworth wrote:
> That decision, along with several other decisions made in the IO
> rewrite stem from my own personal preferences and a few test cases. If
> my preferences don't match what other developers think parrot should
> do, please feel free to correct it.
>
> There is a very real case that a line of text may be sent without a
> trailing newline. Several of our tests for FileHandle.readline test
> this very thing (the last line in a file that isn't terminated with a
> newline, etc). In those cases, Socket.readline would be looking for a
> newline character and would hang forever not finding it. Without a
> better system for specifying and handling timeouts, it seemed to me
> like the best thing to do was not wait forever on an input buffer
> which is never going to be filled.
>
> Please don't hesitate to replace my code with something better.
>
> Thanks,
>
> --Andrew Whitworth

The problem is that if you did not receive the line terminator, it's
impossible to decide if what you just got is a whole line or just the
first part of one.

The current codebase only tries one read and bails out early if no
terminator has been seen yet. This means that long lines that don't
arrive in a single chunk (my test case was a 500 bytes long string)
will be split, and we need to duplicate logic that's already in Parrot
at a higher layer if we want lines to arrive at the receiving end the
same way they were sent.

I attempted just that in my Rakudo pull request, but messed up an edge
case (multi-character line terminator split across multiple chunks).

Imo the best approach for now would be to just remove the early bail
out and work on providing an explicit timeout parameter at a later
date. If we keep the status quo, I'll be forced to fix my Rakudo-side
changes, which will become obsolete once the Parrot gets its act
together.

-- gerdr

PS at whiteknight: if you have the time, could you please read through my
changes to io_readline_encoded_string() -
https://github.com/gerdr/parrot/blob/3c59862dec40205cde331b8c302eae4df4f47103/src/io/utilities.c#L410
- and see if they make sense?


More information about the parrot-dev mailing list