X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2Fmemcached.c;h=946af6cb8f6bdd9a4edbc0e2c8179a001eed1031;hb=89eed63d9bf97065589679c45a3095088c4bb150;hp=a5be8e255fab93eba37af6c3de2a7b71930b27f1;hpb=311bd0fafe1da7b5cc770a2ff4fac5472a801a40;p=awesomized%2Flibmemcached diff --git a/lib/memcached.c b/lib/memcached.c index a5be8e25..946af6cb 100644 --- a/lib/memcached.c +++ b/lib/memcached.c @@ -5,8 +5,9 @@ memcached_st *memcached_create(memcached_st *ptr) { - memcached_string_st *string_ptr; - if (!ptr) + memcached_result_st *result_ptr; + + if (ptr == NULL) { ptr= (memcached_st *)malloc(sizeof(memcached_st)); @@ -20,10 +21,10 @@ memcached_st *memcached_create(memcached_st *ptr) { memset(ptr, 0, sizeof(memcached_st)); } - string_ptr= memcached_string_create(ptr, &ptr->result_buffer, 0); - WATCHPOINT_ASSERT(string_ptr); - ptr->poll_timeout= -1; - ptr->distribution= MEMCACHED_DISTRIBUTION_MODULO; + result_ptr= memcached_result_create(ptr, &ptr->result); + WATCHPOINT_ASSERT(result_ptr); + ptr->poll_timeout= MEMCACHED_DEFAULT_TIMEOUT; + ptr->distribution= MEMCACHED_DISTRIBUTION_MODULA; return ptr; } @@ -32,11 +33,19 @@ void memcached_free(memcached_st *ptr) { /* If we have anything open, lets close it now */ memcached_quit(ptr); - memcached_server_list_free(ptr->hosts); - memcached_string_free(&ptr->result_buffer); + server_list_free(ptr, ptr->hosts); + memcached_result_free(&ptr->result); + + if (ptr->on_cleanup) + ptr->on_cleanup(ptr); if (ptr->is_allocated == MEMCACHED_ALLOCATED) - free(ptr); + { + if (ptr->call_free) + ptr->call_free(ptr, ptr); + else + free(ptr); + } else ptr->is_allocated= MEMCACHED_USED; } @@ -48,11 +57,18 @@ void memcached_free(memcached_st *ptr) */ memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr) { - memcached_return rc; + memcached_return rc= MEMCACHED_SUCCESS; memcached_st *new_clone; if (ptr == NULL) - return memcached_create(clone); + { + new_clone= memcached_create(clone); + + if (ptr->on_clone) + ptr->on_clone(NULL, new_clone); + + return new_clone; + } if (ptr->is_allocated == MEMCACHED_USED) { @@ -77,11 +93,21 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr) new_clone->flags= ptr->flags; - new_clone->number_of_hosts= ptr->number_of_hosts; new_clone->send_size= ptr->send_size; new_clone->recv_size= ptr->recv_size; new_clone->poll_timeout= ptr->poll_timeout; new_clone->distribution= ptr->distribution; + new_clone->hash= ptr->hash; + new_clone->user_data= ptr->user_data; + + new_clone->on_clone= ptr->on_clone; + new_clone->on_cleanup= ptr->on_cleanup; + new_clone->call_free= ptr->call_free; + new_clone->call_malloc= ptr->call_malloc; + new_clone->call_realloc= ptr->call_realloc; + + if (ptr->on_clone) + ptr->on_clone(ptr, new_clone); return new_clone; }