Created a bigger buffer for write/read.
[m6w6/libmemcached] / lib / memcached_behavior.c
1 #include "common.h"
2 #include <sys/types.h>
3 #include <sys/socket.h>
4 #include <netinet/tcp.h>
5
6 /*
7 This function is used to modify the behabior of running client.
8
9 We quit all connections so we can reset the sockets.
10 */
11
12 void set_behavior_flag(memcached_st *ptr, memcached_flags temp_flag, void *data)
13 {
14 unsigned int *truefalse= (unsigned int *)data;
15
16 memcached_quit(ptr);
17 if (truefalse)
18 ptr->flags|= temp_flag;
19 else
20 ptr->flags+= temp_flag;
21 }
22
23 memcached_return memcached_behavior_set(memcached_st *ptr,
24 memcached_behavior flag,
25 void *data)
26 {
27 switch (flag)
28 {
29 case MEMCACHED_BEHAVIOR_NO_BLOCK:
30 set_behavior_flag(ptr, MEM_NO_BLOCK, data);
31 break;
32 case MEMCACHED_BEHAVIOR_TCP_NODELAY:
33 set_behavior_flag(ptr, MEM_TCP_NODELAY, data);
34 break;
35 case MEMCACHED_BEHAVIOR_MD5_HASHING:
36 set_behavior_flag(ptr, MEM_USE_MD5, data);
37 break;
38 case MEMCACHED_BEHAVIOR_KETAMA:
39 set_behavior_flag(ptr, MEM_USE_KETAMA, data);
40 break;
41 }
42
43 return MEMCACHED_SUCCESS;
44 }
45
46 unsigned long long memcached_behavior_get(memcached_st *ptr,
47 memcached_behavior flag)
48 {
49 memcached_flags temp_flag;
50
51 switch (flag)
52 {
53 case MEMCACHED_BEHAVIOR_NO_BLOCK:
54 temp_flag= MEM_NO_BLOCK;
55 break;
56 case MEMCACHED_BEHAVIOR_TCP_NODELAY:
57 temp_flag= MEM_TCP_NODELAY;
58 break;
59 case MEMCACHED_BEHAVIOR_MD5_HASHING:
60 temp_flag= MEM_USE_MD5;
61 break;
62 case MEMCACHED_BEHAVIOR_KETAMA:
63 temp_flag= MEM_USE_KETAMA;
64 break;
65 }
66
67 if (ptr->flags & temp_flag)
68 return 1;
69 else
70 return 0;
71
72 return MEMCACHED_SUCCESS;
73 }