X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemcached.c;h=2fa4f42ce940cd4a19dd369851d0bc78d80eff86;hb=8fd8f655540e3d6aa0b0a3eb0f4f7df1be2e6542;hp=b880d83377c493e9faeeea411218d5007507311e;hpb=7afbf5c09228f6614b8831ec5f374971a38bbf9f;p=m6w6%2Flibmemcached diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index b880d833..2fa4f42c 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -11,15 +11,22 @@ memcached_st *memcached_create(memcached_st *ptr) { ptr= (memcached_st *)calloc(1, sizeof(memcached_st)); - if (!ptr) + if (! ptr) + { return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */ + } - ptr->is_allocated= true; + ptr->options.is_allocated= true; } else { memset(ptr, 0, sizeof(memcached_st)); } + + ptr->options.is_initialized= true; + + memcached_set_memory_allocators(ptr, NULL, NULL, NULL, NULL); + result_ptr= memcached_result_create(ptr, &ptr->result); WATCHPOINT_ASSERT(result_ptr); ptr->poll_timeout= MEMCACHED_DEFAULT_TIMEOUT; @@ -31,6 +38,8 @@ memcached_st *memcached_create(memcached_st *ptr) ptr->io_msg_watermark= 500; ptr->io_bytes_watermark= 65 * 1024; + WATCHPOINT_ASSERT_INITIALIZED(&ptr->result); + return ptr; } @@ -45,22 +54,16 @@ void memcached_free(memcached_st *ptr) ptr->on_cleanup(ptr); if (ptr->continuum) - { - if (ptr->call_free) - ptr->call_free(ptr, ptr->continuum); - else - free(ptr->continuum); - } + ptr->call_free(ptr, ptr->continuum); - if (ptr->is_allocated) + if (memcached_is_allocated(ptr)) { - if (ptr->call_free) - ptr->call_free(ptr, ptr); - else - free(ptr); + ptr->call_free(ptr, ptr); } else - memset(ptr, 0, sizeof(memcached_st)); + { + ptr->options.is_initialized= false; + } } /* @@ -70,13 +73,13 @@ void memcached_free(memcached_st *ptr) */ memcached_st *memcached_clone(memcached_st *clone, memcached_st *source) { - memcached_return rc= MEMCACHED_SUCCESS; + memcached_return_t rc= MEMCACHED_SUCCESS; memcached_st *new_clone; if (source == NULL) return memcached_create(clone); - if (clone && clone->is_allocated) + if (clone && memcached_is_allocated(clone)) { return NULL; } @@ -94,7 +97,7 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *source) new_clone->retry_timeout= source->retry_timeout; new_clone->distribution= source->distribution; new_clone->hash= source->hash; - new_clone->hash_continuum= source->hash_continuum; + new_clone->distribution_hash= source->distribution_hash; new_clone->user_data= source->user_data; new_clone->snd_timeout= source->snd_timeout; @@ -105,6 +108,7 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *source) new_clone->call_free= source->call_free; new_clone->call_malloc= source->call_malloc; new_clone->call_realloc= source->call_realloc; + new_clone->call_calloc= source->call_calloc; new_clone->get_key_failure= source->get_key_failure; new_clone->delete_trigger= source->delete_trigger; new_clone->server_failure_limit= source->server_failure_limit; @@ -131,6 +135,7 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *source) } rc= run_distribution(new_clone); + if (rc != MEMCACHED_SUCCESS) { memcached_free(new_clone); @@ -143,3 +148,16 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *source) return new_clone; } + +void *memcached_get_user_data(memcached_st *ptr) +{ + return ptr->user_data; +} + +void *memcached_set_user_data(memcached_st *ptr, void *data) +{ + void *ret= ptr->user_data; + ptr->user_data= data; + + return ret; +}