X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemcached.c;h=90d3a708aee4a414add1c1eaada8c430e2115f4e;hb=3107b89b4d3441929835e6f96fda841c76f704fe;hp=52b3834b7752fcfee7bb720e02c895c09c837fa6;hpb=b10a03e4afb5514f1c86f5c75b9bfc7d46ce49b4;p=awesomized%2Flibmemcached diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index 52b3834b..90d3a708 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -9,18 +9,24 @@ memcached_st *memcached_create(memcached_st *ptr) if (ptr == NULL) { - ptr= (memcached_st *)malloc(sizeof(memcached_st)); + ptr= (memcached_st *)calloc(1, sizeof(memcached_st)); - if (!ptr) + if (! ptr) + { return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */ + } - memset(ptr, 0, sizeof(memcached_st)); - 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; @@ -32,6 +38,9 @@ memcached_st *memcached_create(memcached_st *ptr) ptr->io_msg_watermark= 500; ptr->io_bytes_watermark= 65 * 1024; + WATCHPOINT_ASSERT_INITIALIZED(&ptr->result); + WATCHPOINT_ASSERT_INITIALIZED(&ptr->hashkit); + return ptr; } @@ -46,22 +55,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; + } } /* @@ -71,13 +74,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; } @@ -95,7 +98,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; @@ -106,12 +109,14 @@ 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; new_clone->io_msg_watermark= source->io_msg_watermark; new_clone->io_bytes_watermark= source->io_bytes_watermark; new_clone->io_key_prefetch= source->io_key_prefetch; + new_clone->number_of_replicas= source->number_of_replicas; if (source->hosts) rc= memcached_server_push(new_clone, source->hosts); @@ -131,6 +136,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 +149,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; +}