7149e276332252803f8ee35cb89114374494714f
[awesomized/libmemcached] / lib / memcached_callback.c
1 #include "common.h"
2 #include <sys/types.h>
3 #include <sys/socket.h>
4 #include <netinet/tcp.h>
5
6 /*
7 These functions provide data and function callback support
8 */
9
10 memcached_return memcached_callback_set(memcached_st *ptr,
11 memcached_callback flag,
12 void *data)
13 {
14 switch (flag)
15 {
16 case MEMCACHED_CALLBACK_USER_DATA:
17 {
18 ptr->user_data= data;
19 break;
20 }
21 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION:
22 {
23 cleanup_func func= (cleanup_func)data;
24 ptr->on_cleanup= func;
25 break;
26 }
27 case MEMCACHED_CALLBACK_CLONE_FUNCTION:
28 {
29 clone_func func= (clone_func)data;
30 ptr->on_clone= func;
31 break;
32 }
33 default:
34 return MEMCACHED_FAILURE;
35 }
36
37 return MEMCACHED_SUCCESS;
38 }
39
40 void *memcached_callback_get(memcached_st *ptr,
41 memcached_callback flag,
42 memcached_return *error)
43 {
44 switch (flag)
45 {
46 case MEMCACHED_CALLBACK_USER_DATA:
47 {
48 *error= ptr->user_data ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
49 return (void *)ptr->user_data;
50 }
51 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION:
52 {
53 *error= ptr->on_cleanup ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
54 return (void *)ptr->on_cleanup;
55 }
56 case MEMCACHED_CALLBACK_CLONE_FUNCTION:
57 {
58 *error= ptr->on_clone ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
59 return (void *)ptr->on_clone;
60 }
61 default:
62 WATCHPOINT_ASSERT(0);
63 *error= MEMCACHED_FAILURE;
64 return NULL;
65 }
66 }