From: Brian Aker Date: Fri, 2 Apr 2010 04:10:35 +0000 (-0700) Subject: Updating for vector interface. X-Git-Tag: 0.40~25 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=4767d70bea3e4930081016a15630ac927757962b;p=m6w6%2Flibmemcached Updating for vector interface. --- diff --git a/libmemcached/auto.c b/libmemcached/auto.c index b4575f07..16e65b86 100644 --- a/libmemcached/auto.c +++ b/libmemcached/auto.c @@ -116,10 +116,15 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, 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; diff --git a/libmemcached/delete.c b/libmemcached/delete.c index c83ea5e6..d2109ecc 100644 --- a/libmemcached/delete.c +++ b/libmemcached/delete.c @@ -126,7 +126,9 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, goto error; if (! to_write) + { rc= MEMCACHED_BUFFERED; + } else if (!no_reply) { rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); @@ -171,11 +173,16 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, 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; @@ -195,8 +202,7 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, 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); diff --git a/libmemcached/get.c b/libmemcached/get.c index 035f6ea2..88b6d879 100644 --- a/libmemcached/get.c +++ b/libmemcached/get.c @@ -243,25 +243,14 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, 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; @@ -535,9 +524,14 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, * 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; diff --git a/libmemcached/io.c b/libmemcached/io.c index f1afc669..c72aaa27 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.c @@ -326,6 +326,34 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, 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) { diff --git a/libmemcached/io.h b/libmemcached/io.h index dc6a672f..89f3d477 100644 --- a/libmemcached/io.h +++ b/libmemcached/io.h @@ -40,6 +40,18 @@ struct udp_datagram_header_st 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); diff --git a/libmemcached/sasl.c b/libmemcached/sasl.c index 9b4533b3..d77532de 100644 --- a/libmemcached/sasl.c +++ b/libmemcached/sasl.c @@ -140,10 +140,15 @@ memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *s 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; diff --git a/libmemcached/storage.c b/libmemcached/storage.c index 88794596..954e733a 100644 --- a/libmemcached/storage.c +++ b/libmemcached/storage.c @@ -487,13 +487,17 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, } } + 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; @@ -513,10 +517,8 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, 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); }