if (send_length +instance->write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
{
- memcached_io_write(instance, NULL, 0, true);
+ memcached_io_write(instance);
}
}
if (cmd_size +instance->write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
{
- memcached_io_write(instance, NULL, 0, true);
+ memcached_io_write(instance);
}
}
**/
if (memcached_is_udp(ptr->root) and with_flush and ptr->write_buffer_offset > UDP_DATAGRAM_HEADER_LENGTH)
{
- if (memcached_io_write(ptr, NULL, 0, true) == -1)
+ if (memcached_io_write(ptr) == false)
{
memcached_io_reset(ptr);
return memcached_set_error(*ptr, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT);
return ret;
}
- if (memcached_io_write(instance, NULL, 0, true) == -1)
+ if (memcached_io_write(instance) == false)
{
ret= MEMCACHED_SOME_ERRORS;
}
if (ptr->flags.no_block)
{
- (void)memcached_io_write(instance, NULL, 0, true);
+ memcached_io_write(instance);
}
while(memcached_server_response_count(instance))
+ {
(void)memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->result);
+ }
}
}
for (uint32_t x= 0; x < memcached_server_count(ptr); ++x)
{
- memcached_server_write_instance_st instance=
- memcached_server_instance_fetch(ptr, x);
+ memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
if (memcached_server_response_count(instance))
{
- if (memcached_io_write(instance, NULL, 0, true) == -1)
+ if (memcached_io_write(instance) == false)
{
memcached_server_response_reset(instance);
memcached_io_reset(instance);
static bool io_flush(memcached_server_write_instance_st ptr,
const bool with_flush,
- memcached_return_t *error)
+ memcached_return_t& error)
{
/*
** We might want to purge the input buffer if we haven't consumed
return false;
}
}
- size_t return_length;
char *local_write_ptr= ptr->write_buffer;
size_t write_length= ptr->write_buffer_offset;
- *error= MEMCACHED_SUCCESS;
+ error= MEMCACHED_SUCCESS;
WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET);
// UDP Sanity check, make sure that we are not sending somthing too big
if (memcached_is_udp(ptr->root) and write_length > MAX_UDP_DATAGRAM_LENGTH)
{
- *error= MEMCACHED_WRITE_FAILURE;
+ error= memcached_set_error(*ptr, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT);
return false;
}
WATCHPOINT_ASSERT((ptr->write_buffer + MEMCACHED_MAX_BUFFER) >= (local_write_ptr + write_length));
#endif
- return_length= 0;
while (write_length)
{
WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET);
}
else if (rc == MEMCACHED_TIMEOUT)
{
- *error= memcached_set_error(*ptr, MEMCACHED_TIMEOUT, MEMCACHED_AT);
+ error= memcached_set_error(*ptr, MEMCACHED_TIMEOUT, MEMCACHED_AT);
return false;
}
memcached_quit_server(ptr, true);
- *error= memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT);
+ error= memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT);
return false;
}
case ENOTCONN:
case EPIPE:
default:
memcached_quit_server(ptr, true);
- *error= memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT);
+ error= memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT);
WATCHPOINT_ASSERT(ptr->fd == INVALID_SOCKET);
return false;
}
if (memcached_is_udp(ptr->root) and size_t(sent_length) != write_length)
{
memcached_quit_server(ptr, true);
- *error= memcached_set_error(*ptr, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT);
+ error= memcached_set_error(*ptr, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT);
return false;
}
local_write_ptr+= sent_length;
write_length-= uint32_t(sent_length);
- return_length+= uint32_t(sent_length);
}
WATCHPOINT_ASSERT(write_length == 0);
- // Need to study this assert() WATCHPOINT_ASSERT(return_length ==
- // ptr->write_buffer_offset);
-
- // if we are a udp server, the begining of the buffer is reserverd for
- // the upd frame header
if (memcached_is_udp(ptr->root))
{
ptr->write_buffer_offset= UDP_DATAGRAM_HEADER_LENGTH;
WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET);
memcached_return_t rc;
- if (io_flush(ptr, with_flush, &rc) == false)
+ if (io_flush(ptr, with_flush, rc) == false)
{
return -1;
}
{
memcached_return_t rc;
WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET);
- if (io_flush(ptr, with_flush, &rc) == false)
+ if (io_flush(ptr, with_flush, rc) == false)
{
return -1;
}
return (ssize_t) original_length;
}
+bool memcached_io_write(memcached_server_write_instance_st ptr)
+{
+ return (_io_write(ptr, NULL, 0, true) >= 0);
+}
+
ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
- const void *buffer, size_t length, bool with_flush)
+ const void *buffer, const size_t length, const bool with_flush)
{
return _io_write(ptr, buffer, length, with_flush);
}
if (with_flush)
{
- if (memcached_io_write(ptr, NULL, 0, true) == -1)
+ if (memcached_io_write(ptr) == false)
{
return -1;
}
for (uint32_t x= 0; x < memcached_server_count(memc) && host_index < MAX_SERVERS_TO_POLL; ++x)
{
- memcached_server_write_instance_st instance=
- memcached_server_instance_fetch(memc, x);
+ memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, x);
if (instance->read_buffer_length > 0) /* I have data in the buffer */
+ {
return instance;
+ }
if (memcached_server_response_count(instance) > 0)
{
const void *buffer;
size_t length;
};
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-LIBMEMCACHED_LOCAL
-ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
- const void *buffer, size_t length, bool with_flush);
-
-LIBMEMCACHED_LOCAL
-ssize_t memcached_io_writev(memcached_server_write_instance_st ptr,
- const struct libmemcached_io_vector_st *vector,
- size_t number_of, bool with_flush);
-
-#ifdef __cplusplus
-}
-#endif
-
-#ifdef __cplusplus
-
-size_t io_vector_total_size(libmemcached_io_vector_st* vector, const size_t number_of);
-
-#endif
#pragma once
-LIBMEMCACHED_LOCAL
+size_t io_vector_total_size(libmemcached_io_vector_st* vector, const size_t number_of);
+
+bool memcached_io_write(memcached_server_write_instance_st ptr);
+
+ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
+ const void *buffer, size_t length, bool with_flush);
+
+ssize_t memcached_io_writev(memcached_server_write_instance_st ptr,
+ const struct libmemcached_io_vector_st *vector,
+ size_t number_of, bool with_flush);
+
memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr);
-LIBMEMCACHED_LOCAL
void memcached_io_reset(memcached_server_write_instance_st ptr);
-LIBMEMCACHED_LOCAL
memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr,
void *buffer, size_t length, ssize_t *nread);
/* Read a line (terminated by '\n') into the buffer */
-LIBMEMCACHED_LOCAL
memcached_return_t memcached_io_readline(memcached_server_write_instance_st ptr,
char *buffer_ptr,
size_t size,
size_t& total);
-LIBMEMCACHED_LOCAL
void memcached_io_close(memcached_server_write_instance_st ptr);
/* Read n bytes of data from the server and store them in dta */
-LIBMEMCACHED_LOCAL
memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr,
void *dta,
size_t size);
-LIBMEMCACHED_LOCAL
memcached_return_t memcached_io_init_udp_header(memcached_server_write_instance_st ptr,
uint16_t thread_id);
-LIBMEMCACHED_LOCAL
memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st *memc);
-LIBMEMCACHED_LOCAL
memcached_return_t memcached_io_slurp(memcached_server_write_instance_st ptr);
return MEMCACHED_SUCCESS;
}
- /* memcached_io_write and memcached_response may call memcached_purge
- so we need to be able stop any recursion.. */
+ /*
+ memcached_io_write and memcached_response may call memcached_purge
+ so we need to be able stop any recursion..
+ */
memcached_set_purging(root, true);
WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET);
- /* Force a flush of the buffer to ensure that we don't have the n-1 pending
- requests buffered up.. */
- if (memcached_io_write(ptr, NULL, 0, true) == -1)
+ /*
+ Force a flush of the buffer to ensure that we don't have the n-1 pending
+ requests buffered up..
+ */
+ if (memcached_io_write(ptr) == false)
{
memcached_set_purging(root, true);
/* We may have old commands in the buffer not set, first purge */
if ((ptr->root->flags.no_block) && (memcached_is_processing_input(ptr->root) == false))
{
- (void)memcached_io_write(ptr, NULL, 0, true);
+ (void)memcached_io_write(ptr);
}
/*
}
if (cmd_size + server->write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
{
- memcached_io_write(server, NULL, 0, true);
+ memcached_io_write(server);
}
}
if (cmd_size + instance->write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
{
- memcached_io_write(instance, NULL, 0, true);
+ memcached_io_write(instance);
}
}