Remove mass calloc() on memcached_st creation.
[awesomized/libmemcached] / libmemcached / memcached.h
1 /* LibMemcached
2 * Copyright (C) 2006-2009 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary: interface for memcached server
9 * Description: main include file for libmemcached
10 *
11 */
12
13 #ifndef __MEMCACHED_H__
14 #define __MEMCACHED_H__
15
16 #include <stdlib.h>
17 #include <inttypes.h>
18
19 #if !defined(__cplusplus)
20 # include <stdbool.h>
21 #endif
22
23 #include <sys/types.h>
24 #include <netinet/in.h>
25
26 #include <libmemcached/visibility.h>
27 #include <libmemcached/configure.h>
28 #include <libmemcached/constants.h>
29 #include <libmemcached/types.h>
30 #include <libmemcached/string.h>
31 #include <libmemcached/stats.h>
32 // Everything above this line must be in the order specified.
33 #include <libmemcached/allocators.h>
34 #include <libmemcached/analyze.h>
35 #include <libmemcached/auto.h>
36 #include <libmemcached/behavior.h>
37 #include <libmemcached/callback.h>
38 #include <libmemcached/delete.h>
39 #include <libmemcached/dump.h>
40 #include <libmemcached/fetch.h>
41 #include <libmemcached/flush.h>
42 #include <libmemcached/flush_buffers.h>
43 #include <libmemcached/get.h>
44 #include <libmemcached/hash.h>
45 #include <libmemcached/parse.h>
46 #include <libmemcached/quit.h>
47 #include <libmemcached/result.h>
48 #include <libmemcached/server.h>
49 #include <libmemcached/storage.h>
50 #include <libmemcached/strerror.h>
51 #include <libmemcached/verbosity.h>
52 #include <libmemcached/version.h>
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 struct memcached_st {
59 /**
60 @note these are static and should not change without a call to behavior.
61 */
62 struct {
63 bool is_purging:1;
64 bool is_processing_input:1;
65 } state;
66 struct {
67 // Everything below here is pretty static.
68 bool auto_eject_hosts:1;
69 bool binary_protocol:1;
70 bool buffer_requests:1;
71 bool cork:1;
72 bool hash_with_prefix_key:1;
73 bool ketama_weighted:1;
74 bool no_block:1;
75 bool no_reply:1;
76 bool randomize_replica_read:1;
77 bool reuse_memory:1;
78 bool support_cas:1;
79 bool tcp_nodelay:1;
80 bool use_cache_lookups:1;
81 bool use_sort_hosts:1;
82 bool use_udp:1;
83 bool verify_key:1;
84 } flags;
85 memcached_server_distribution_t distribution;
86 memcached_hash_t hash;
87 uint32_t continuum_points_counter; // Ketama
88 uint32_t number_of_hosts;
89 memcached_server_st *servers;
90 memcached_server_st *last_disconnected_server;
91 int32_t snd_timeout;
92 int32_t rcv_timeout;
93 uint32_t server_failure_limit;
94 uint32_t io_msg_watermark;
95 uint32_t io_bytes_watermark;
96 uint32_t io_key_prefetch;
97 int cached_errno;
98 int32_t poll_timeout;
99 int32_t connect_timeout;
100 int32_t retry_timeout;
101 uint32_t continuum_count; // Ketama
102 int send_size;
103 int recv_size;
104 void *user_data;
105 time_t next_distribution_rebuild; // Ketama
106 size_t prefix_key_length;
107 uint32_t number_of_replicas;
108 memcached_hash_t distribution_hash;
109 memcached_result_st result;
110 memcached_continuum_item_st *continuum; // Ketama
111
112 memcached_free_fn call_free;
113 memcached_malloc_fn call_malloc;
114 memcached_realloc_fn call_realloc;
115 memcached_calloc_fn call_calloc;
116
117 memcached_clone_fn on_clone;
118 memcached_cleanup_fn on_cleanup;
119 memcached_trigger_key_fn get_key_failure;
120 memcached_trigger_delete_key_fn delete_trigger;
121 memcached_callback_st *callbacks;
122 char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
123 struct {
124 bool is_allocated:1;
125 } options;
126 };
127
128 LIBMEMCACHED_API
129 void memcached_servers_reset(memcached_st *ptr);
130
131 /* Public API */
132
133 LIBMEMCACHED_API
134 memcached_st *memcached_create(memcached_st *ptr);
135
136 LIBMEMCACHED_API
137 void memcached_free(memcached_st *ptr);
138
139 LIBMEMCACHED_API
140 memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr);
141
142 LIBMEMCACHED_API
143 void *memcached_get_user_data(const memcached_st *ptr);
144
145 LIBMEMCACHED_API
146 void *memcached_set_user_data(memcached_st *ptr, void *data);
147
148 // Local Only Inline
149 static inline memcached_server_st *memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key)
150 {
151 return &ptr->servers[server_key];
152 }
153
154
155 #ifdef __cplusplus
156 }
157 #endif
158
159
160 #endif /* __MEMCACHED_H__ */