6 memcached_st
*memcached_create(memcached_st
*ptr
)
8 memcached_result_st
*result_ptr
;
12 ptr
= (memcached_st
*)malloc(sizeof(memcached_st
));
15 return NULL
; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
17 memset(ptr
, 0, sizeof(memcached_st
));
18 ptr
->is_allocated
= MEMCACHED_ALLOCATED
;
22 memset(ptr
, 0, sizeof(memcached_st
));
24 result_ptr
= memcached_result_create(ptr
, &ptr
->result
);
25 WATCHPOINT_ASSERT(result_ptr
);
26 ptr
->poll_timeout
= MEMCACHED_DEFAULT_TIMEOUT
;
27 ptr
->distribution
= MEMCACHED_DISTRIBUTION_MODULA
;
28 ptr
->number_of_replicas
= 1;
33 void memcached_free(memcached_st
*ptr
)
35 /* If we have anything open, lets close it now */
37 server_list_free(ptr
, ptr
->hosts
);
38 memcached_result_free(&ptr
->result
);
43 if (ptr
->is_allocated
== MEMCACHED_ALLOCATED
)
46 ptr
->call_free(ptr
, ptr
);
51 ptr
->is_allocated
= MEMCACHED_USED
;
55 clone is the destination, while ptr is the structure to clone.
56 If ptr is NULL the call is the same as if a memcached_create() was
59 memcached_st
*memcached_clone(memcached_st
*clone
, memcached_st
*ptr
)
61 memcached_return rc
= MEMCACHED_SUCCESS
;
62 memcached_st
*new_clone
;
65 return memcached_create(clone
);
67 if (ptr
->is_allocated
== MEMCACHED_USED
)
73 new_clone
= memcached_create(clone
);
75 if (new_clone
== NULL
)
79 rc
= memcached_server_push(new_clone
, ptr
->hosts
);
81 if (rc
!= MEMCACHED_SUCCESS
)
83 memcached_free(new_clone
);
89 new_clone
->flags
= ptr
->flags
;
90 new_clone
->send_size
= ptr
->send_size
;
91 new_clone
->recv_size
= ptr
->recv_size
;
92 new_clone
->poll_timeout
= ptr
->poll_timeout
;
93 new_clone
->distribution
= ptr
->distribution
;
94 new_clone
->hash
= ptr
->hash
;
95 new_clone
->user_data
= ptr
->user_data
;
97 new_clone
->on_clone
= ptr
->on_clone
;
98 new_clone
->on_cleanup
= ptr
->on_cleanup
;
99 new_clone
->call_free
= ptr
->call_free
;
100 new_clone
->call_malloc
= ptr
->call_malloc
;
101 new_clone
->call_realloc
= ptr
->call_realloc
;
104 ptr
->on_clone(ptr
, new_clone
);