don't convert between 16 and 32 bit when you don't need to
[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 uint8_t major_version;
33 uint8_t micro_version;
34 uint8_t minor_version;
35 memcached_connection_t type;
36 char *read_ptr;
37 char *cached_server_error;
38 size_t read_buffer_length;
39 size_t read_data_length;
40 size_t write_buffer_offset;
41 struct addrinfo *address_info;
42 time_t next_retry;
43 memcached_st *root;
44 uint64_t limit_maxbytes;
45 char read_buffer[MEMCACHED_MAX_BUFFER];
46 char write_buffer[MEMCACHED_MAX_BUFFER];
47 char hostname[MEMCACHED_MAX_HOST_LENGTH];
48 };
49
50 static inline uint32_t memcached_servers_count(memcached_server_st *servers)
51 {
52 return servers->number_of_hosts;
53 }
54
55 static inline uint32_t memcached_servers_set_count(memcached_server_st *servers, uint32_t count)
56 {
57 return servers->number_of_hosts= count;
58 }
59
60 #define memcached_server_count(A) (A)->number_of_hosts
61 #define memcached_server_name(A,B) (B).hostname
62 #define memcached_server_port(A,B) (B).port
63 #define memcached_server_list(A) (A)->hosts
64 #define memcached_server_response_count(A) (A)->cursor_active
65
66 LIBMEMCACHED_API
67 memcached_return_t memcached_server_cursor(memcached_st *ptr,
68 memcached_server_fn *callback,
69 void *context,
70 uint32_t number_of_callbacks);
71
72 LIBMEMCACHED_API
73 memcached_server_st *memcached_server_by_key(memcached_st *ptr,
74 const char *key,
75 size_t key_length,
76 memcached_return_t *error);
77
78 LIBMEMCACHED_API
79 const char *memcached_server_error(memcached_server_st *ptr);
80
81 LIBMEMCACHED_API
82 void memcached_server_error_reset(memcached_server_st *ptr);
83
84 /* These should not currently be used by end users */
85 /* TODO: Is the above comment valid? If so, how can we unit test these if they
86 * aren't exported. If not, we should remove the comment */
87 LIBMEMCACHED_API
88 memcached_server_st *memcached_server_create(memcached_st *memc, memcached_server_st *ptr);
89
90 LIBMEMCACHED_API
91 memcached_server_st *memcached_server_create_with(memcached_st *memc,
92 memcached_server_st *host,
93 const char *hostname,
94 in_port_t port,
95 uint32_t weight,
96 memcached_connection_t type);
97
98 LIBMEMCACHED_API
99 void memcached_server_free(memcached_server_st *ptr);
100
101 LIBMEMCACHED_API
102 memcached_server_st *memcached_server_clone(memcached_server_st *clone,
103 memcached_server_st *ptr);
104
105 LIBMEMCACHED_API
106 memcached_return_t memcached_server_remove(memcached_server_st *st_ptr);
107
108 LIBMEMCACHED_API
109 memcached_server_st *memcached_server_get_last_disconnect(memcached_st *ptr);
110
111 #ifdef __cplusplus
112 }
113 #endif
114
115 #endif /* __MEMCACHED_SERVER_H__ */