X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2Fmemcached_get.c;h=251cd59201c0ac67236cf289b6ee48006185af2f;hb=9e9572af3e9be02dd3de5c71bf1665217a770e1b;hp=c7c21d1ee43ad7518700d1c6f026ca1323dcd62a;hpb=b9298b65419d873299e010afa0f4eca2c8259969;p=m6w6%2Flibmemcached diff --git a/lib/memcached_get.c b/lib/memcached_get.c index c7c21d1e..251cd592 100644 --- a/lib/memcached_get.c +++ b/lib/memcached_get.c @@ -85,17 +85,23 @@ static char *memcached_value_fetch(memcached_st *ptr, char *key, size_t *key_len /* We add two bytes so that we can walk the \r\n */ value= (char *)malloc(((*value_length) +2) * sizeof(char)); - memset(value, 0, ((*value_length) +2) * sizeof(char)); - if (!value) { *value_length= 0; *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; return NULL; } + memset(value, 0, ((*value_length) +2) * sizeof(char)); value_ptr= value; read_length= 0; + /* + We read the \r\n into the string since not doing so is more + cycles then the waster of memory to do so. + + We are null terminating through, which will most likely make + some people lazy about using the return length. + */ to_read= (*value_length) + 2; read_length= memcached_io_read(ptr, server_key, @@ -107,6 +113,9 @@ static char *memcached_value_fetch(memcached_st *ptr, char *key, size_t *key_len goto read_error; } + value[*value_length]= 0; + value[(*value_length) + 1]= 0; + return value; } } @@ -154,6 +163,8 @@ char *memcached_get(memcached_st *ptr, char *key, size_t key_length, *error= MEMCACHED_NOTFOUND; goto error; } + else if (*error == MEMCACHED_END) + assert(0); /* If this happens we have somehow messed up the fetch */ else if (*error == MEMCACHED_SUCCESS) { memcached_return rc; @@ -249,7 +260,10 @@ memcached_return memcached_mget(memcached_st *ptr, } memcached_string_free(ptr, string); cursor_key_exec[x]= NULL; /* Remove warning */ + ptr->hosts[x].cursor_active= 1; } + else + ptr->hosts[x].cursor_active= 0; } free(cursor_key_exec); @@ -267,16 +281,28 @@ char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length, while (ptr->cursor_server < ptr->number_of_hosts) { + if (!ptr->hosts[ptr->cursor_server].cursor_active) + { + ptr->cursor_server++; + continue; + } + value_check= memcached_value_fetch(ptr, key, key_length, value_length, flags, error, 1, ptr->cursor_server); if (*error == MEMCACHED_NOTFOUND) ptr->cursor_server++; + else if (*error == MEMCACHED_END && *value_length == 0) + return NULL; + else if (*error == MEMCACHED_END) + assert(0); /* If this happens we have somehow messed up the fetch */ else if (*error != MEMCACHED_SUCCESS) return NULL; else return value_check; + } + *value_length= 0; return NULL; }