6 memcached_st
*memcached_create(memcached_st
*ptr
)
8 memcached_result_st
*result_ptr
;
12 ptr
= (memcached_st
*)calloc(1, sizeof(memcached_st
));
16 return NULL
; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
19 ptr
->options
.is_allocated
= true;
23 memset(ptr
, 0, sizeof(memcached_st
));
26 ptr
->options
.is_initialized
= true;
28 memcached_set_memory_allocators(ptr
, NULL
, NULL
, NULL
, NULL
);
30 result_ptr
= memcached_result_create(ptr
, &ptr
->result
);
31 WATCHPOINT_ASSERT(result_ptr
);
32 ptr
->poll_timeout
= MEMCACHED_DEFAULT_TIMEOUT
;
33 ptr
->connect_timeout
= MEMCACHED_DEFAULT_TIMEOUT
;
34 ptr
->retry_timeout
= 0;
35 ptr
->distribution
= MEMCACHED_DISTRIBUTION_MODULA
;
37 /* TODO, Document why we picked these defaults */
38 ptr
->io_msg_watermark
= 500;
39 ptr
->io_bytes_watermark
= 65 * 1024;
41 WATCHPOINT_ASSERT_INITIALIZED(&ptr
->result
);
46 void memcached_free(memcached_st
*ptr
)
48 /* If we have anything open, lets close it now */
50 server_list_free(ptr
, ptr
->hosts
);
51 memcached_result_free(&ptr
->result
);
57 ptr
->call_free(ptr
, ptr
->continuum
);
59 if (memcached_is_allocated(ptr
))
61 ptr
->call_free(ptr
, ptr
);
65 ptr
->options
.is_initialized
= false;
70 clone is the destination, while source is the structure to clone.
71 If source is NULL the call is the same as if a memcached_create() was
74 memcached_st
*memcached_clone(memcached_st
*clone
, memcached_st
*source
)
76 memcached_return_t rc
= MEMCACHED_SUCCESS
;
77 memcached_st
*new_clone
;
80 return memcached_create(clone
);
82 if (clone
&& memcached_is_allocated(clone
))
87 new_clone
= memcached_create(clone
);
89 if (new_clone
== NULL
)
92 new_clone
->flags
= source
->flags
;
93 new_clone
->send_size
= source
->send_size
;
94 new_clone
->recv_size
= source
->recv_size
;
95 new_clone
->poll_timeout
= source
->poll_timeout
;
96 new_clone
->connect_timeout
= source
->connect_timeout
;
97 new_clone
->retry_timeout
= source
->retry_timeout
;
98 new_clone
->distribution
= source
->distribution
;
99 new_clone
->hash
= source
->hash
;
100 new_clone
->distribution_hash
= source
->distribution_hash
;
101 new_clone
->user_data
= source
->user_data
;
103 new_clone
->snd_timeout
= source
->snd_timeout
;
104 new_clone
->rcv_timeout
= source
->rcv_timeout
;
106 new_clone
->on_clone
= source
->on_clone
;
107 new_clone
->on_cleanup
= source
->on_cleanup
;
108 new_clone
->call_free
= source
->call_free
;
109 new_clone
->call_malloc
= source
->call_malloc
;
110 new_clone
->call_realloc
= source
->call_realloc
;
111 new_clone
->call_calloc
= source
->call_calloc
;
112 new_clone
->get_key_failure
= source
->get_key_failure
;
113 new_clone
->delete_trigger
= source
->delete_trigger
;
114 new_clone
->server_failure_limit
= source
->server_failure_limit
;
115 new_clone
->io_msg_watermark
= source
->io_msg_watermark
;
116 new_clone
->io_bytes_watermark
= source
->io_bytes_watermark
;
117 new_clone
->io_key_prefetch
= source
->io_key_prefetch
;
118 new_clone
->number_of_replicas
= source
->number_of_replicas
;
121 rc
= memcached_server_push(new_clone
, source
->hosts
);
123 if (rc
!= MEMCACHED_SUCCESS
)
125 memcached_free(new_clone
);
131 if (source
->prefix_key
[0] != 0)
133 strcpy(new_clone
->prefix_key
, source
->prefix_key
);
134 new_clone
->prefix_key_length
= source
->prefix_key_length
;
137 rc
= run_distribution(new_clone
);
139 if (rc
!= MEMCACHED_SUCCESS
)
141 memcached_free(new_clone
);
146 if (source
->on_clone
)
147 source
->on_clone(source
, new_clone
);
152 void *memcached_get_user_data(memcached_st
*ptr
)
154 return ptr
->user_data
;
157 void *memcached_set_user_data(memcached_st
*ptr
, void *data
)
159 void *ret
= ptr
->user_data
;
160 ptr
->user_data
= data
;