}
#endif
-ssize_t memcached_io_read(memcached_server_st *ptr,
- void *buffer, size_t length)
+memcached_return memcached_io_read(memcached_server_st *ptr,
+ void *buffer, size_t length, ssize_t *nread)
{
char *buffer_ptr;
while (1)
{
- data_read= read(ptr->fd,
- ptr->read_buffer,
- MEMCACHED_MAX_BUFFER);
+ data_read= read(ptr->fd, ptr->read_buffer, MEMCACHED_MAX_BUFFER);
if (data_read > 0)
break;
else if (data_read == -1)
{
ptr->cached_errno= errno;
+ memcached_return rc= MEMCACHED_UNKNOWN_READ_FAILURE;
switch (errno)
{
case EAGAIN:
case EINTR:
- if (io_wait(ptr, MEM_READ) == MEMCACHED_SUCCESS)
+ if ((rc= io_wait(ptr, MEM_READ)) == MEMCACHED_SUCCESS)
continue;
/* fall through */
default:
{
memcached_quit_server(ptr, 1);
- return -1;
+ *nread= -1;
+ return rc;
}
}
}
it will return EGAIN if data is not immediatly available.
*/
memcached_quit_server(ptr, 1);
- return -1;
+ *nread= -1;
+ return MEMCACHED_UNKNOWN_READ_FAILURE;
}
}
}
ptr->server_failure_counter= 0;
- return (size_t)(buffer_ptr - (char*)buffer);
+ *nread = (size_t)(buffer_ptr - (char*)buffer);
+ return MEMCACHED_SUCCESS;
}
ssize_t memcached_io_write(memcached_server_st *ptr,
while (offset < size)
{
- ssize_t nread= memcached_io_read(ptr, data + offset, size - offset);
- if (nread <= 0)
- {
- memcached_io_reset(ptr);
- return MEMCACHED_UNKNOWN_READ_FAILURE;
- }
+ ssize_t nread;
+ memcached_return rc= memcached_io_read(ptr, data + offset, size - offset,
+ &nread);
+ if (rc != MEMCACHED_SUCCESS)
+ return rc;
+
offset+= nread;
}
* 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;
+ ssize_t nread;
+ memcached_return rc= memcached_io_read(ptr, buffer_ptr, 1, &nread);
+ if (rc != MEMCACHED_SUCCESS)
+ return rc;
if (*buffer_ptr == '\n')
line_complete= true;
ssize_t memcached_io_write(memcached_server_st *ptr,
const void *buffer, size_t length, char with_flush);
void memcached_io_reset(memcached_server_st *ptr);
-ssize_t memcached_io_read(memcached_server_st *ptr,
- void *buffer, size_t length);
+memcached_return memcached_io_read(memcached_server_st *ptr,
+ void *buffer, size_t length, ssize_t *nread);
/* Read a line (terminated by '\n') into the buffer */
memcached_return memcached_io_readline(memcached_server_st *ptr,
char *buffer_ptr,
if (io_death == 0 && ptr->type != MEMCACHED_CONNECTION_UDP)
{
memcached_return rc;
- ssize_t read_length;
char buffer[MEMCACHED_MAX_BUFFER];
if (ptr->root->flags & MEM_BINARY_PROTOCOL)
* results in server throwing away all data which is
* not read
*/
- while ((read_length=
- memcached_io_read(ptr, buffer, sizeof(buffer)/sizeof(*buffer)))
- > 0);
+ ssize_t nread;
+ while (memcached_io_read(ptr, buffer, sizeof(buffer)/sizeof(*buffer),
+ &nread) == MEMCACHED_SUCCESS);
}
memcached_io_close(ptr);
char *end_ptr;
char *next_ptr;
size_t value_length;
- size_t read_length;
size_t to_read;
char *value_ptr;
}
value_ptr= memcached_string_value(&result->value);
- read_length= 0;
/*
We read the \r\n into the string since not doing so is more
cycles then the waster of memory to do so.
some people lazy about using the return length.
*/
to_read= (value_length) + 2;
- read_length= memcached_io_read(ptr, value_ptr, to_read);
+ ssize_t read_length= 0;
+ memcached_return rrc= memcached_io_read(ptr, value_ptr, to_read, &read_length);
+ if (rrc != MEMCACHED_SUCCESS)
+ return rrc;
+
if (read_length != (size_t)(value_length + 2))
{
goto read_error;
{
rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0);
- assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_WRITE_FAILURE || rc == MEMCACHED_BUFFERED);
+ assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_WRITE_FAILURE ||
+ rc == MEMCACHED_BUFFERED || rc == MEMCACHED_TIMEOUT);
- if (rc == MEMCACHED_WRITE_FAILURE)
+ if (rc == MEMCACHED_WRITE_FAILURE || rc == MEMCACHED_TIMEOUT)
x--;
}