Skip to content

Commit

Permalink
Revert "Merge pull request #943 from gerdr/fix-socket-readline"
Browse files Browse the repository at this point in the history
This reverts commit fb2e957, reversing
changes made to 83bb863.

This is needed for the duration of the 5.2.0 release process, because the
branch was merged prematurely, and causes test failures. When the branch is
in a completed state, and ready to merge, it is important that a
"revert-the-revert" is performed just before the merge:
    git revert ID-of-*this*-revert
For rationale, see:
https://www.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.txt
  • Loading branch information
Util committed Mar 24, 2013
1 parent a3c2754 commit 5120d02
Showing 1 changed file with 15 additions and 36 deletions.
51 changes: 15 additions & 36 deletions src/io/utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,6 @@ io_read_encoded_string(PARROT_INTERP, ARGMOD(PMC *handle),
/* When we have a request with PIO_READ_SIZE_ANY, we just want a big chunk
of data. Fill the buffer up as full as it gets and read it out. */
if (char_length == PIO_READ_SIZE_ANY) {
/* FIXME: see io_readline_encoded_string() why checking against
encoding->max_bytes_per_codepoint is a bad idea
*/
if (BUFFER_USED_SIZE(buffer) < encoding->max_bytes_per_codepoint)
Parrot_io_buffer_fill(interp, buffer, handle, vtable);
bytes_to_read = io_buffer_find_num_characters(interp, buffer,
Expand Down Expand Up @@ -416,62 +413,44 @@ io_readline_encoded_string(PARROT_INTERP, ARGMOD(PMC *handle),
size_t total_bytes_read = 0;
const size_t raw_reads = buffer->raw_reads;
size_t available_bytes = BUFFER_USED_SIZE(buffer);
size_t prev_available_bytes = 0;
const size_t delim_size = STRING_byte_length(rs);
INTVAL have_delim = 0;

s->bufused = 0;
s->strlen = 0;

if (encoding == NULL)
encoding = io_get_encoding(interp, handle, vtable, PIO_F_READ);

if (available_bytes < delim_size || available_bytes < encoding->max_bytes_per_codepoint)
available_bytes = Parrot_io_buffer_fill(interp, buffer, handle, vtable);

s->encoding = encoding;

while (!have_delim) {
while (1) {
Parrot_String_Bounds bounds;
size_t bytes_to_read;

/* We used to check against encoding->max_bytes_per_codepoint
instead of encoding->bytes_per_unit.
In case of variable-length codings like UTF-8, this meant waiting
for more characters even if we already got all expected data and
possibly hanging indefinitely if there's no more input available.
FIXME: available_bytes < delim_size only makes sense if the
encodings agree
*/
if (available_bytes < delim_size || available_bytes < encoding->bytes_per_unit) {
prev_available_bytes = available_bytes;
available_bytes = Parrot_io_buffer_fill(interp, buffer, handle, vtable);
}

bytes_to_read = io_buffer_find_string_marker(interp, buffer, handle,
vtable, encoding, &bounds, rs, &have_delim);
INTVAL have_delim = 0;
const size_t bytes_to_read = io_buffer_find_string_marker(interp,
buffer, handle, vtable, encoding, &bounds, rs, &have_delim);

/* Check if the buffer contains no (full) characters.
If the last read returned nothing, assume we're at EOF and
break out of the loop.
This used to check bytes_to_read == 0 only. In case of
variable-length codings, the buffer may now contain a single
partial character after a successful read, whereas it used to
contain at least one full character.
*/
if (bytes_to_read == 0 && prev_available_bytes == available_bytes)
/* Buffer is empty, so we're probably at EOF. */
if (bytes_to_read == 0)
break;

/* Append buffer to result */
io_read_chars_append_string(interp, s, handle, vtable, buffer, bytes_to_read);
total_bytes_read += bytes_to_read;
available_bytes -= bytes_to_read;

if (have_delim)
break;

/* Some types, like Socket, don't want to be read more than once in a
single request because recv can hang waiting for data. In those
cases, break out of the loop early. */
if ((vtable->flags & PIO_VF_MULTI_READABLE) == 0 && buffer->raw_reads > raw_reads)
break;
available_bytes -= bytes_to_read;
if (available_bytes < delim_size || available_bytes < encoding->max_bytes_per_codepoint)
available_bytes = Parrot_io_buffer_fill(interp, buffer, handle, vtable);
}

if (total_bytes_read == 0)
Expand Down

0 comments on commit 5120d02

Please sign in to comment.