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 #ifdef HAVE_SYS_TIME_H
19 # include <sys/time.h>
24 memcached_server_st *__server_create_with(memcached_st *memc, memcached_server_st *self,
25 const memcached_string_t &hostname, const in_port_t port,
26 uint32_t weight, const memcached_connection_t type);
28 memcached_return_t memcached_server_add_parsed(memcached_st *ptr, const char *hostname,
29 size_t hostname_length, in_port_t port,
32 void __server_free(memcached_server_st *);
34 static inline bool memcached_is_valid_servername(const memcached_string_t &arg) {
35 return (arg.c_str != NULL or arg.size == 0) and arg.size < MEMCACHED_NI_MAXHOST;
38 static inline bool memcached_is_valid_filename(const memcached_string_t &arg) {
39 return arg.c_str != NULL and arg.size > 0 and arg.size < MEMCACHED_NI_MAXHOST;
42 void memcached_instance_free(memcached_instance_st *);
44 void set_last_disconnected_host(memcached_instance_st *self);
46 static inline void memcached_mark_server_for_timeout(memcached_instance_st *server) {
47 if (server->state != MEMCACHED_SERVER_STATE_IN_TIMEOUT) {
48 if (server->server_timeout_counter_query_id != server->root->query_id) {
49 server->server_timeout_counter++;
50 server->server_timeout_counter_query_id = server->root->query_id;
53 if (server->server_timeout_counter >= server->root->server_timeout_limit) {
54 struct timeval next_time;
55 if (gettimeofday(&next_time, NULL) == 0) {
56 server->next_retry = next_time.tv_sec + server->root->retry_timeout;
58 server->next_retry = 1; // Setting the value to 1 causes the timeout to occur immediately
61 server->state = MEMCACHED_SERVER_STATE_IN_TIMEOUT;
62 if (server->server_failure_counter_query_id != server->root->query_id) {
63 server->server_failure_counter++;
64 server->server_failure_counter_query_id = server->root->query_id;
66 set_last_disconnected_host(server);