6 memcached_st
*memcached_create(memcached_st
*ptr
)
8 memcached_result_st
*result_ptr
;
11 ptr
= (memcached_st
*)malloc(sizeof(memcached_st
));
14 return NULL
; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
16 memset(ptr
, 0, sizeof(memcached_st
));
17 ptr
->is_allocated
= MEMCACHED_ALLOCATED
;
21 memset(ptr
, 0, sizeof(memcached_st
));
23 result_ptr
= memcached_result_create(ptr
, &ptr
->result
);
24 WATCHPOINT_ASSERT(result_ptr
);
25 ptr
->poll_timeout
= MEMCACHED_DEFAULT_TIMEOUT
;
26 ptr
->distribution
= MEMCACHED_DISTRIBUTION_MODULA
;
31 void memcached_free(memcached_st
*ptr
)
33 /* If we have anything open, lets close it now */
35 memcached_server_list_free(ptr
->hosts
);
36 memcached_result_free(&ptr
->result
);
38 if (ptr
->is_allocated
== MEMCACHED_ALLOCATED
)
41 ptr
->is_allocated
= MEMCACHED_USED
;
45 clone is the destination, while ptr is the structure to clone.
46 If ptr is NULL the call is the same as if a memcached_create() was
49 memcached_st
*memcached_clone(memcached_st
*clone
, memcached_st
*ptr
)
51 memcached_return rc
= MEMCACHED_SUCCESS
;
52 memcached_st
*new_clone
;
55 return memcached_create(clone
);
57 if (ptr
->is_allocated
== MEMCACHED_USED
)
63 new_clone
= memcached_create(clone
);
65 if (new_clone
== NULL
)
69 rc
= memcached_server_push(new_clone
, ptr
->hosts
);
71 if (rc
!= MEMCACHED_SUCCESS
)
73 memcached_free(new_clone
);
79 new_clone
->flags
= ptr
->flags
;
80 new_clone
->send_size
= ptr
->send_size
;
81 new_clone
->recv_size
= ptr
->recv_size
;
82 new_clone
->poll_timeout
= ptr
->poll_timeout
;
83 new_clone
->distribution
= ptr
->distribution
;
84 new_clone
->hash
= ptr
->hash
;