struct __write_vector_st vector[]=
{
+ { .length= sizeof(request.bytes), .buffer= request.bytes },
{ .length= ptr->prefix_key_length, .buffer= ptr->prefix_key },
{ .length= key_length, .buffer= key }
};
memcached_return_t rc;
- if (((rc= memcached_do(instance, request.bytes, sizeof(request.bytes), false)) != MEMCACHED_SUCCESS) ||
- (memcached_io_writev(instance, vector, 2, true) == -1))
+ if ((rc= memcached_vdo(instance, vector, 3, true)) != MEMCACHED_SUCCESS)
{
memcached_io_reset(instance);
return (rc == MEMCACHED_SUCCESS) ? MEMCACHED_WRITE_FAILURE : rc;
memcached_server_write_instance_st memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key);
/* These are private not to be installed headers */
-#include "libmemcached/do.h"
#include "libmemcached/io.h"
+#include "libmemcached/do.h"
#include "libmemcached/internal.h"
#include "libmemcached/libmemcached_probes.h"
#include "libmemcached/memcached/protocol_binary.h"
}
}
else
- send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "delete %.*s%.*s%s\r\n",
- (int)ptr->prefix_key_length,
- ptr->prefix_key,
- (int)key_length, key, no_reply ? " noreply" :"");
+ {
+ send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
+ "delete %.*s%.*s%s\r\n",
+ (int)ptr->prefix_key_length,
+ ptr->prefix_key,
+ (int)key_length, key, no_reply ? " noreply" :"");
+ }
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
{
struct __write_vector_st vector[]=
{
+ { .length= sizeof(request.bytes), .buffer= request.bytes},
{ .length= ptr->prefix_key_length, .buffer= ptr->prefix_key },
{ .length= key_length, .buffer= key },
};
memcached_return_t rc= MEMCACHED_SUCCESS;
- if (((rc= memcached_do(instance, request.bytes, sizeof(request.bytes), false)) != MEMCACHED_SUCCESS) ||
- (memcached_io_writev(instance, vector, 2, flush) == -1))
+ if ((rc= memcached_vdo(instance, vector, 3, flush)) != MEMCACHED_SUCCESS)
{
memcached_io_reset(instance);
rc= (rc == MEMCACHED_SUCCESS) ? MEMCACHED_WRITE_FAILURE : rc;
replica= memcached_server_instance_fetch(ptr, server_key);
- if ((memcached_do(replica, (const char*)request.bytes, sizeof(request.bytes), false) != MEMCACHED_SUCCESS) ||
- (memcached_io_write(replica, key, key_length, flush) == -1))
+ if (memcached_vdo(replica, vector, 3, flush) != MEMCACHED_SUCCESS)
{
memcached_io_reset(replica);
}
sent_length= memcached_io_write(ptr, command, command_length, with_flush);
if (sent_length == -1 || (size_t)sent_length != command_length)
+ {
rc= MEMCACHED_WRITE_FAILURE;
+ }
else if ((ptr->root->flags.no_reply) == 0)
+ {
memcached_server_response_increment(ptr);
+ }
+
+ return rc;
+}
+
+memcached_return_t memcached_vdo(memcached_server_write_instance_st ptr,
+ const struct __write_vector_st *vector, size_t count,
+ bool with_flush)
+{
+ memcached_return_t rc;
+ ssize_t sent_length;
+
+ WATCHPOINT_ASSERT(command_length);
+ WATCHPOINT_ASSERT(command);
+
+ if ((rc= memcached_connect(ptr)) != MEMCACHED_SUCCESS)
+ {
+ WATCHPOINT_ERROR(rc);
+ return rc;
+ }
+
+ /*
+ ** Since non buffering ops in UDP mode dont check to make sure they will fit
+ ** before they start writing, if there is any data in buffer, clear it out,
+ ** otherwise we might get a partial write.
+ **/
+ if (ptr->type == MEMCACHED_CONNECTION_UDP && with_flush && ptr->write_buffer_offset > UDP_DATAGRAM_HEADER_LENGTH)
+ {
+ memcached_io_write(ptr, NULL, 0, true);
+ }
+
+ sent_length= memcached_io_writev(ptr, vector, count, with_flush);
+
+ size_t command_length= 0;
+ for (uint32_t x= 0; x < count; ++x, vector++)
+ {
+ command_length+= vector->length;
+ }
+
+ if (sent_length == -1 || (size_t)sent_length != command_length)
+ {
+ rc= MEMCACHED_WRITE_FAILURE;
+ }
+ else if ((ptr->root->flags.no_reply) == 0)
+ {
+ memcached_server_response_increment(ptr);
+ }
return rc;
}
size_t command_length,
bool with_flush);
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_vdo(memcached_server_write_instance_st ptr,
+ const struct __write_vector_st *vector, size_t count,
+ bool with_flush);
+
#ifdef __cplusplus
}
#endif
static memcached_return_t memcached_flush_binary(memcached_st *ptr,
time_t expiration)
{
- uint32_t x;
protocol_binary_request_flush request= {.bytes= {0}};
unlikely (memcached_server_count(ptr) == 0)
request.message.header.request.bodylen= htonl(request.message.header.request.extlen);
request.message.body.expiration= htonl((uint32_t) expiration);
- for (x= 0; x < memcached_server_count(ptr); x++)
+ for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
memcached_server_write_instance_st instance=
memcached_server_instance_fetch(ptr, x);
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_FLUSH;
}
- if (memcached_do(instance, request.bytes,
- sizeof(request.bytes), true) != MEMCACHED_SUCCESS)
+ if (memcached_do(instance, request.bytes, sizeof(request.bytes), true) != MEMCACHED_SUCCESS)
{
memcached_io_reset(instance);
return MEMCACHED_WRITE_FAILURE;
}
}
- for (x= 0; x < memcached_server_count(ptr); x++)
+ for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
memcached_server_write_instance_st instance=
memcached_server_instance_fetch(ptr, x);
}
else
{
- rc= memcached_do(ptr, "quit\r\n", sizeof("quit\r\n"), true);
+ rc= memcached_do(ptr, "quit\r\n", strlen("quit\r\n"), true);
}
WATCHPOINT_ASSERT(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_FETCH_NOTFINISHED);
request.message.header.request.keylen= htons((uint16_t)len);
request.message.header.request.bodylen= htonl((uint32_t) len);
- if ((memcached_do(instance, request.bytes,
- sizeof(request.bytes), false) != MEMCACHED_SUCCESS) ||
- (memcached_io_write(instance, args, len, true) == -1))
+ struct __write_vector_st vector[]=
+ {
+ { .length= sizeof(request.bytes), .buffer= request.bytes },
+ { .length= len, .buffer= args }
+ };
+
+ if (memcached_vdo(instance, vector, 2, true) != MEMCACHED_SUCCESS)
{
memcached_io_reset(instance);
return MEMCACHED_WRITE_FAILURE;
memcached_server_response_decrement(instance);
do
{
- rc= memcached_response(instance, buffer,
- sizeof(buffer), NULL);
+ rc= memcached_response(instance, buffer, sizeof(buffer), NULL);
+
if (rc == MEMCACHED_END)
break;
goto error;
}
- /* Send command header */
- rc= memcached_do(instance, buffer, write_length, false);
- if (rc != MEMCACHED_SUCCESS)
- goto error;
+
+ struct __write_vector_st vector[]=
+ {
+ { .length= write_length, .buffer= buffer },
+ { .length= value_length, .buffer= value },
+ { .length= 2, .buffer= "\r\n" }
+ };
if (ptr->flags.buffer_requests && verb == SET_OP)
{
to_write= true;
}
- struct __write_vector_st vector[]=
- {
- { .length= value_length, .buffer= value },
- { .length= 2, .buffer= "\r\n" }
- };
-
- if (memcached_io_writev(instance, vector, 2, to_write) == -1)
+ /* Send command header */
+ rc= memcached_vdo(instance, vector, 3, to_write);
+ if (rc == MEMCACHED_SUCCESS)
{
- rc= MEMCACHED_WRITE_FAILURE;
- goto error;
- }
if (ptr->flags.no_reply)
return (to_write == false) ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS;
return MEMCACHED_SUCCESS;
else
return rc;
+ }
error:
+
memcached_io_reset(instance);
return rc;
struct __write_vector_st vector[]=
{
+ { .length= send_length, .buffer= request.bytes },
{ .length= ptr->prefix_key_length, .buffer= ptr->prefix_key },
{ .length= key_length, .buffer= key },
{ .length= value_length, .buffer= value }
/* write the header */
memcached_return_t rc;
- if (((rc= memcached_do(server, (const char*)request.bytes, send_length, false)) != MEMCACHED_SUCCESS) ||
- (memcached_io_writev(server, vector, 3, flush) == -1))
+ if ((rc= memcached_vdo(server, vector, 4, flush)) != MEMCACHED_SUCCESS)
{
memcached_io_reset(server);
return (rc == MEMCACHED_SUCCESS) ? MEMCACHED_WRITE_FAILURE : rc;
instance= memcached_server_instance_fetch(ptr, server_key);
- if ((memcached_do(instance, (const char*)request.bytes, send_length, false) != MEMCACHED_SUCCESS) ||
- (memcached_io_writev(instance, vector, 3, flush) == -1))
+ if (memcached_vdo(instance, vector, 4, false) != MEMCACHED_SUCCESS)
{
memcached_io_reset(instance);
}
memcached_return_t memcached_verbosity(memcached_st *ptr, uint32_t verbosity)
{
- uint32_t x;
size_t send_length;
memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
return MEMCACHED_WRITE_FAILURE;
rc= MEMCACHED_SUCCESS;
- for (x= 0; x < memcached_server_count(ptr); x++)
+ for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
memcached_return_t rrc;
memcached_server_write_instance_st instance=
static inline memcached_return_t memcached_version_binary(memcached_st *ptr)
{
memcached_return_t rc;
- unsigned int x;
protocol_binary_request_version request= { .bytes= {0}};
request.message.header.request.magic= PROTOCOL_BINARY_REQ;
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_VERSION;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
rc= MEMCACHED_SUCCESS;
- for (x= 0; x < memcached_server_count(ptr); x++)
+ for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
memcached_return_t rrc;
}
}
- for (x= 0; x < memcached_server_count(ptr); x++)
+ for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
memcached_server_write_instance_st instance=
memcached_server_instance_fetch(ptr, x);