X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2Fmemcached.c;h=e40c3db4c229d1b02e984abb7daa2aba439b2c70;hb=5c17e733976d4ce6287a68205a30d87f58f71ce1;hp=38d479ea00e3f37c4987148c388df64d0a256d15;hpb=44152c2062812b74edbcad6b7bf15e78d93ed12c;p=m6w6%2Flibmemcached diff --git a/lib/memcached.c b/lib/memcached.c index 38d479ea..e40c3db4 100644 --- a/lib/memcached.c +++ b/lib/memcached.c @@ -5,6 +5,7 @@ memcached_st *memcached_create(memcached_st *ptr) { + memcached_string_st *string_ptr; if (!ptr) { ptr= (memcached_st *)malloc(sizeof(memcached_st)); @@ -19,6 +20,9 @@ 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; return ptr; } @@ -27,12 +31,50 @@ void memcached_free(memcached_st *ptr) { if (ptr->hosts) { + memcached_quit(ptr); memcached_server_list_free(ptr->hosts); ptr->hosts= NULL; } + memcached_string_free(&ptr->result_buffer); + if (ptr->is_allocated == MEMCACHED_ALLOCATED) free(ptr); else - memset(ptr, 0, sizeof(memcached_st)); + ptr->is_allocated= MEMCACHED_USED; +} + +/* + clone is the destination, while ptr is the structure to clone. + If ptr is NULL the call is the same as if a memcached_create() was + called. +*/ +memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr) +{ + memcached_return rc; + memcached_st *new_clone; + + if (ptr == NULL) + return memcached_create(clone); + + new_clone= memcached_create(clone); + + + rc= memcached_server_push(new_clone, ptr->hosts); + + if (rc != MEMCACHED_SUCCESS) + { + memcached_free(new_clone); + + return NULL; + } + + + 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; + + return new_clone; }