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
= true;
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
->connect_timeout
= MEMCACHED_DEFAULT_TIMEOUT
;
28 ptr
->retry_timeout
= 0;
29 ptr
->distribution
= MEMCACHED_DISTRIBUTION_MODULA
;
31 /* TODO, Document why we picked these defaults */
32 ptr
->io_msg_watermark
= 500;
33 ptr
->io_bytes_watermark
= 65 * 1024;
38 void memcached_free(memcached_st
*ptr
)
40 /* If we have anything open, lets close it now */
42 server_list_free(ptr
, ptr
->hosts
);
43 memcached_result_free(&ptr
->result
);
51 ptr
->call_free(ptr
, ptr
->continuum
);
56 if (ptr
->is_allocated
)
59 ptr
->call_free(ptr
, ptr
);
64 memset(ptr
, 0, sizeof(memcached_st
));
68 clone is the destination, while source is the structure to clone.
69 If source is NULL the call is the same as if a memcached_create() was
72 memcached_st
*memcached_clone(memcached_st
*clone
, memcached_st
*source
)
74 memcached_return rc
= MEMCACHED_SUCCESS
;
75 memcached_st
*new_clone
;
78 return memcached_create(clone
);
80 if (clone
&& clone
->is_allocated
)
85 new_clone
= memcached_create(clone
);
87 if (new_clone
== NULL
)
90 new_clone
->flags
= source
->flags
;
91 new_clone
->send_size
= source
->send_size
;
92 new_clone
->recv_size
= source
->recv_size
;
93 new_clone
->poll_timeout
= source
->poll_timeout
;
94 new_clone
->connect_timeout
= source
->connect_timeout
;
95 new_clone
->retry_timeout
= source
->retry_timeout
;
96 new_clone
->distribution
= source
->distribution
;
97 new_clone
->hash
= source
->hash
;
98 new_clone
->hash_continuum
= source
->hash_continuum
;
99 new_clone
->user_data
= source
->user_data
;
101 new_clone
->snd_timeout
= source
->snd_timeout
;
102 new_clone
->rcv_timeout
= source
->rcv_timeout
;
104 new_clone
->on_clone
= source
->on_clone
;
105 new_clone
->on_cleanup
= source
->on_cleanup
;
106 new_clone
->call_free
= source
->call_free
;
107 new_clone
->call_malloc
= source
->call_malloc
;
108 new_clone
->call_realloc
= source
->call_realloc
;
109 new_clone
->get_key_failure
= source
->get_key_failure
;
110 new_clone
->delete_trigger
= source
->delete_trigger
;
111 new_clone
->server_failure_limit
= source
->server_failure_limit
;
112 new_clone
->io_msg_watermark
= source
->io_msg_watermark
;
113 new_clone
->io_bytes_watermark
= source
->io_bytes_watermark
;
116 rc
= memcached_server_push(new_clone
, source
->hosts
);
118 if (rc
!= MEMCACHED_SUCCESS
)
120 memcached_free(new_clone
);
126 if (source
->prefix_key
[0] != 0)
128 strcpy(new_clone
->prefix_key
, source
->prefix_key
);
129 new_clone
->prefix_key_length
= source
->prefix_key_length
;
132 rc
= run_distribution(new_clone
);
133 if (rc
!= MEMCACHED_SUCCESS
)
135 memcached_free(new_clone
);
140 if (source
->on_clone
)
141 source
->on_clone(source
, new_clone
);