return MEMCACHED_SUCCESS;
}
+
+memcached_return memcached_io_readline(memcached_server_st *ptr,
+ char *buffer_ptr,
+ size_t size)
+{
+ bool line_complete= false;
+ int total_nr= 0;
+
+ while (!line_complete)
+ {
+ if (ptr->read_buffer_length == 0)
+ {
+ /*
+ * We don't have any data in the buffer, so let's fill the read
+ * buffer. Call the standard read function to avoid duplicating
+ * the logic.
+ */
+ if (memcached_io_read(ptr, buffer_ptr, 1) != 1)
+ return MEMCACHED_UNKNOWN_READ_FAILURE;
+
+ if (*buffer_ptr == '\n')
+ line_complete= true;
+
+ ++buffer_ptr;
+ ++total_nr;
+ }
+
+ /* Now let's look in the buffer and copy as we go! */
+ while (ptr->read_buffer_length && total_nr < size && !line_complete)
+ {
+ *buffer_ptr = *ptr->read_ptr;
+ if (*buffer_ptr == '\n')
+ line_complete = true;
+ --ptr->read_buffer_length;
+ ++ptr->read_ptr;
+ ++total_nr;
+ ++buffer_ptr;
+ }
+
+ if (total_nr == size)
+ return MEMCACHED_PROTOCOL_ERROR;
+ }
+
+ return MEMCACHED_SUCCESS;
+}
void memcached_io_reset(memcached_server_st *ptr);
ssize_t memcached_io_read(memcached_server_st *ptr,
void *buffer, size_t length);
+/* Read a line (terminated by '\n') into the buffer */
+memcached_return memcached_io_readline(memcached_server_st *ptr,
+ char *buffer_ptr,
+ size_t size);
memcached_return memcached_io_close(memcached_server_st *ptr);
/* Read n bytes of data from the server and store them in dta */
memcached_return memcached_safe_read(memcached_server_st *ptr,
return memcached_read_one_response(ptr, buffer, buffer_length, result);
}
-static memcached_return memcached_readline(memcached_server_st *ptr,
- char *buffer,
- size_t size)
-{
- bool line_complete= false;
- char *buffer_ptr= buffer;
- int total_nr=0;
-
- while (!line_complete)
- {
- if (memcached_io_read(ptr, buffer_ptr, 1) != 1)
- return MEMCACHED_UNKNOWN_READ_FAILURE;
-
- WATCHPOINT_ASSERT(*buffer_ptr != '\0');
- if (*buffer_ptr == '\n')
- line_complete=true;
- else
- {
- ++buffer_ptr;
- ++total_nr;
- }
-
- if (total_nr == size)
- return MEMCACHED_PROTOCOL_ERROR;
- }
-
- return MEMCACHED_SUCCESS;
-}
-
static memcached_return textual_read_one_response(memcached_server_st *ptr,
char *buffer, size_t buffer_length,
memcached_result_st *result)
{
- memcached_return rc=memcached_readline(ptr, buffer, buffer_length);
+ memcached_return rc= memcached_io_readline(ptr, buffer, buffer_length);
if (rc != MEMCACHED_SUCCESS)
return rc;