request.message.body.initial= htonll(initial);
request.message.body.expiration= htonl((uint32_t) expiration);
+ struct __write_vector_st vector[]=
+ {
+ { .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_write(instance, ptr->prefix_key, ptr->prefix_key_length, false) == -1) ||
- (memcached_io_write(instance, key, key_length, true) == -1))
+ (memcached_io_writev(instance, vector, 2, true) == -1))
{
memcached_io_reset(instance);
return (rc == MEMCACHED_SUCCESS) ? MEMCACHED_WRITE_FAILURE : rc;
goto error;
if (! to_write)
+ {
rc= MEMCACHED_BUFFERED;
+ }
else if (!no_reply)
{
rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
memcached_io_write(instance, NULL, 0, true);
}
+ struct __write_vector_st vector[]=
+ {
+ { .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_write(instance, ptr->prefix_key, ptr->prefix_key_length, false) == -1) ||
- (memcached_io_write(instance, key, key_length, flush) == -1))
+ (memcached_io_writev(instance, vector, 2, flush) == -1))
{
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) ||
+ if ((memcached_do(replica, (const char*)request.bytes, sizeof(request.bytes), false) != MEMCACHED_SUCCESS) ||
(memcached_io_write(replica, key, key_length, flush) == -1))
{
memcached_io_reset(replica);
WATCHPOINT_ASSERT(instance->cursor_active == 1);
}
- /* Only called when we have a prefix key */
- if (ptr->prefix_key_length)
- {
- if ((memcached_io_write(instance, ptr->prefix_key, ptr->prefix_key_length, false)) == -1)
- {
- memcached_server_response_reset(instance);
- rc= MEMCACHED_SOME_ERRORS;
- continue;
- }
- }
-
- if ((memcached_io_write(instance, keys[x], key_length[x], false)) == -1)
- {
- memcached_server_response_reset(instance);
- rc= MEMCACHED_SOME_ERRORS;
- continue;
- }
-
- if ((memcached_io_write(instance, " ", 1, false)) == -1)
+ struct __write_vector_st vector[]=
+ {
+ { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key },
+ { .length= key_length[x], .buffer= keys[x] },
+ { .length= 1, .buffer= " " }
+ };
+
+ if ((memcached_io_writev(instance, vector, 3, false)) == -1)
{
memcached_server_response_reset(instance);
rc= MEMCACHED_SOME_ERRORS;
* that we might have processed some of the responses etc. For now,
* just make sure we work _correctly_
*/
- if ((memcached_io_write(instance, request.bytes, sizeof(request.bytes), false) == -1) ||
- (memcached_io_write(instance, ptr->prefix_key, ptr->prefix_key_length, false) == -1) ||
- (memcached_io_write(instance, keys[x], key_length[x], true) == -1))
+ struct __write_vector_st vector[]=
+ {
+ { .length= sizeof(request.bytes), .buffer= request.bytes },
+ { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key },
+ { .length= key_length[x], .buffer= keys[x] }
+ };
+
+ if (memcached_io_writev(instance, vector, 3, true) == -1)
{
memcached_io_reset(instance);
dead_servers[server]= true;
return MEMCACHED_SUCCESS;
}
+ssize_t memcached_io_writev(memcached_server_write_instance_st ptr,
+ struct __write_vector_st *vector,
+ size_t number_of, bool with_flush)
+{
+ ssize_t total= 0;
+
+ for (size_t x= 0; x < number_of; x++, vector++)
+ {
+ ssize_t returnable;
+
+ if ((returnable= memcached_io_write(ptr, vector->buffer, vector->length, false)) == -1)
+ {
+ return -1;
+ }
+ total+= returnable;
+ }
+
+ if (with_flush)
+ {
+ if (memcached_io_write(ptr, NULL, 0, true) == -1)
+ {
+ return -1;
+ }
+ }
+
+ return total;
+}
+
ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
const void *buffer, size_t length, bool with_flush)
{
uint16_t reserved;
};
+struct __write_vector_st
+{
+ size_t length;
+ const void *buffer;
+};
+
+
+LIBMEMCACHED_LOCAL
+ssize_t memcached_io_writev(memcached_server_write_instance_st ptr,
+ struct __write_vector_st *vector,
+ size_t number_of, bool with_flush);
+
LIBMEMCACHED_LOCAL
ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
const void *buffer, size_t length, bool with_flush);
do {
/* send the packet */
- if (memcached_io_write(server, request.bytes,
- sizeof(request.bytes), 0) != sizeof(request.bytes) ||
- memcached_io_write(server, chosenmech, keylen, 0) != keylen ||
- memcached_io_write(server, data, len, 1) != (ssize_t)len)
+
+ struct __write_vector_st vector[]=
+ {
+ { .length= sizeof(request.bytes), .buffer= request.bytes },
+ { .length= keylen, .buffer= chosenmech },
+ { .length= len, .buffer= data }
+ };
+
+ if (memcached_io_writev(server, vector, 3, true) == -1)
{
rc= MEMCACHED_WRITE_FAILURE;
goto end;
}
}
+ struct __write_vector_st vector[]=
+ {
+ { .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_write(server, ptr->prefix_key, ptr->prefix_key_length, false) == -1) ||
- (memcached_io_write(server, key, key_length, false) == -1) ||
- (memcached_io_write(server, value, value_length, flush) == -1))
+ if (((rc= memcached_do(server, (const char*)request.bytes, send_length, false)) != MEMCACHED_SUCCESS) ||
+ (memcached_io_writev(server, vector, 3, flush) == -1))
{
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_write(instance, key, key_length, false) == -1) ||
- (memcached_io_write(instance, value, value_length, flush) == -1))
+ if ((memcached_do(instance, (const char*)request.bytes, send_length, false) != MEMCACHED_SUCCESS) ||
+ (memcached_io_writev(instance, vector, 3, flush) == -1))
{
memcached_io_reset(instance);
}