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