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