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 +--------------------------------------------------------------------+
18 #include "p9y/gettimeofday.hpp"
22 memcached_server_st *server_create_with(memcached_st *memc, memcached_server_st *self,
23 const memcached_string_t &hostname, const in_port_t port,
24 uint32_t weight, const memcached_connection_t type);
26 memcached_return_t memcached_server_add_parsed(memcached_st *ptr, const char *hostname,
27 size_t hostname_length, in_port_t port,
30 void server_free(memcached_server_st *);
32 static inline bool memcached_is_valid_servername(const memcached_string_t &arg) {
33 return (arg.c_str != NULL or arg.size == 0) and arg.size < MEMCACHED_NI_MAXHOST;
36 static inline bool memcached_is_valid_filename(const memcached_string_t &arg) {
37 return arg.c_str != NULL and arg.size > 0 and arg.size < MEMCACHED_NI_MAXHOST;
40 void memcached_instance_free(memcached_instance_st *);
42 void set_last_disconnected_host(memcached_instance_st *self);
44 static inline void memcached_mark_server_for_timeout(memcached_instance_st *server) {
45 if (server->state != MEMCACHED_SERVER_STATE_IN_TIMEOUT) {
46 if (server->server_timeout_counter_query_id != server->root->query_id) {
47 server->server_timeout_counter++;
48 server->server_timeout_counter_query_id = server->root->query_id;
51 if (server->server_timeout_counter >= server->root->server_timeout_limit) {
52 struct timeval next_time;
53 if (gettimeofday(&next_time, NULL) == 0) {
54 server->next_retry = next_time.tv_sec + server->root->retry_timeout;
56 server->next_retry = 1; // Setting the value to 1 causes the timeout to occur immediately
59 server->state = MEMCACHED_SERVER_STATE_IN_TIMEOUT;
60 if (server->server_failure_counter_query_id != server->root->query_id) {
61 server->server_failure_counter++;
62 server->server_failure_counter_query_id = server->root->query_id;
64 set_last_disconnected_host(server);