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