C++: double underscores are reserved
[m6w6/libmemcached] / src / libmemcached / instance.hpp
1 /*
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
14 */
15
16 #pragma once
17
18 #ifndef WIN32
19 # ifdef HAVE_NETDB_H
20 # include <netdb.h>
21 # endif
22 #endif
23
24 #ifdef NI_MAXHOST
25 # define MEMCACHED_NI_MAXHOST NI_MAXHOST
26 #else
27 # define MEMCACHED_NI_MAXHOST 1025
28 #endif
29
30 #ifdef NI_MAXSERV
31 # define MEMCACHED_NI_MAXSERV NI_MAXSERV
32 #else
33 # define MEMCACHED_NI_MAXSERV 32
34 #endif
35
36 #include "libmemcached/string.hpp"
37
38 // @todo Complete class transformation
39 struct memcached_instance_st {
40 in_port_t port() const { return port_; }
41
42 void port(in_port_t arg) { port_ = arg; }
43
44 void mark_server_as_clean() {
45 server_failure_counter = 0;
46 server_timeout_counter = 0;
47 next_retry = 0;
48 }
49
50 void disable() {}
51
52 void enable() {}
53
54 bool valid() const;
55
56 bool is_shutting_down() const;
57
58 void start_close_socket();
59 void close_socket();
60 void reset_socket();
61
62 uint32_t response_count() const { return cursor_active_; }
63
64 struct {
65 bool is_allocated;
66 bool is_initialized;
67 bool is_shutting_down;
68 bool is_dead;
69 bool ready;
70 } options;
71
72 short _events;
73 short _revents;
74
75 short events(void) { return _events; }
76
77 short revents(void) { return _revents; }
78
79 const char *hostname() { return _hostname; }
80
81 void hostname(const memcached_string_t &hostname_) {
82 if (hostname_.size) {
83 memcpy(_hostname, hostname_.c_str, hostname_.size);
84 _hostname[hostname_.size] = 0;
85 } else {
86 memcpy(_hostname, memcached_literal_param("localhost"));
87 _hostname[memcached_literal_param_size("localhost")] = 0;
88 }
89 }
90
91 void events(short);
92 void revents(short);
93
94 uint32_t cursor_active_;
95 in_port_t port_;
96 memcached_socket_t fd;
97 uint32_t io_bytes_sent; /* # bytes sent since last read */
98 uint32_t request_id;
99 uint32_t server_failure_counter;
100 uint64_t server_failure_counter_query_id;
101 uint32_t server_timeout_counter;
102 uint64_t server_timeout_counter_query_id;
103 uint32_t weight;
104 uint32_t version;
105 enum memcached_server_state_t state;
106 struct {
107 uint32_t read;
108 uint32_t write;
109 uint32_t timeouts;
110 size_t _bytes_read;
111 } io_wait_count;
112 uint8_t major_version; // Default definition of UINT8_MAX means that it has not been set.
113 uint8_t micro_version; // ditto, and note that this is the third, not second version bit
114 uint8_t minor_version; // ditto
115 memcached_connection_t type;
116 char *read_ptr;
117 size_t read_buffer_length;
118 size_t write_buffer_offset;
119 struct addrinfo *address_info;
120 struct addrinfo *address_info_next;
121 time_t next_retry;
122 struct memcached_st *root;
123 uint64_t limit_maxbytes;
124 struct memcached_error_t *error_messages;
125 char read_buffer[MEMCACHED_MAX_BUFFER];
126 char write_buffer[MEMCACHED_MAX_BUFFER];
127 char _hostname[MEMCACHED_NI_MAXHOST];
128
129 void clear_addrinfo() {
130 if (address_info) {
131 freeaddrinfo(address_info);
132 address_info = NULL;
133 address_info_next = NULL;
134 }
135 }
136 };
137
138 memcached_instance_st *instance_create_with(memcached_st *memc, memcached_instance_st *self,
139 const memcached_string_t &_hostname,
140 const in_port_t port, uint32_t weight,
141 const memcached_connection_t type);
142
143 memcached_return_t memcached_instance_push(memcached_st *ptr, const memcached_instance_st *,
144 uint32_t);
145
146 void instance_free(memcached_instance_st *);