Updates for CORK.
[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 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 LIBMEMCACHED_LOCAL
96 memcached_server_st *memcached_server_create(memcached_st *memc, memcached_server_st *ptr);
97
98 LIBMEMCACHED_LOCAL
99 memcached_server_st *memcached_server_create_with(memcached_st *memc,
100 memcached_server_st *host,
101 const char *hostname,
102 in_port_t port,
103 uint32_t weight,
104 memcached_connection_t type);
105
106 LIBMEMCACHED_API
107 void memcached_server_free(memcached_server_st *ptr);
108
109 LIBMEMCACHED_LOCAL
110 memcached_server_st *memcached_server_clone(memcached_server_st *clone,
111 memcached_server_st *ptr);
112
113 LIBMEMCACHED_API
114 memcached_return_t memcached_server_remove(memcached_server_st *st_ptr);
115
116 LIBMEMCACHED_API
117 memcached_server_st *memcached_server_get_last_disconnect(memcached_st *ptr);
118
119 #ifdef __cplusplus
120 }
121 #endif
122
123 #endif /* __MEMCACHED_SERVER_H__ */