1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
#include "common.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
/*
This function is used to modify the behabior of running client.
We quit all connections so we can reset the sockets.
*/
static void set_behavior_flag(gearman_st *ptr, gearman_flags temp_flag, uint64_t data)
{
if (data)
ptr->flags|= temp_flag;
else
ptr->flags&= ~temp_flag;
}
gearman_return gearman_behavior_set(gearman_st *ptr,
gearman_behavior flag,
uint64_t data)
{
switch (flag)
{
case GEARMAN_BEHAVIOR_SUPPORT_CAS:
set_behavior_flag(ptr, GEAR_SUPPORT_CAS, data);
break;
case GEARMAN_BEHAVIOR_NO_BLOCK:
set_behavior_flag(ptr, GEAR_NO_BLOCK, data);
gearman_quit(ptr);
case GEARMAN_BEHAVIOR_BUFFER_REQUESTS:
set_behavior_flag(ptr, GEAR_BUFFER_REQUESTS, data);
gearman_quit(ptr);
break;
case GEARMAN_BEHAVIOR_TCP_NODELAY:
set_behavior_flag(ptr, GEAR_TCP_NODELAY, data);
gearman_quit(ptr);
break;
case GEARMAN_BEHAVIOR_DISTRIBUTION:
ptr->distribution= (gearman_server_distribution)(data);
break;
case GEARMAN_BEHAVIOR_HASH:
ptr->hash= (gearman_hash)(data);
break;
case GEARMAN_BEHAVIOR_CACHE_LOOKUPS:
set_behavior_flag(ptr, GEAR_USE_CACHE_LOOKUPS, data);
gearman_quit(ptr);
break;
case GEARMAN_BEHAVIOR_VERIFY_KEY:
set_behavior_flag(ptr, GEAR_VERIFY_KEY, data);
break;
case GEARMAN_BEHAVIOR_KETAMA:
set_behavior_flag(ptr, GEAR_USE_KETAMA, data);
break;
case GEARMAN_BEHAVIOR_SORT_HOSTS:
set_behavior_flag(ptr, GEAR_USE_SORT_HOSTS, data);
break;
case GEARMAN_BEHAVIOR_POLL_TIMEOUT:
ptr->poll_timeout= (int32_t)data;
break;
case GEARMAN_BEHAVIOR_CONNECT_TIMEOUT:
ptr->connect_timeout= (int32_t)data;
break;
case GEARMAN_BEHAVIOR_RETRY_TIMEOUT:
ptr->retry_timeout= (int32_t)data;
break;
case GEARMAN_BEHAVIOR_SOCKET_SEND_SIZE:
ptr->send_size= (int32_t)data;
gearman_quit(ptr);
break;
case GEARMAN_BEHAVIOR_SOCKET_RECV_SIZE:
ptr->recv_size= (int32_t)data;
gearman_quit(ptr);
break;
case GEARMAN_BEHAVIOR_USER_DATA:
return GEARMAN_FAILURE;
}
return GEARMAN_SUCCESS;
}
uint64_t gearman_behavior_get(gearman_st *ptr,
gearman_behavior flag)
{
gearman_flags temp_flag= 0;
switch (flag)
{
case GEARMAN_BEHAVIOR_SUPPORT_CAS:
temp_flag= GEAR_SUPPORT_CAS;
break;
case GEARMAN_BEHAVIOR_CACHE_LOOKUPS:
temp_flag= GEAR_USE_CACHE_LOOKUPS;
break;
case GEARMAN_BEHAVIOR_NO_BLOCK:
temp_flag= GEAR_NO_BLOCK;
break;
case GEARMAN_BEHAVIOR_BUFFER_REQUESTS:
temp_flag= GEAR_BUFFER_REQUESTS;
break;
case GEARMAN_BEHAVIOR_TCP_NODELAY:
temp_flag= GEAR_TCP_NODELAY;
break;
case GEARMAN_BEHAVIOR_VERIFY_KEY:
temp_flag= GEAR_VERIFY_KEY;
break;
case GEARMAN_BEHAVIOR_DISTRIBUTION:
return ptr->distribution;
case GEARMAN_BEHAVIOR_HASH:
return ptr->hash;
case GEARMAN_BEHAVIOR_KETAMA:
temp_flag= GEAR_USE_KETAMA;
break;
case GEARMAN_BEHAVIOR_SORT_HOSTS:
temp_flag= GEAR_USE_SORT_HOSTS;
break;
case GEARMAN_BEHAVIOR_POLL_TIMEOUT:
{
return (unsigned long long)ptr->poll_timeout;
}
case GEARMAN_BEHAVIOR_CONNECT_TIMEOUT:
{
return (unsigned long long)ptr->connect_timeout;
}
case GEARMAN_BEHAVIOR_RETRY_TIMEOUT:
{
return (unsigned long long)ptr->retry_timeout;
}
case GEARMAN_BEHAVIOR_SOCKET_SEND_SIZE:
{
int sock_size;
socklen_t sock_length= sizeof(int);
/* REFACTOR */
/* We just try the first host, and if it is down we return zero */
if ((gearman_connect(&ptr->hosts[0])) != GEARMAN_SUCCESS)
return 0;
if (getsockopt(ptr->hosts[0].fd, SOL_SOCKET,
SO_SNDBUF, &sock_size, &sock_length))
return 0; /* Zero means error */
return sock_size;
}
case GEARMAN_BEHAVIOR_SOCKET_RECV_SIZE:
{
int sock_size;
socklen_t sock_length= sizeof(int);
/* REFACTOR */
/* We just try the first host, and if it is down we return zero */
if ((gearman_connect(&ptr->hosts[0])) != GEARMAN_SUCCESS)
return 0;
if (getsockopt(ptr->hosts[0].fd, SOL_SOCKET,
SO_RCVBUF, &sock_size, &sock_length))
return 0; /* Zero means error */
return sock_size;
}
case GEARMAN_BEHAVIOR_USER_DATA:
return GEARMAN_FAILURE;
}
WATCHPOINT_ASSERT(temp_flag); /* Programming mistake if it gets this far */
if (ptr->flags & temp_flag)
return 1;
else
return 0;
return GEARMAN_SUCCESS;
}
|