Fixed a typo that was causing a race condition error.
[awesomized/libmemcached] / libmemcached / util / version.c
1 /* LibMemcached
2 * Copyright (C) 2010 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary: connect to all hosts, and make sure they meet a minimum version
9 *
10 */
11
12 /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
13 #include "libmemcached/common.h"
14 #include "libmemcached/memcached_util.h"
15
16 struct local_context
17 {
18 uint8_t major_version;
19 uint8_t minor_version;
20 uint8_t micro_version;
21
22 bool truth;
23 };
24
25 static memcached_return_t check_server_version(const memcached_st *ptr __attribute__((unused)),
26 const memcached_server_st *instance,
27 void *context)
28 {
29 /* Do Nothing */
30 struct local_context *check= (struct local_context *)context;
31
32 if (instance->major_version >= check->major_version &&
33 instance->minor_version >= check->minor_version &&
34 instance->micro_version >= check->micro_version )
35 {
36 return MEMCACHED_SUCCESS;
37 }
38
39 check->truth= false;
40
41 return MEMCACHED_FAILURE;
42 }
43
44 bool libmemcached_util_version_check(memcached_st *memc,
45 uint8_t major_version,
46 uint8_t minor_version,
47 uint8_t micro_version)
48 {
49 memcached_server_fn callbacks[1];
50 memcached_version(memc);
51
52 struct local_context check= { .major_version= major_version, .minor_version= minor_version, .micro_version= micro_version, .truth= true };
53
54 callbacks[0]= check_server_version;
55 memcached_server_cursor(memc, callbacks, (void *)&check, 1);
56
57 return check.truth;
58 }