Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace raw_reads from IO_BUFFER with PIO_BF_UNDERFLOW flag

  • Loading branch information...
commit ab3776eebdab159e531108ec2335cee22003a06d 1 parent 7fac981
@gerdr authored
Showing with 19 additions and 12 deletions.
  1. +5 −5 include/parrot/io.h
  2. +12 −5 src/io/buffer.c
  3. +2 −2 src/io/utilities.c
View
10 include/parrot/io.h
@@ -32,10 +32,11 @@
#endif
/* Buffer flags */
-#define PIO_BF_MALLOC 0x0001 /* Buffer malloced */
-#define PIO_BF_MMAP 0x0002 /* Buffer mmap()ed */
-#define PIO_BF_LINEBUF 0x0004 /* Flushes on newline */
-#define PIO_BF_BLKBUF 0x0008 /* Raw block-based buffering */
+#define PIO_BF_MALLOC 0x0001 /* Buffer malloced */
+#define PIO_BF_MMAP 0x0002 /* Buffer mmap()ed */
+#define PIO_BF_LINEBUF 0x0004 /* Flushes on newline */
+#define PIO_BF_BLKBUF 0x0008 /* Raw block-based buffering */
+#define PIO_BF_UNDERFLOW 0x0010 /* Buffer failed to fill */
/* TODO: What is this? Figure it out and properly document it's use. */
#define PIO_NR_OPEN 256 /* Size of an "IO handle table" */
@@ -113,7 +114,6 @@ typedef struct _ParrotIOData ParrotIOData;
/* BUFFERING */
typedef struct _io_buffer {
INTVAL flags; /* Flags on this buffer */
- size_t raw_reads; /* Number of raw reads */
size_t buffer_size; /* Current allocated size */
const STR_VTABLE *encoding; /* Encoding used by this buffer */
char *buffer_ptr; /* ptr to the buffer mem block */
View
17 src/io/buffer.c
@@ -117,8 +117,6 @@ Parrot_io_buffer_allocate(PARROT_INTERP, ARGMOD(PMC *owner), INTVAL flags,
buffer->buffer_end = buffer->buffer_ptr;
PARROT_ASSERT(BUFFER_IS_EMPTY(buffer));
- buffer->raw_reads = 0;
-
buffer->flags = flags;
return buffer;
}
@@ -293,8 +291,12 @@ Parrot_io_buffer_read_b(PARROT_INTERP, ARGMOD_NULLOK(IO_BUFFER *buffer),
size_t length)
{
ASSERT_ARGS(Parrot_io_buffer_read_b)
+ if(length == 0)
+ return 0;
+
if (!buffer)
return vtable->read_b(interp, handle, s, length);
+
{
size_t bytes_read = io_buffer_transfer_to_mem(interp, buffer, s, length);
PARROT_ASSERT(bytes_read <= length);
@@ -305,8 +307,11 @@ Parrot_io_buffer_read_b(PARROT_INTERP, ARGMOD_NULLOK(IO_BUFFER *buffer),
/* If we still need more data than the buffer can hold, just read it
directly. */
if (length > buffer->buffer_size) {
- bytes_read += vtable->read_b(interp, handle, s + bytes_read, length);
- buffer->raw_reads++;
+ const size_t count = vtable->read_b(interp, handle, s + bytes_read,
+ length);
+ bytes_read += count;
+ if (count == 0)
+ buffer->flags |= PIO_BF_UNDERFLOW;
}
/* Else, if we need to read an amount that the buffer can handle, fill
@@ -617,7 +622,9 @@ Parrot_io_buffer_fill(PARROT_INTERP, ARGMOD_NULLOK(IO_BUFFER *buffer),
return BUFFER_USED_SIZE(buffer);
read_bytes = vtable->read_b(interp, handle, buffer->buffer_end,
available_size);
- buffer->raw_reads++;
+ if (read_bytes == 0)
+ buffer->flags |= PIO_BF_UNDERFLOW;
+
buffer->buffer_end += read_bytes;
BUFFER_ASSERT_SANITY(buffer);
return BUFFER_USED_SIZE(buffer);
View
4 src/io/utilities.c
@@ -278,7 +278,6 @@ io_read_encoded_string(PARROT_INTERP, ARGMOD(PMC *handle),
{
ASSERT_ARGS(io_read_encoded_string)
STRING * const s = Parrot_gc_new_string_header(interp, 0);
- const size_t raw_reads = buffer->raw_reads;
size_t total_bytes_read = 0;
Parrot_String_Bounds bounds;
size_t bytes_to_read = 0;
@@ -333,8 +332,9 @@ io_read_encoded_string(PARROT_INTERP, ARGMOD(PMC *handle),
/* 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. */
+/* FIXME - buffer-raw_reads is gone
if ((vtable->flags & PIO_VF_MULTI_READABLE) == 0 && buffer->raw_reads > raw_reads)
- break;
+ break; */
}
return s;
Please sign in to comment.
Something went wrong with that request. Please try again.