2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
8 * Summary: String structure used for libmemcached.
12 #ifndef __LIBMEMCACHED_SERVER_H__
13 #define __LIBMEMCACHED_SERVER_H__
16 struct memcached_server_st
{
18 bool is_allocated MEMCACHED_BITFIELD
;
19 bool is_initialized MEMCACHED_BITFIELD
;
20 bool sockaddr_inited MEMCACHED_BITFIELD
;
22 uint32_t number_of_hosts
;
23 uint32_t cursor_active
;
27 uint32_t io_bytes_sent
; /* # bytes sent since last read */
28 uint32_t server_failure_counter
;
30 struct { // Place any "state" sort variables in here.
33 uint8_t major_version
;
34 uint8_t micro_version
;
35 uint8_t minor_version
;
36 memcached_connection_t type
;
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
;
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
[NI_MAXHOST
];
57 memcached_return_t
memcached_server_cursor(memcached_st
*ptr
,
58 memcached_server_fn
*callback
,
60 uint32_t number_of_callbacks
);
63 memcached_server_st
*memcached_server_by_key(memcached_st
*ptr
,
66 memcached_return_t
*error
);
69 const char *memcached_server_error(memcached_server_st
*ptr
);
72 void memcached_server_error_reset(memcached_server_st
*ptr
);
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 */
79 memcached_server_st
*memcached_server_create_with(const memcached_st
*memc
,
80 memcached_server_st
*host
,
84 memcached_connection_t type
);
87 void memcached_server_free(memcached_server_st
*ptr
);
90 memcached_server_st
*memcached_server_clone(memcached_server_st
*destination
,
91 const memcached_server_st
*source
);
94 memcached_return_t
memcached_server_remove(memcached_server_st
*st_ptr
);
97 memcached_server_st
*memcached_server_get_last_disconnect(memcached_st
*ptr
);
101 memcached_return_t
memcached_server_add_udp(memcached_st
*ptr
,
102 const char *hostname
,
105 memcached_return_t
memcached_server_add_unix_socket(memcached_st
*ptr
,
106 const char *filename
);
108 memcached_return_t
memcached_server_add(memcached_st
*ptr
,
109 const char *hostname
, in_port_t port
);
112 memcached_return_t
memcached_server_add_udp_with_weight(memcached_st
*ptr
,
113 const char *hostname
,
117 memcached_return_t
memcached_server_add_unix_socket_with_weight(memcached_st
*ptr
,
118 const char *filename
,
121 memcached_return_t
memcached_server_add_with_weight(memcached_st
*ptr
, const char *hostname
,
124 /* Server List Public functions */
127 void memcached_server_list_free(memcached_server_st
*ptr
);
131 memcached_return_t
memcached_server_push(memcached_st
*ptr
, memcached_server_st
*list
);
134 memcached_server_st
*memcached_server_list_append(memcached_server_st
*ptr
,
135 const char *hostname
,
137 memcached_return_t
*error
);
139 memcached_server_st
*memcached_server_list_append_with_weight(memcached_server_st
*ptr
,
140 const char *hostname
,
143 memcached_return_t
*error
);
145 unsigned int memcached_server_list_count(memcached_server_st
*ptr
);
148 static inline uint32_t memcached_servers_count(memcached_server_st
*servers
)
150 return servers
->number_of_hosts
;
154 static inline uint32_t memcached_servers_set_count(memcached_server_st
*servers
, uint32_t count
)
156 return servers
->number_of_hosts
= count
;
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
171 #endif /* __LIBMEMCACHED_SERVER_H__ */