We now check return key size for memcached_fetch() to make sure it is not
[m6w6/libmemcached] / libmemcached / server.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: String structure used for libmemcached.
9 *
10 */
11
12 #ifndef __MEMCACHED_SERVER_H__
13 #define __MEMCACHED_SERVER_H__
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 struct memcached_server_st {
20 struct {
21 bool is_allocated:1;
22 bool is_initialized:1;
23 bool sockaddr_inited:1;
24 } options;
25 uint32_t number_of_hosts;
26 uint32_t cursor_active;
27 in_port_t port;
28 int cached_errno;
29 int fd;
30 uint32_t io_bytes_sent; /* # bytes sent since last read */
31 uint32_t server_failure_counter;
32 uint32_t weight;
33 struct { // Place any "state" sort variables in here.
34 bool is_corked;
35 } state;
36 uint8_t major_version;
37 uint8_t micro_version;
38 uint8_t minor_version;
39 memcached_connection_t type;
40 char *read_ptr;
41 char *cached_server_error;
42 size_t read_buffer_length;
43 size_t read_data_length;
44 size_t write_buffer_offset;
45 struct addrinfo *address_info;
46 time_t next_retry;
47 const memcached_st *root;
48 uint64_t limit_maxbytes;
49 char read_buffer[MEMCACHED_MAX_BUFFER];
50 char write_buffer[MEMCACHED_MAX_BUFFER];
51 char hostname[MEMCACHED_MAX_HOST_LENGTH];
52 };
53
54 // Local Only Inline
55 static inline uint32_t memcached_servers_count(memcached_server_st *servers)
56 {
57 return servers->number_of_hosts;
58 }
59
60 // Local Only Inline
61 static inline uint32_t memcached_servers_set_count(memcached_server_st *servers, uint32_t count)
62 {
63 return servers->number_of_hosts= count;
64 }
65
66
67
68 #define memcached_server_count(A) (A)->number_of_hosts
69 #define memcached_server_name(A,B) (B).hostname
70 #define memcached_server_port(A,B) (B).port
71 #define memcached_server_list(A) (A)->servers
72 #define memcached_server_list_set(A,B) (A)->servers=(B)
73 #define memcached_server_response_count(A) (A)->cursor_active
74
75 LIBMEMCACHED_API
76 memcached_return_t memcached_server_cursor(memcached_st *ptr,
77 memcached_server_fn *callback,
78 void *context,
79 uint32_t number_of_callbacks);
80
81 LIBMEMCACHED_API
82 memcached_server_st *memcached_server_by_key(memcached_st *ptr,
83 const char *key,
84 size_t key_length,
85 memcached_return_t *error);
86
87 LIBMEMCACHED_API
88 const char *memcached_server_error(memcached_server_st *ptr);
89
90 LIBMEMCACHED_API
91 void memcached_server_error_reset(memcached_server_st *ptr);
92
93 /* These should not currently be used by end users */
94 /* TODO: Is the above comment valid? If so, how can we unit test these if they
95 * aren't exported. If not, we should remove the comment */
96
97 LIBMEMCACHED_LOCAL
98 memcached_server_st *memcached_server_create_with(const memcached_st *memc,
99 memcached_server_st *host,
100 const char *hostname,
101 in_port_t port,
102 uint32_t weight,
103 memcached_connection_t type);
104
105 LIBMEMCACHED_API
106 void memcached_server_free(memcached_server_st *ptr);
107
108 LIBMEMCACHED_LOCAL
109 memcached_server_st *memcached_server_clone(memcached_server_st *destination,
110 const memcached_server_st *source);
111
112 LIBMEMCACHED_API
113 memcached_return_t memcached_server_remove(memcached_server_st *st_ptr);
114
115 LIBMEMCACHED_API
116 memcached_server_st *memcached_server_get_last_disconnect(memcached_st *ptr);
117
118
119 LIBMEMCACHED_API
120 memcached_return_t memcached_server_add_udp(memcached_st *ptr,
121 const char *hostname,
122 in_port_t port);
123 LIBMEMCACHED_API
124 memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr,
125 const char *filename);
126 LIBMEMCACHED_API
127 memcached_return_t memcached_server_add(memcached_st *ptr,
128 const char *hostname, in_port_t port);
129
130 LIBMEMCACHED_API
131 memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr,
132 const char *hostname,
133 in_port_t port,
134 uint32_t weight);
135 LIBMEMCACHED_API
136 memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *ptr,
137 const char *filename,
138 uint32_t weight);
139 LIBMEMCACHED_API
140 memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, const char *hostname,
141 in_port_t port,
142 uint32_t weight);
143 /* Server List Public functions */
144
145 LIBMEMCACHED_API
146 void memcached_server_list_free(memcached_server_st *ptr);
147
148
149 LIBMEMCACHED_API
150 memcached_return_t memcached_server_push(memcached_st *ptr, memcached_server_st *list);
151
152 LIBMEMCACHED_API
153 memcached_server_st *memcached_server_list_append(memcached_server_st *ptr,
154 const char *hostname,
155 in_port_t port,
156 memcached_return_t *error);
157 LIBMEMCACHED_API
158 memcached_server_st *memcached_server_list_append_with_weight(memcached_server_st *ptr,
159 const char *hostname,
160 in_port_t port,
161 uint32_t weight,
162 memcached_return_t *error);
163 LIBMEMCACHED_API
164 unsigned int memcached_server_list_count(memcached_server_st *ptr);
165
166
167 #ifdef __cplusplus
168 }
169 #endif
170
171 #endif /* __MEMCACHED_SERVER_H__ */