X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fauto.c;h=4fde5827de73f4172b7094a48d1f42b794811c83;hb=3f74469068084eab48af568f477360fb24dc8bcb;hp=5e3e026111ae42e39c5b74e868cc0450f4a3bca1;hpb=814d911f182e08fb4401df649270f5fff2e8ed4c;p=m6w6%2Flibmemcached diff --git a/libmemcached/auto.c b/libmemcached/auto.c index 5e3e0261..4fde5827 100644 --- a/libmemcached/auto.c +++ b/libmemcached/auto.c @@ -21,30 +21,33 @@ static memcached_return_t memcached_auto(memcached_st *ptr, size_t send_length; memcached_return_t rc; char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - unsigned int server_key; + uint32_t server_key; + memcached_server_instance_st *instance; bool no_reply= ptr->flags.no_reply; - unlikely (ptr->hosts == NULL || memcached_server_count(ptr) == 0) + unlikely (memcached_server_count(ptr) == 0) return MEMCACHED_NO_SERVERS; if (ptr->flags.verify_key && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) return MEMCACHED_BAD_KEY_PROVIDED; server_key= memcached_generate_hash(ptr, master_key, master_key_length); + instance= memcached_server_instance_fetch(ptr, server_key); send_length= (size_t)snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "%s %s%.*s %" PRIu64 "%s\r\n", verb, + "%s %.*s%.*s %" PRIu64 "%s\r\n", verb, + (int)ptr->prefix_key_length, ptr->prefix_key, (int)key_length, key, offset, no_reply ? " noreply" : ""); unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; - rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, 1); + rc= memcached_do(instance, buffer, send_length, 1); if (no_reply || rc != MEMCACHED_SUCCESS) return rc; - rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); /* So why recheck responce? Because the protocol is brain dead :) @@ -79,13 +82,15 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, uint32_t expiration, uint64_t *value) { - unsigned int server_key; + uint32_t server_key; + memcached_server_instance_st *instance; bool no_reply= ptr->flags.no_reply; - unlikely (ptr->hosts == NULL || memcached_server_count(ptr) == 0) + unlikely (memcached_server_count(ptr) == 0) return MEMCACHED_NO_SERVERS; server_key= memcached_generate_hash(ptr, master_key, master_key_length); + instance= memcached_server_instance_fetch(ptr, server_key); if (no_reply) { @@ -106,17 +111,17 @@ 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); - if ((memcached_do(&ptr->hosts[server_key], request.bytes, + if ((memcached_do(instance, request.bytes, sizeof(request.bytes), 0)!=MEMCACHED_SUCCESS) || - (memcached_io_write(&ptr->hosts[server_key], key, key_length, 1) == -1)) + (memcached_io_write(instance, key, key_length, 1) == -1)) { - memcached_io_reset(&ptr->hosts[server_key]); + memcached_io_reset(instance); return MEMCACHED_WRITE_FAILURE; } if (no_reply) return MEMCACHED_SUCCESS; - return memcached_response(&ptr->hosts[server_key], (char*)value, sizeof(*value), NULL); + return memcached_response(instance, (char*)value, sizeof(*value), NULL); } memcached_return_t memcached_increment(memcached_st *ptr,