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 __MEMCACHED_SERVER_H__
13 #define __MEMCACHED_SERVER_H__
19 struct memcached_server_st
{
22 bool is_initialized
:1;
23 bool sockaddr_inited
:1;
25 uint32_t number_of_hosts
;
26 uint32_t cursor_active
;
30 uint32_t io_bytes_sent
; /* # bytes sent since last read */
31 uint32_t server_failure_counter
;
33 struct { // Place any "state" sort variables in here.
36 uint8_t major_version
;
37 uint8_t micro_version
;
38 uint8_t minor_version
;
39 memcached_connection_t type
;
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
;
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
];
55 static inline uint32_t memcached_servers_count(memcached_server_st
*servers
)
57 return servers
->number_of_hosts
;
61 static inline uint32_t memcached_servers_set_count(memcached_server_st
*servers
, uint32_t count
)
63 return servers
->number_of_hosts
= count
;
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
76 memcached_return_t
memcached_server_cursor(memcached_st
*ptr
,
77 memcached_server_fn
*callback
,
79 uint32_t number_of_callbacks
);
82 memcached_server_st
*memcached_server_by_key(memcached_st
*ptr
,
85 memcached_return_t
*error
);
88 const char *memcached_server_error(memcached_server_st
*ptr
);
91 void memcached_server_error_reset(memcached_server_st
*ptr
);
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 */
98 memcached_server_st
*memcached_server_create_with(const memcached_st
*memc
,
99 memcached_server_st
*host
,
100 const char *hostname
,
103 memcached_connection_t type
);
106 void memcached_server_free(memcached_server_st
*ptr
);
109 memcached_server_st
*memcached_server_clone(memcached_server_st
*destination
,
110 const memcached_server_st
*source
);
113 memcached_return_t
memcached_server_remove(memcached_server_st
*st_ptr
);
116 memcached_server_st
*memcached_server_get_last_disconnect(memcached_st
*ptr
);
120 memcached_return_t
memcached_server_add_udp(memcached_st
*ptr
,
121 const char *hostname
,
124 memcached_return_t
memcached_server_add_unix_socket(memcached_st
*ptr
,
125 const char *filename
);
127 memcached_return_t
memcached_server_add(memcached_st
*ptr
,
128 const char *hostname
, in_port_t port
);
131 memcached_return_t
memcached_server_add_udp_with_weight(memcached_st
*ptr
,
132 const char *hostname
,
136 memcached_return_t
memcached_server_add_unix_socket_with_weight(memcached_st
*ptr
,
137 const char *filename
,
140 memcached_return_t
memcached_server_add_with_weight(memcached_st
*ptr
, const char *hostname
,
143 /* Server List Public functions */
146 void memcached_server_list_free(memcached_server_st
*ptr
);
150 memcached_return_t
memcached_server_push(memcached_st
*ptr
, memcached_server_st
*list
);
153 memcached_server_st
*memcached_server_list_append(memcached_server_st
*ptr
,
154 const char *hostname
,
156 memcached_return_t
*error
);
158 memcached_server_st
*memcached_server_list_append_with_weight(memcached_server_st
*ptr
,
159 const char *hostname
,
162 memcached_return_t
*error
);
164 unsigned int memcached_server_list_count(memcached_server_st
*ptr
);
171 #endif /* __MEMCACHED_SERVER_H__ */