ci: sr.ht: fix git ref
[m6w6/libmemcached] / test / fixtures / callbacks.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 #include "test/lib/common.hpp"
19 #include "libmemcached/common.h"
20 #include "libmemcachedutil/common.h"
21
22 static inline memcached_return_t ping_callback(const memcached_st *,
23 const memcached_instance_st *instance, void *) {
24 memcached_return_t rc;
25
26 REQUIRE(libmemcached_util_ping(memcached_server_name(instance), memcached_server_port(instance),
27 &rc));
28 REQUIRE(rc == MEMCACHED_SUCCESS);
29 return MEMCACHED_SUCCESS;
30 }
31
32 static inline memcached_return_t ping2_callback(const memcached_st *,
33 const memcached_instance_st *instance, void *) {
34 memcached_return_t rc;
35
36 REQUIRE(libmemcached_util_ping2(memcached_server_name(instance), memcached_server_port(instance),
37 "memcached", "memcached", &rc));
38 REQUIRE(rc == MEMCACHED_SUCCESS);
39 return MEMCACHED_SUCCESS;
40 }
41
42 static inline memcached_return_t callback_counter(const memcached_st *, memcached_result_st *,
43 void *context) {
44 auto *counter = reinterpret_cast<size_t *>(context);
45 *counter = *counter + 1;
46
47 return MEMCACHED_SUCCESS;
48 }
49
50 static inline memcached_return_t delete_trigger(memcached_st *, const char *, size_t) {
51 return MEMCACHED_SUCCESS;
52 }
53
54 static inline memcached_return_t get_failure(memcached_st *, char *, size_t,
55 memcached_result_st *result) {
56 return memcached_result_set_value(result, S("updated by read through trigger"));
57 }
58
59 static inline memcached_return_t clone_callback(memcached_st *, memcached_st *) {
60 return MEMCACHED_SUCCESS;
61 }
62
63 static inline memcached_return_t cleanup_callback(memcached_st *) {
64 return MEMCACHED_SUCCESS;
65 }
66
67 static inline memcached_return_t
68 server_sort_callback(const memcached_st *, const memcached_instance_st *server, void *context) {
69 if (context) {
70 auto bigger = reinterpret_cast<size_t *>(context);
71 REQUIRE(*bigger <= memcached_server_port(server));
72 *bigger = memcached_server_port(server);
73 }
74 return MEMCACHED_SUCCESS;
75 }