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 sockaddr_inited
:1;
24 uint32_t number_of_hosts
;
25 uint32_t cursor_active
;
29 uint32_t io_bytes_sent
; /* # bytes sent since last read */
30 uint32_t server_failure_counter
;
32 struct { // Place any "state" sort variables in here.
35 uint8_t major_version
;
36 uint8_t micro_version
;
37 uint8_t minor_version
;
38 memcached_connection_t type
;
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
;
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
];
54 static inline uint32_t memcached_servers_count(memcached_server_st
*servers
)
56 return servers
->number_of_hosts
;
60 static inline uint32_t memcached_servers_set_count(memcached_server_st
*servers
, uint32_t count
)
62 return servers
->number_of_hosts
= count
;
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
75 memcached_return_t
memcached_server_cursor(memcached_st
*ptr
,
76 memcached_server_fn
*callback
,
78 uint32_t number_of_callbacks
);
81 memcached_server_st
*memcached_server_by_key(memcached_st
*ptr
,
84 memcached_return_t
*error
);
87 const char *memcached_server_error(memcached_server_st
*ptr
);
90 void memcached_server_error_reset(memcached_server_st
*ptr
);
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 */
97 memcached_server_st
*memcached_server_create_with(const memcached_st
*memc
,
98 memcached_server_st
*host
,
102 memcached_connection_t type
);
105 void memcached_server_free(memcached_server_st
*ptr
);
108 memcached_server_st
*memcached_server_clone(memcached_server_st
*clone
,
109 memcached_server_st
*ptr
);
112 memcached_return_t
memcached_server_remove(memcached_server_st
*st_ptr
);
115 memcached_server_st
*memcached_server_get_last_disconnect(memcached_st
*ptr
);
119 memcached_return_t
memcached_server_add_udp(memcached_st
*ptr
,
120 const char *hostname
,
123 memcached_return_t
memcached_server_add_unix_socket(memcached_st
*ptr
,
124 const char *filename
);
126 memcached_return_t
memcached_server_add(memcached_st
*ptr
,
127 const char *hostname
, in_port_t port
);
130 memcached_return_t
memcached_server_add_udp_with_weight(memcached_st
*ptr
,
131 const char *hostname
,
135 memcached_return_t
memcached_server_add_unix_socket_with_weight(memcached_st
*ptr
,
136 const char *filename
,
139 memcached_return_t
memcached_server_add_with_weight(memcached_st
*ptr
, const char *hostname
,
142 /* Server List Public functions */
145 void memcached_server_list_free(memcached_server_st
*ptr
);
149 memcached_return_t
memcached_server_push(memcached_st
*ptr
, memcached_server_st
*list
);
152 memcached_server_st
*memcached_server_list_append(memcached_server_st
*ptr
,
153 const char *hostname
,
155 memcached_return_t
*error
);
157 memcached_server_st
*memcached_server_list_append_with_weight(memcached_server_st
*ptr
,
158 const char *hostname
,
161 memcached_return_t
*error
);
163 unsigned int memcached_server_list_count(memcached_server_st
*ptr
);
170 #endif /* __MEMCACHED_SERVER_H__ */