3
#include <sys/socket.h>
4
#include <netinet/tcp.h>
7
This function is used to modify the behabior of running client.
9
We quit all connections so we can reset the sockets.
12
static void set_behavior_flag(gearman_st *ptr, gearman_flags temp_flag, uint64_t data)
15
ptr->flags|= temp_flag;
17
ptr->flags&= ~temp_flag;
20
gearman_return gearman_behavior_set(gearman_st *ptr,
21
gearman_behavior flag,
26
case GEARMAN_BEHAVIOR_SUPPORT_CAS:
27
set_behavior_flag(ptr, GEAR_SUPPORT_CAS, data);
29
case GEARMAN_BEHAVIOR_NO_BLOCK:
30
set_behavior_flag(ptr, GEAR_NO_BLOCK, data);
32
case GEARMAN_BEHAVIOR_BUFFER_REQUESTS:
33
set_behavior_flag(ptr, GEAR_BUFFER_REQUESTS, data);
36
case GEARMAN_BEHAVIOR_TCP_NODELAY:
37
set_behavior_flag(ptr, GEAR_TCP_NODELAY, data);
40
case GEARMAN_BEHAVIOR_DISTRIBUTION:
41
ptr->distribution= (gearman_server_distribution)(data);
43
case GEARMAN_BEHAVIOR_HASH:
44
ptr->hash= (gearman_hash)(data);
46
case GEARMAN_BEHAVIOR_CACHE_LOOKUPS:
47
set_behavior_flag(ptr, GEAR_USE_CACHE_LOOKUPS, data);
50
case GEARMAN_BEHAVIOR_VERIFY_KEY:
51
set_behavior_flag(ptr, GEAR_VERIFY_KEY, data);
53
case GEARMAN_BEHAVIOR_KETAMA:
54
set_behavior_flag(ptr, GEAR_USE_KETAMA, data);
56
case GEARMAN_BEHAVIOR_SORT_HOSTS:
57
set_behavior_flag(ptr, GEAR_USE_SORT_HOSTS, data);
59
case GEARMAN_BEHAVIOR_POLL_TIMEOUT:
60
ptr->poll_timeout= (int32_t)data;
62
case GEARMAN_BEHAVIOR_CONNECT_TIMEOUT:
63
ptr->connect_timeout= (int32_t)data;
65
case GEARMAN_BEHAVIOR_RETRY_TIMEOUT:
66
ptr->retry_timeout= (int32_t)data;
68
case GEARMAN_BEHAVIOR_SOCKET_SEND_SIZE:
69
ptr->send_size= (int32_t)data;
72
case GEARMAN_BEHAVIOR_SOCKET_RECV_SIZE:
73
ptr->recv_size= (int32_t)data;
76
case GEARMAN_BEHAVIOR_USER_DATA:
77
return GEARMAN_FAILURE;
80
return GEARMAN_SUCCESS;
83
uint64_t gearman_behavior_get(gearman_st *ptr,
84
gearman_behavior flag)
86
gearman_flags temp_flag= 0;
90
case GEARMAN_BEHAVIOR_SUPPORT_CAS:
91
temp_flag= GEAR_SUPPORT_CAS;
93
case GEARMAN_BEHAVIOR_CACHE_LOOKUPS:
94
temp_flag= GEAR_USE_CACHE_LOOKUPS;
96
case GEARMAN_BEHAVIOR_NO_BLOCK:
97
temp_flag= GEAR_NO_BLOCK;
99
case GEARMAN_BEHAVIOR_BUFFER_REQUESTS:
100
temp_flag= GEAR_BUFFER_REQUESTS;
102
case GEARMAN_BEHAVIOR_TCP_NODELAY:
103
temp_flag= GEAR_TCP_NODELAY;
105
case GEARMAN_BEHAVIOR_VERIFY_KEY:
106
temp_flag= GEAR_VERIFY_KEY;
108
case GEARMAN_BEHAVIOR_DISTRIBUTION:
109
return ptr->distribution;
110
case GEARMAN_BEHAVIOR_HASH:
112
case GEARMAN_BEHAVIOR_KETAMA:
113
temp_flag= GEAR_USE_KETAMA;
115
case GEARMAN_BEHAVIOR_SORT_HOSTS:
116
temp_flag= GEAR_USE_SORT_HOSTS;
118
case GEARMAN_BEHAVIOR_POLL_TIMEOUT:
120
return (unsigned long long)ptr->poll_timeout;
122
case GEARMAN_BEHAVIOR_CONNECT_TIMEOUT:
124
return (unsigned long long)ptr->connect_timeout;
126
case GEARMAN_BEHAVIOR_RETRY_TIMEOUT:
128
return (unsigned long long)ptr->retry_timeout;
130
case GEARMAN_BEHAVIOR_SOCKET_SEND_SIZE:
133
socklen_t sock_length= sizeof(int);
136
/* We just try the first host, and if it is down we return zero */
137
if ((gearman_connect(&ptr->hosts[0])) != GEARMAN_SUCCESS)
140
if (getsockopt(ptr->hosts[0].fd, SOL_SOCKET,
141
SO_SNDBUF, &sock_size, &sock_length))
142
return 0; /* Zero means error */
146
case GEARMAN_BEHAVIOR_SOCKET_RECV_SIZE:
149
socklen_t sock_length= sizeof(int);
152
/* We just try the first host, and if it is down we return zero */
153
if ((gearman_connect(&ptr->hosts[0])) != GEARMAN_SUCCESS)
156
if (getsockopt(ptr->hosts[0].fd, SOL_SOCKET,
157
SO_RCVBUF, &sock_size, &sock_length))
158
return 0; /* Zero means error */
162
case GEARMAN_BEHAVIOR_USER_DATA:
163
return GEARMAN_FAILURE;
166
WATCHPOINT_ASSERT(temp_flag); /* Programming mistake if it gets this far */
167
if (ptr->flags & temp_flag)
172
return GEARMAN_SUCCESS;