X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2Fmemcached.c;h=5471eba6e8b16c743f86075a867268cded2dc7ea;hb=8820c618bc66991f0ea6cb45cd8deb0fc0fc560e;hp=861bafda95dbaf76dba54503cf90efc558268b6f;hpb=666a820df3605bf92a4ffefed6ec3b1649f37291;p=awesomized%2Flibmemcached diff --git a/lib/memcached.c b/lib/memcached.c index 861bafda..5471eba6 100644 --- a/lib/memcached.c +++ b/lib/memcached.c @@ -5,7 +5,7 @@ memcached_st *memcached_create(memcached_st *ptr) { - memcached_string_st *string_ptr; + memcached_result_st *result_ptr; if (!ptr) { ptr= (memcached_st *)malloc(sizeof(memcached_st)); @@ -20,10 +20,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; } @@ -33,7 +33,10 @@ 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); + memcached_result_free(&ptr->result); + + if (ptr->on_cleanup) + ptr->on_cleanup(ptr); if (ptr->is_allocated == MEMCACHED_ALLOCATED) free(ptr); @@ -48,11 +51,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) { @@ -61,9 +71,12 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr) } new_clone= memcached_create(clone); + + if (new_clone == NULL) + return NULL; - - rc= memcached_server_push(new_clone, ptr->hosts); + if (ptr->hosts) + rc= memcached_server_push(new_clone, ptr->hosts); if (rc != MEMCACHED_SUCCESS) { @@ -74,11 +87,15 @@ 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; + + if (ptr->on_clone) + ptr->on_clone(ptr, new_clone); return new_clone; }