Merge lp:~brianaker/gearmand/ref-client-fix into lp:gearmand
- ref-client-fix
- Merge into 1.2
Proposed by
Brian Aker
Status: | Merged |
---|---|
Merged at revision: | 811 |
Proposed branch: | lp:~brianaker/gearmand/ref-client-fix |
Merge into: | lp:gearmand |
Diff against target: |
1247 lines (+290/-251) (has conflicts) 7 files modified
libgearman/actions.cc (+3/-3) libgearman/add.cc (+24/-25) libgearman/client.cc (+210/-199) libgearman/interface/task.hpp (+3/-3) libgearman/run.cc (+37/-13) libgearman/task.cc (+11/-8) libgearman/task.hpp (+2/-0) Text conflict in libgearman/run.cc |
To merge this branch: | bzr merge lp:~brianaker/gearmand/ref-client-fix |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tangent Trunk | Pending | ||
Review via email: mp+173325@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'libgearman/actions.cc' | |||
2 | --- libgearman/actions.cc 2013-07-06 08:02:19 +0000 | |||
3 | +++ libgearman/actions.cc 2013-07-06 19:18:28 +0000 | |||
4 | @@ -68,7 +68,7 @@ | |||
5 | 68 | { | 68 | { |
6 | 69 | if (task->create_result(gearman_task_data_size(shell)) == false) | 69 | if (task->create_result(gearman_task_data_size(shell)) == false) |
7 | 70 | { | 70 | { |
9 | 71 | return gearman_error(task->client->impl()->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Failed to create result_st"); | 71 | return gearman_error(task->client->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Failed to create result_st"); |
10 | 72 | } | 72 | } |
11 | 73 | } | 73 | } |
12 | 74 | assert_msg(task->result(), "programmer error, result_ptr has not been allocated for task"); | 74 | assert_msg(task->result(), "programmer error, result_ptr has not been allocated for task"); |
13 | @@ -137,7 +137,7 @@ | |||
14 | 137 | { | 137 | { |
15 | 138 | if (task->create_result(gearman_task_data_size(shell)) == false) | 138 | if (task->create_result(gearman_task_data_size(shell)) == false) |
16 | 139 | { | 139 | { |
18 | 140 | return gearman_error(task->client->impl()->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Failed to create result_st"); | 140 | return gearman_error(task->client->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Failed to create result_st"); |
19 | 141 | } | 141 | } |
20 | 142 | } | 142 | } |
21 | 143 | 143 | ||
22 | @@ -158,7 +158,7 @@ | |||
23 | 158 | { | 158 | { |
24 | 159 | if (task->create_result(gearman_task_data_size(shell)) == false) | 159 | if (task->create_result(gearman_task_data_size(shell)) == false) |
25 | 160 | { | 160 | { |
27 | 161 | return gearman_error(task->client->impl()->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Failed to create result_st"); | 161 | return gearman_error(task->client->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Failed to create result_st"); |
28 | 162 | } | 162 | } |
29 | 163 | } | 163 | } |
30 | 164 | 164 | ||
31 | 165 | 165 | ||
32 | === modified file 'libgearman/add.cc' | |||
33 | --- libgearman/add.cc 2013-07-03 09:00:14 +0000 | |||
34 | +++ libgearman/add.cc 2013-07-06 19:18:28 +0000 | |||
35 | @@ -202,7 +202,6 @@ | |||
36 | 202 | return NULL; | 202 | return NULL; |
37 | 203 | } | 203 | } |
38 | 204 | assert(task_shell->impl()->client); | 204 | assert(task_shell->impl()->client); |
39 | 205 | assert(task_shell->impl()->client == &client); | ||
40 | 206 | 205 | ||
41 | 207 | Task* task= task_shell->impl(); | 206 | Task* task= task_shell->impl(); |
42 | 208 | 207 | ||
43 | @@ -229,7 +228,7 @@ | |||
44 | 229 | { | 228 | { |
45 | 230 | if (safe_uuid_generate(task->unique, task->unique_length) == -1) | 229 | if (safe_uuid_generate(task->unique, task->unique_length) == -1) |
46 | 231 | { | 230 | { |
48 | 232 | gearman_log_debug(task->client->impl()->universal, "uuid_generate_time_safe() failed or does not exist on this platform"); | 231 | gearman_log_debug(task->client->universal, "uuid_generate_time_safe() failed or does not exist on this platform"); |
49 | 233 | } | 232 | } |
50 | 234 | } | 233 | } |
51 | 235 | else | 234 | else |
52 | @@ -242,7 +241,6 @@ | |||
53 | 242 | gearman_unique_t final_unique= gearman_unique_make(task->unique, task->unique_length); | 241 | gearman_unique_t final_unique= gearman_unique_make(task->unique, task->unique_length); |
54 | 243 | 242 | ||
55 | 244 | assert(task->client); | 243 | assert(task->client); |
56 | 245 | assert(task->client == &client); | ||
57 | 246 | 244 | ||
58 | 247 | gearman_return_t rc= GEARMAN_INVALID_ARGUMENT; | 245 | gearman_return_t rc= GEARMAN_INVALID_ARGUMENT; |
59 | 248 | switch (command) | 246 | switch (command) |
60 | @@ -250,7 +248,7 @@ | |||
61 | 250 | case GEARMAN_COMMAND_SUBMIT_JOB: | 248 | case GEARMAN_COMMAND_SUBMIT_JOB: |
62 | 251 | case GEARMAN_COMMAND_SUBMIT_JOB_LOW: | 249 | case GEARMAN_COMMAND_SUBMIT_JOB_LOW: |
63 | 252 | case GEARMAN_COMMAND_SUBMIT_JOB_HIGH: | 250 | case GEARMAN_COMMAND_SUBMIT_JOB_HIGH: |
65 | 253 | rc= libgearman::protocol::submit(task->client->impl()->universal, | 251 | rc= libgearman::protocol::submit(task->client->universal, |
66 | 254 | task->send, | 252 | task->send, |
67 | 255 | final_unique, | 253 | final_unique, |
68 | 256 | command, | 254 | command, |
69 | @@ -259,7 +257,7 @@ | |||
70 | 259 | break; | 257 | break; |
71 | 260 | 258 | ||
72 | 261 | case GEARMAN_COMMAND_SUBMIT_JOB_EPOCH: | 259 | case GEARMAN_COMMAND_SUBMIT_JOB_EPOCH: |
74 | 262 | rc= libgearman::protocol::submit_epoch(task->client->impl()->universal, | 260 | rc= libgearman::protocol::submit_epoch(task->client->universal, |
75 | 263 | task->send, | 261 | task->send, |
76 | 264 | final_unique, | 262 | final_unique, |
77 | 265 | function, | 263 | function, |
78 | @@ -270,7 +268,7 @@ | |||
79 | 270 | case GEARMAN_COMMAND_SUBMIT_JOB_BG: | 268 | case GEARMAN_COMMAND_SUBMIT_JOB_BG: |
80 | 271 | case GEARMAN_COMMAND_SUBMIT_JOB_LOW_BG: | 269 | case GEARMAN_COMMAND_SUBMIT_JOB_LOW_BG: |
81 | 272 | case GEARMAN_COMMAND_SUBMIT_JOB_HIGH_BG: | 270 | case GEARMAN_COMMAND_SUBMIT_JOB_HIGH_BG: |
83 | 273 | rc= libgearman::protocol::submit_background(task->client->impl()->universal, | 271 | rc= libgearman::protocol::submit_background(task->client->universal, |
84 | 274 | task->send, | 272 | task->send, |
85 | 275 | final_unique, | 273 | final_unique, |
86 | 276 | command, | 274 | command, |
87 | @@ -379,15 +377,16 @@ | |||
88 | 379 | return NULL; | 377 | return NULL; |
89 | 380 | } | 378 | } |
90 | 381 | 379 | ||
93 | 382 | gearman_task_st *task= gearman_task_internal_create(*client, NULL); | 380 | gearman_task_st *task_shell= gearman_task_internal_create(*client, NULL); |
94 | 383 | if (task == NULL) | 381 | if (task_shell == NULL) |
95 | 384 | { | 382 | { |
96 | 385 | assert(client->impl()->universal.error_code()); | 383 | assert(client->impl()->universal.error_code()); |
97 | 386 | return NULL; | 384 | return NULL; |
98 | 387 | } | 385 | } |
99 | 388 | 386 | ||
102 | 389 | task->impl()->context= context; | 387 | Task* task= task_shell->impl(); |
103 | 390 | task->impl()->func= actions; | 388 | task->context= context; |
104 | 389 | task->func= actions; | ||
105 | 391 | 390 | ||
106 | 392 | /** | 391 | /** |
107 | 393 | @todo fix it so that NULL is done by default by the API not by happenstance. | 392 | @todo fix it so that NULL is done by default by the API not by happenstance. |
108 | @@ -413,33 +412,33 @@ | |||
109 | 413 | 412 | ||
110 | 414 | if (gearman_unique_is_hash(unique)) | 413 | if (gearman_unique_is_hash(unique)) |
111 | 415 | { | 414 | { |
113 | 416 | task->impl()->unique_length= snprintf(task->impl()->unique, GEARMAN_MAX_UNIQUE_SIZE, "%u", libhashkit_murmur3(gearman_string_param(workload))); | 415 | task->unique_length= snprintf(task->unique, GEARMAN_MAX_UNIQUE_SIZE, "%u", libhashkit_murmur3(gearman_string_param(workload))); |
114 | 417 | } | 416 | } |
116 | 418 | else if ((task->impl()->unique_length= gearman_size(unique))) | 417 | else if ((task->unique_length= gearman_size(unique))) |
117 | 419 | { | 418 | { |
119 | 420 | if (task->impl()->unique_length >= GEARMAN_MAX_UNIQUE_SIZE) | 419 | if (task->unique_length >= GEARMAN_MAX_UNIQUE_SIZE) |
120 | 421 | { | 420 | { |
122 | 422 | task->impl()->unique_length= GEARMAN_MAX_UNIQUE_SIZE -1; // Leave space for NULL byte | 421 | task->unique_length= GEARMAN_MAX_UNIQUE_SIZE -1; // Leave space for NULL byte |
123 | 423 | } | 422 | } |
124 | 424 | 423 | ||
127 | 425 | strncpy(task->impl()->unique, gearman_c_str(unique), GEARMAN_MAX_UNIQUE_SIZE); | 424 | strncpy(task->unique, gearman_c_str(unique), GEARMAN_MAX_UNIQUE_SIZE); |
128 | 426 | task->impl()->unique[task->impl()->unique_length]= 0; | 425 | task->unique[task->unique_length]= 0; |
129 | 427 | } | 426 | } |
130 | 428 | else | 427 | else |
131 | 429 | { | 428 | { |
132 | 430 | if (client->impl()->options.generate_unique or is_background(command)) | 429 | if (client->impl()->options.generate_unique or is_background(command)) |
133 | 431 | { | 430 | { |
135 | 432 | safe_uuid_generate(task->impl()->unique, task->impl()->unique_length); | 431 | safe_uuid_generate(task->unique, task->unique_length); |
136 | 433 | } | 432 | } |
137 | 434 | else | 433 | else |
138 | 435 | { | 434 | { |
141 | 436 | task->impl()->unique_length= 0; | 435 | task->unique_length= 0; |
142 | 437 | task->impl()->unique[0]= 0; | 436 | task->unique[0]= 0; |
143 | 438 | } | 437 | } |
144 | 439 | } | 438 | } |
145 | 440 | 439 | ||
148 | 441 | args[1]= task->impl()->unique; | 440 | args[1]= task->unique; |
149 | 442 | args_size[1]= task->impl()->unique_length +1; // +1 is for the needed null | 441 | args_size[1]= task->unique_length +1; // +1 is for the needed null |
150 | 443 | 442 | ||
151 | 444 | assert_msg(command == GEARMAN_COMMAND_SUBMIT_REDUCE_JOB or command == GEARMAN_COMMAND_SUBMIT_REDUCE_JOB_BACKGROUND, | 443 | assert_msg(command == GEARMAN_COMMAND_SUBMIT_REDUCE_JOB or command == GEARMAN_COMMAND_SUBMIT_REDUCE_JOB_BACKGROUND, |
152 | 445 | "Command was not appropriate for request"); | 444 | "Command was not appropriate for request"); |
153 | @@ -474,14 +473,14 @@ | |||
154 | 474 | args_size[4]= gearman_size(workload); | 473 | args_size[4]= gearman_size(workload); |
155 | 475 | 474 | ||
156 | 476 | gearman_return_t rc; | 475 | gearman_return_t rc; |
158 | 477 | if (gearman_success(rc= gearman_packet_create_args(client->impl()->universal, task->impl()->send, | 476 | if (gearman_success(rc= gearman_packet_create_args(client->impl()->universal, task->send, |
159 | 478 | GEARMAN_MAGIC_REQUEST, command, | 477 | GEARMAN_MAGIC_REQUEST, command, |
160 | 479 | args, args_size, | 478 | args, args_size, |
161 | 480 | 5))) | 479 | 5))) |
162 | 481 | { | 480 | { |
163 | 482 | client->impl()->new_tasks++; | 481 | client->impl()->new_tasks++; |
164 | 483 | client->impl()->running_tasks++; | 482 | client->impl()->running_tasks++; |
166 | 484 | task->impl()->options.send_in_use= true; | 483 | task->options.send_in_use= true; |
167 | 485 | } | 484 | } |
168 | 486 | else | 485 | else |
169 | 487 | { | 486 | { |
170 | @@ -489,7 +488,7 @@ | |||
171 | 489 | gearman_task_free(task); | 488 | gearman_task_free(task); |
172 | 490 | task= NULL; | 489 | task= NULL; |
173 | 491 | } | 490 | } |
175 | 492 | task->impl()->type= GEARMAN_TASK_KIND_EXECUTE; | 491 | task->type= GEARMAN_TASK_KIND_EXECUTE; |
176 | 493 | 492 | ||
178 | 494 | return task; | 493 | return task->shell(); |
179 | 495 | } | 494 | } |
180 | 496 | 495 | ||
181 | === modified file 'libgearman/client.cc' | |||
182 | --- libgearman/client.cc 2013-07-06 08:02:19 +0000 | |||
183 | +++ libgearman/client.cc 2013-07-06 19:18:28 +0000 | |||
184 | @@ -89,7 +89,7 @@ | |||
185 | 89 | /** | 89 | /** |
186 | 90 | * Real do function. | 90 | * Real do function. |
187 | 91 | */ | 91 | */ |
189 | 92 | static void *_client_do(gearman_client_st *client, gearman_command_t command, | 92 | static void *_client_do(gearman_client_st *client_shell, gearman_command_t command, |
190 | 93 | const char *function_name, | 93 | const char *function_name, |
191 | 94 | const char *unique, | 94 | const char *unique, |
192 | 95 | const void *workload_str, size_t workload_size, | 95 | const void *workload_str, size_t workload_size, |
193 | @@ -101,13 +101,15 @@ | |||
194 | 101 | ret_ptr= &unused; | 101 | ret_ptr= &unused; |
195 | 102 | } | 102 | } |
196 | 103 | 103 | ||
198 | 104 | if (client == NULL or client->impl() == NULL) | 104 | if (client_shell == NULL or client_shell->impl() == NULL) |
199 | 105 | { | 105 | { |
200 | 106 | *ret_ptr= GEARMAN_INVALID_ARGUMENT; | 106 | *ret_ptr= GEARMAN_INVALID_ARGUMENT; |
201 | 107 | return NULL; | 107 | return NULL; |
202 | 108 | } | 108 | } |
203 | 109 | 109 | ||
205 | 110 | client->impl()->universal.reset_error(); | 110 | Client* client= client_shell->impl(); |
206 | 111 | |||
207 | 112 | client->universal.reset_error(); | ||
208 | 111 | 113 | ||
209 | 112 | size_t unused_size; | 114 | size_t unused_size; |
210 | 113 | if (result_size == NULL) | 115 | if (result_size == NULL) |
211 | @@ -122,17 +124,17 @@ | |||
212 | 122 | 124 | ||
213 | 123 | gearman_task_st do_task; | 125 | gearman_task_st do_task; |
214 | 124 | { | 126 | { |
217 | 125 | client->impl()->universal.options.no_new_data= true; | 127 | client->universal.options.no_new_data= true; |
218 | 126 | gearman_task_st *do_task_ptr= add_task(*client, &do_task, NULL, command, | 128 | gearman_task_st *do_task_ptr= add_task(*(client->shell()), &do_task, NULL, command, |
219 | 127 | function, | 129 | function, |
220 | 128 | local_unique, | 130 | local_unique, |
221 | 129 | workload, | 131 | workload, |
222 | 130 | time_t(0), | 132 | time_t(0), |
223 | 131 | gearman_actions_do_default()); | 133 | gearman_actions_do_default()); |
225 | 132 | client->impl()->universal.options.no_new_data= false; | 134 | client->universal.options.no_new_data= false; |
226 | 133 | if (do_task_ptr == NULL) | 135 | if (do_task_ptr == NULL) |
227 | 134 | { | 136 | { |
229 | 135 | *ret_ptr= client->impl()->universal.error_code(); | 137 | *ret_ptr= client->universal.error_code(); |
230 | 136 | return NULL; | 138 | return NULL; |
231 | 137 | } | 139 | } |
232 | 138 | assert_msg(do_task.impl(), "Bad return by add_task()"); | 140 | assert_msg(do_task.impl(), "Bad return by add_task()"); |
233 | @@ -141,10 +143,10 @@ | |||
234 | 141 | 143 | ||
235 | 142 | do_task.impl()->type= GEARMAN_TASK_KIND_DO; | 144 | do_task.impl()->type= GEARMAN_TASK_KIND_DO; |
236 | 143 | 145 | ||
238 | 144 | gearman_return_t ret= gearman_client_run_block_tasks(client, &do_task); | 146 | gearman_return_t ret= gearman_client_run_block_tasks(client->shell(), &do_task); |
239 | 145 | 147 | ||
240 | 146 | // gearman_client_run_tasks failed | 148 | // gearman_client_run_tasks failed |
242 | 147 | assert(client->impl()->task_list); // Programmer error, we should always have the task that we used for do | 149 | assert(client->task_list); // Programmer error, we should always have the task that we used for do |
243 | 148 | 150 | ||
244 | 149 | char *returnable= NULL; | 151 | char *returnable= NULL; |
245 | 150 | if (gearman_failed(ret)) | 152 | if (gearman_failed(ret)) |
246 | @@ -153,7 +155,7 @@ | |||
247 | 153 | { } | 155 | { } |
248 | 154 | else | 156 | else |
249 | 155 | { | 157 | { |
251 | 156 | gearman_error(client->impl()->universal, ret, "occured during gearman_client_run_tasks()"); | 158 | gearman_error(client->universal, ret, "occured during gearman_client_run_tasks()"); |
252 | 157 | } | 159 | } |
253 | 158 | 160 | ||
254 | 159 | *ret_ptr= ret; | 161 | *ret_ptr= ret; |
255 | @@ -164,13 +166,13 @@ | |||
256 | 164 | *ret_ptr= do_task.impl()->result_rc; | 166 | *ret_ptr= do_task.impl()->result_rc; |
257 | 165 | if (gearman_task_result(&do_task)) | 167 | if (gearman_task_result(&do_task)) |
258 | 166 | { | 168 | { |
260 | 167 | if (gearman_has_allocator(client->impl()->universal)) | 169 | if (gearman_has_allocator(client->universal)) |
261 | 168 | { | 170 | { |
262 | 169 | gearman_string_t result= gearman_result_string(do_task.impl()->result()); | 171 | gearman_string_t result= gearman_result_string(do_task.impl()->result()); |
264 | 170 | returnable= static_cast<char *>(gearman_malloc(client->impl()->universal, gearman_size(result) +1)); | 172 | returnable= static_cast<char *>(gearman_malloc(client->universal, gearman_size(result) +1)); |
265 | 171 | if (returnable == NULL) | 173 | if (returnable == NULL) |
266 | 172 | { | 174 | { |
268 | 173 | gearman_error(client->impl()->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "custom workload_fn failed to allocate memory"); | 175 | gearman_error(client->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "custom workload_fn failed to allocate memory"); |
269 | 174 | *result_size= 0; | 176 | *result_size= 0; |
270 | 175 | } | 177 | } |
271 | 176 | else // NULL terminate | 178 | else // NULL terminate |
272 | @@ -194,15 +196,15 @@ | |||
273 | 194 | } | 196 | } |
274 | 195 | else // gearman_client_run_tasks() was successful, but the task was not | 197 | else // gearman_client_run_tasks() was successful, but the task was not |
275 | 196 | { | 198 | { |
277 | 197 | gearman_error(client->impl()->universal, do_task.impl()->result_rc, "occured during gearman_client_run_tasks()"); | 199 | gearman_error(client->universal, do_task.impl()->result_rc, "occured during gearman_client_run_tasks()"); |
278 | 198 | 200 | ||
279 | 199 | *ret_ptr= do_task.impl()->result_rc; | 201 | *ret_ptr= do_task.impl()->result_rc; |
280 | 200 | *result_size= 0; | 202 | *result_size= 0; |
281 | 201 | } | 203 | } |
282 | 202 | 204 | ||
283 | 203 | gearman_task_free(&do_task); | 205 | gearman_task_free(&do_task); |
286 | 204 | client->impl()->new_tasks= 0; | 206 | client->new_tasks= 0; |
287 | 205 | client->impl()->running_tasks= 0; | 207 | client->running_tasks= 0; |
288 | 206 | 208 | ||
289 | 207 | return returnable; | 209 | return returnable; |
290 | 208 | } | 210 | } |
291 | @@ -210,31 +212,32 @@ | |||
292 | 210 | /* | 212 | /* |
293 | 211 | Real background do function. | 213 | Real background do function. |
294 | 212 | */ | 214 | */ |
296 | 213 | static gearman_return_t _client_do_background(gearman_client_st *client, | 215 | static gearman_return_t _client_do_background(gearman_client_st* client_shell, |
297 | 214 | gearman_command_t command, | 216 | gearman_command_t command, |
298 | 215 | gearman_string_t &function, | 217 | gearman_string_t &function, |
299 | 216 | gearman_unique_t &unique, | 218 | gearman_unique_t &unique, |
300 | 217 | gearman_string_t &workload, | 219 | gearman_string_t &workload, |
301 | 218 | gearman_job_handle_t job_handle) | 220 | gearman_job_handle_t job_handle) |
302 | 219 | { | 221 | { |
304 | 220 | if (client == NULL) | 222 | if (client_shell == NULL or client_shell->impl() == NULL) |
305 | 221 | { | 223 | { |
306 | 222 | return GEARMAN_INVALID_ARGUMENT; | 224 | return GEARMAN_INVALID_ARGUMENT; |
307 | 223 | } | 225 | } |
308 | 224 | 226 | ||
310 | 225 | client->impl()->universal.reset_error(); | 227 | Client* client= client_shell->impl(); |
311 | 228 | client->universal.reset_error(); | ||
312 | 226 | 229 | ||
313 | 227 | if (gearman_size(function) == 0) | 230 | if (gearman_size(function) == 0) |
314 | 228 | { | 231 | { |
316 | 229 | return gearman_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, "function argument was empty"); | 232 | return gearman_error(client->universal, GEARMAN_INVALID_ARGUMENT, "function argument was empty"); |
317 | 230 | } | 233 | } |
318 | 231 | 234 | ||
320 | 232 | client->impl()->_do_handle[0]= 0; // Reset the job_handle we store in client | 235 | client->_do_handle[0]= 0; // Reset the job_handle we store in client |
321 | 233 | 236 | ||
322 | 234 | gearman_task_st do_task; | 237 | gearman_task_st do_task; |
323 | 235 | { | 238 | { |
326 | 236 | client->impl()->universal.options.no_new_data= true; | 239 | client->universal.options.no_new_data= true; |
327 | 237 | gearman_task_st* do_task_ptr= add_task(*client, &do_task, | 240 | gearman_task_st* do_task_ptr= add_task(*client_shell, &do_task, |
328 | 238 | client, | 241 | client, |
329 | 239 | command, | 242 | command, |
330 | 240 | function, | 243 | function, |
331 | @@ -242,26 +245,26 @@ | |||
332 | 242 | workload, | 245 | workload, |
333 | 243 | time_t(0), | 246 | time_t(0), |
334 | 244 | gearman_actions_do_default()); | 247 | gearman_actions_do_default()); |
336 | 245 | client->impl()->universal.options.no_new_data= false; | 248 | client->universal.options.no_new_data= false; |
337 | 246 | 249 | ||
338 | 247 | if (do_task_ptr == NULL) | 250 | if (do_task_ptr == NULL) |
339 | 248 | { | 251 | { |
341 | 249 | return client->impl()->universal.error_code(); | 252 | return client->universal.error_code(); |
342 | 250 | } | 253 | } |
343 | 251 | assert(do_task_ptr); | 254 | assert(do_task_ptr); |
344 | 252 | assert(&do_task == do_task_ptr); | 255 | assert(&do_task == do_task_ptr); |
345 | 253 | } | 256 | } |
346 | 254 | do_task.impl()->type= GEARMAN_TASK_KIND_DO; | 257 | do_task.impl()->type= GEARMAN_TASK_KIND_DO; |
347 | 255 | 258 | ||
349 | 256 | gearman_return_t ret= gearman_client_run_block_tasks(client, &do_task); | 259 | gearman_return_t ret= gearman_client_run_block_tasks(client_shell, &do_task); |
350 | 257 | 260 | ||
351 | 258 | if (job_handle) | 261 | if (job_handle) |
352 | 259 | { | 262 | { |
353 | 260 | strncpy(job_handle, do_task.impl()->job_handle, GEARMAN_JOB_HANDLE_SIZE); | 263 | strncpy(job_handle, do_task.impl()->job_handle, GEARMAN_JOB_HANDLE_SIZE); |
354 | 261 | } | 264 | } |
358 | 262 | strncpy(client->impl()->_do_handle, do_task.impl()->job_handle, GEARMAN_JOB_HANDLE_SIZE); | 265 | strncpy(client->_do_handle, do_task.impl()->job_handle, GEARMAN_JOB_HANDLE_SIZE); |
359 | 263 | client->impl()->new_tasks= 0; | 266 | client->new_tasks= 0; |
360 | 264 | client->impl()->running_tasks= 0; | 267 | client->running_tasks= 0; |
361 | 265 | gearman_task_free(&do_task); | 268 | gearman_task_free(&do_task); |
362 | 266 | 269 | ||
363 | 267 | return ret; | 270 | return ret; |
364 | @@ -393,31 +396,33 @@ | |||
365 | 393 | { | 396 | { |
366 | 394 | if (client_shell and client_shell->impl()) | 397 | if (client_shell and client_shell->impl()) |
367 | 395 | { | 398 | { |
368 | 399 | Client* client= client_shell->impl(); | ||
369 | 400 | |||
370 | 396 | switch (option) | 401 | switch (option) |
371 | 397 | { | 402 | { |
372 | 398 | case GEARMAN_CLIENT_ALLOCATED: | 403 | case GEARMAN_CLIENT_ALLOCATED: |
373 | 399 | return gearman_is_allocated(client_shell); | 404 | return gearman_is_allocated(client_shell); |
374 | 400 | 405 | ||
375 | 401 | case GEARMAN_CLIENT_NON_BLOCKING: | 406 | case GEARMAN_CLIENT_NON_BLOCKING: |
377 | 402 | return client_shell->impl()->options.non_blocking; | 407 | return client->options.non_blocking; |
378 | 403 | 408 | ||
379 | 404 | case GEARMAN_CLIENT_UNBUFFERED_RESULT: | 409 | case GEARMAN_CLIENT_UNBUFFERED_RESULT: |
381 | 405 | return client_shell->impl()->options.unbuffered_result; | 410 | return client->options.unbuffered_result; |
382 | 406 | 411 | ||
383 | 407 | case GEARMAN_CLIENT_NO_NEW: | 412 | case GEARMAN_CLIENT_NO_NEW: |
385 | 408 | return client_shell->impl()->options.no_new; | 413 | return client->options.no_new; |
386 | 409 | 414 | ||
387 | 410 | case GEARMAN_CLIENT_FREE_TASKS: | 415 | case GEARMAN_CLIENT_FREE_TASKS: |
389 | 411 | return client_shell->impl()->options.free_tasks; | 416 | return client->options.free_tasks; |
390 | 412 | 417 | ||
391 | 413 | case GEARMAN_CLIENT_GENERATE_UNIQUE: | 418 | case GEARMAN_CLIENT_GENERATE_UNIQUE: |
393 | 414 | return client_shell->impl()->options.generate_unique; | 419 | return client->options.generate_unique; |
394 | 415 | 420 | ||
395 | 416 | case GEARMAN_CLIENT_EXCEPTION: | 421 | case GEARMAN_CLIENT_EXCEPTION: |
397 | 417 | return client_shell->impl()->options.exceptions; | 422 | return client->options.exceptions; |
398 | 418 | 423 | ||
399 | 419 | case GEARMAN_CLIENT_SSL: | 424 | case GEARMAN_CLIENT_SSL: |
401 | 420 | return client_shell->impl()->ssl(); | 425 | return client->ssl(); |
402 | 421 | 426 | ||
403 | 422 | default: | 427 | default: |
404 | 423 | case GEARMAN_CLIENT_TASK_IN_USE: | 428 | case GEARMAN_CLIENT_TASK_IN_USE: |
405 | @@ -463,35 +468,36 @@ | |||
406 | 463 | { | 468 | { |
407 | 464 | if (client_shell and client_shell->impl()) | 469 | if (client_shell and client_shell->impl()) |
408 | 465 | { | 470 | { |
409 | 471 | Client* client= client_shell->impl(); | ||
410 | 466 | if (options & GEARMAN_CLIENT_NON_BLOCKING) | 472 | if (options & GEARMAN_CLIENT_NON_BLOCKING) |
411 | 467 | { | 473 | { |
414 | 468 | gearman_universal_add_options(client_shell->impl()->universal, GEARMAN_UNIVERSAL_NON_BLOCKING); | 474 | gearman_universal_add_options(client->universal, GEARMAN_UNIVERSAL_NON_BLOCKING); |
415 | 469 | client_shell->impl()->options.non_blocking= true; | 475 | client->options.non_blocking= true; |
416 | 470 | } | 476 | } |
417 | 471 | 477 | ||
418 | 472 | if (options & GEARMAN_CLIENT_UNBUFFERED_RESULT) | 478 | if (options & GEARMAN_CLIENT_UNBUFFERED_RESULT) |
419 | 473 | { | 479 | { |
421 | 474 | client_shell->impl()->options.unbuffered_result= true; | 480 | client->options.unbuffered_result= true; |
422 | 475 | } | 481 | } |
423 | 476 | 482 | ||
424 | 477 | if (options & GEARMAN_CLIENT_FREE_TASKS) | 483 | if (options & GEARMAN_CLIENT_FREE_TASKS) |
425 | 478 | { | 484 | { |
427 | 479 | client_shell->impl()->options.free_tasks= true; | 485 | client->options.free_tasks= true; |
428 | 480 | } | 486 | } |
429 | 481 | 487 | ||
430 | 482 | if (options & GEARMAN_CLIENT_GENERATE_UNIQUE) | 488 | if (options & GEARMAN_CLIENT_GENERATE_UNIQUE) |
431 | 483 | { | 489 | { |
433 | 484 | client_shell->impl()->options.generate_unique= true; | 490 | client->options.generate_unique= true; |
434 | 485 | } | 491 | } |
435 | 486 | 492 | ||
436 | 487 | if (options & GEARMAN_CLIENT_EXCEPTION) | 493 | if (options & GEARMAN_CLIENT_EXCEPTION) |
437 | 488 | { | 494 | { |
439 | 489 | client_shell->impl()->options.exceptions= gearman_client_set_server_option(client_shell, gearman_literal_param("exceptions")); | 495 | client->options.exceptions= gearman_client_set_server_option(client_shell, gearman_literal_param("exceptions")); |
440 | 490 | } | 496 | } |
441 | 491 | 497 | ||
442 | 492 | if (options & GEARMAN_CLIENT_SSL) | 498 | if (options & GEARMAN_CLIENT_SSL) |
443 | 493 | { | 499 | { |
445 | 494 | client_shell->impl()->ssl(true); | 500 | client->ssl(true); |
446 | 495 | } | 501 | } |
447 | 496 | } | 502 | } |
448 | 497 | } | 503 | } |
449 | @@ -501,25 +507,27 @@ | |||
450 | 501 | { | 507 | { |
451 | 502 | if (client_shell and client_shell->impl()) | 508 | if (client_shell and client_shell->impl()) |
452 | 503 | { | 509 | { |
453 | 510 | Client* client= client_shell->impl(); | ||
454 | 511 | |||
455 | 504 | if (options & GEARMAN_CLIENT_NON_BLOCKING) | 512 | if (options & GEARMAN_CLIENT_NON_BLOCKING) |
456 | 505 | { | 513 | { |
459 | 506 | gearman_universal_remove_options(client_shell->impl()->universal, GEARMAN_UNIVERSAL_NON_BLOCKING); | 514 | gearman_universal_remove_options(client->universal, GEARMAN_UNIVERSAL_NON_BLOCKING); |
460 | 507 | client_shell->impl()->options.non_blocking= false; | 515 | client->options.non_blocking= false; |
461 | 508 | } | 516 | } |
462 | 509 | 517 | ||
463 | 510 | if (options & GEARMAN_CLIENT_UNBUFFERED_RESULT) | 518 | if (options & GEARMAN_CLIENT_UNBUFFERED_RESULT) |
464 | 511 | { | 519 | { |
466 | 512 | client_shell->impl()->options.unbuffered_result= false; | 520 | client->options.unbuffered_result= false; |
467 | 513 | } | 521 | } |
468 | 514 | 522 | ||
469 | 515 | if (options & GEARMAN_CLIENT_FREE_TASKS) | 523 | if (options & GEARMAN_CLIENT_FREE_TASKS) |
470 | 516 | { | 524 | { |
472 | 517 | client_shell->impl()->options.free_tasks= false; | 525 | client->options.free_tasks= false; |
473 | 518 | } | 526 | } |
474 | 519 | 527 | ||
475 | 520 | if (options & GEARMAN_CLIENT_GENERATE_UNIQUE) | 528 | if (options & GEARMAN_CLIENT_GENERATE_UNIQUE) |
476 | 521 | { | 529 | { |
478 | 522 | client_shell->impl()->options.generate_unique= false; | 530 | client->options.generate_unique= false; |
479 | 523 | } | 531 | } |
480 | 524 | } | 532 | } |
481 | 525 | } | 533 | } |
482 | @@ -988,13 +996,14 @@ | |||
483 | 988 | return gearman_echo(client->impl()->universal, workload, workload_size); | 996 | return gearman_echo(client->impl()->universal, workload, workload_size); |
484 | 989 | } | 997 | } |
485 | 990 | 998 | ||
487 | 991 | void gearman_client_task_free_all(gearman_client_st *client) | 999 | void gearman_client_task_free_all(gearman_client_st *client_shell) |
488 | 992 | { | 1000 | { |
490 | 993 | if (client and client->impl() and client->impl()->task_list) | 1001 | if (client_shell and client_shell->impl() and client_shell->impl()->task_list) |
491 | 994 | { | 1002 | { |
493 | 995 | while (client->impl()->task_list) | 1003 | Client* client= client_shell->impl(); |
494 | 1004 | while (client->task_list) | ||
495 | 996 | { | 1005 | { |
497 | 997 | gearman_task_free(client->impl()->task_list); | 1006 | gearman_task_free(client->task_list); |
498 | 998 | } | 1007 | } |
499 | 999 | } | 1008 | } |
500 | 1000 | } | 1009 | } |
501 | @@ -1397,96 +1406,96 @@ | |||
502 | 1397 | } | 1406 | } |
503 | 1398 | } | 1407 | } |
504 | 1399 | 1408 | ||
506 | 1400 | static inline gearman_return_t _client_run_tasks(gearman_client_st *client, gearman_task_st* exit_task) | 1409 | static inline gearman_return_t _client_run_tasks(gearman_client_st *client_shell, gearman_task_st* exit_task) |
507 | 1401 | { | 1410 | { |
508 | 1402 | gearman_return_t ret= GEARMAN_MAX_RETURN; | 1411 | gearman_return_t ret= GEARMAN_MAX_RETURN; |
509 | 1403 | 1412 | ||
511 | 1404 | switch(client->impl()->state) | 1413 | Client* client= client_shell->impl(); |
512 | 1414 | |||
513 | 1415 | switch(client->state) | ||
514 | 1405 | { | 1416 | { |
515 | 1406 | case GEARMAN_CLIENT_STATE_IDLE: | 1417 | case GEARMAN_CLIENT_STATE_IDLE: |
516 | 1407 | while (1) | 1418 | while (1) |
517 | 1408 | { | 1419 | { |
518 | 1409 | /* Start any new tasks. */ | 1420 | /* Start any new tasks. */ |
520 | 1410 | if (client->impl()->new_tasks > 0 && ! (client->impl()->options.no_new)) | 1421 | if (client->new_tasks > 0 && ! (client->options.no_new)) |
521 | 1411 | { | 1422 | { |
524 | 1412 | for (client->impl()->task= client->impl()->task_list; client->impl()->task; | 1423 | for (client->task= client->task_list; client->task; |
525 | 1413 | client->impl()->task= client->impl()->task->impl()->next) | 1424 | client->task= client->task->impl()->next) |
526 | 1414 | { | 1425 | { |
528 | 1415 | if (client->impl()->task->impl()->state != GEARMAN_TASK_STATE_NEW) | 1426 | if (client->task->impl()->state != GEARMAN_TASK_STATE_NEW) |
529 | 1416 | { | 1427 | { |
530 | 1417 | continue; | 1428 | continue; |
531 | 1418 | } | 1429 | } |
532 | 1419 | 1430 | ||
533 | 1420 | case GEARMAN_CLIENT_STATE_NEW: | 1431 | case GEARMAN_CLIENT_STATE_NEW: |
535 | 1421 | if (client->impl()->task == NULL) | 1432 | if (client->task == NULL) |
536 | 1422 | { | 1433 | { |
538 | 1423 | client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; | 1434 | client->state= GEARMAN_CLIENT_STATE_IDLE; |
539 | 1424 | break; | 1435 | break; |
540 | 1425 | } | 1436 | } |
541 | 1426 | 1437 | ||
544 | 1427 | assert_msg(client == client->impl()->task->impl()->client, "Programmer error, client and task member client are not the same"); | 1438 | gearman_return_t local_ret= _client_run_task(client->task->impl()); |
543 | 1428 | gearman_return_t local_ret= _client_run_task(client->impl()->task->impl()); | ||
545 | 1429 | if (gearman_failed(local_ret) and local_ret != GEARMAN_IO_WAIT) | 1439 | if (gearman_failed(local_ret) and local_ret != GEARMAN_IO_WAIT) |
546 | 1430 | { | 1440 | { |
548 | 1431 | client->impl()->state= GEARMAN_CLIENT_STATE_NEW; | 1441 | client->state= GEARMAN_CLIENT_STATE_NEW; |
549 | 1432 | 1442 | ||
550 | 1433 | return local_ret; | 1443 | return local_ret; |
551 | 1434 | } | 1444 | } |
552 | 1435 | } | 1445 | } |
553 | 1436 | 1446 | ||
555 | 1437 | if (client->impl()->new_tasks == 0) | 1447 | if (client->new_tasks == 0) |
556 | 1438 | { | 1448 | { |
558 | 1439 | gearman_flush_all(client->impl()->universal); | 1449 | gearman_flush_all(client->universal); |
559 | 1440 | } | 1450 | } |
560 | 1441 | } | 1451 | } |
561 | 1442 | 1452 | ||
562 | 1443 | /* See if there are any connections ready for I/O. */ | 1453 | /* See if there are any connections ready for I/O. */ |
564 | 1444 | while ((client->impl()->con= gearman_ready(client->impl()->universal))) | 1454 | while ((client->con= gearman_ready(client->universal))) |
565 | 1445 | { | 1455 | { |
567 | 1446 | if (client->impl()->con->revents & (POLLOUT | POLLERR | POLLHUP | POLLNVAL)) | 1456 | if (client->con->revents & (POLLOUT | POLLERR | POLLHUP | POLLNVAL)) |
568 | 1447 | { | 1457 | { |
569 | 1448 | /* Socket is ready for writing, continue submitting jobs. */ | 1458 | /* Socket is ready for writing, continue submitting jobs. */ |
572 | 1449 | for (client->impl()->task= client->impl()->task_list; client->impl()->task; | 1459 | for (client->task= client->task_list; client->task; |
573 | 1450 | client->impl()->task= client->impl()->task->impl()->next) | 1460 | client->task= client->task->impl()->next) |
574 | 1451 | { | 1461 | { |
578 | 1452 | if (client->impl()->task->impl()->con != client->impl()->con or | 1462 | if (client->task->impl()->con != client->con or |
579 | 1453 | (client->impl()->task->impl()->state != GEARMAN_TASK_STATE_SUBMIT and | 1463 | (client->task->impl()->state != GEARMAN_TASK_STATE_SUBMIT and |
580 | 1454 | client->impl()->task->impl()->state != GEARMAN_TASK_STATE_WORKLOAD)) | 1464 | client->task->impl()->state != GEARMAN_TASK_STATE_WORKLOAD)) |
581 | 1455 | { | 1465 | { |
582 | 1456 | continue; | 1466 | continue; |
583 | 1457 | } | 1467 | } |
584 | 1458 | 1468 | ||
585 | 1459 | case GEARMAN_CLIENT_STATE_SUBMIT: | 1469 | case GEARMAN_CLIENT_STATE_SUBMIT: |
587 | 1460 | if (client->impl()->task == NULL) | 1470 | if (client->task == NULL) |
588 | 1461 | { | 1471 | { |
590 | 1462 | client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; | 1472 | client->state= GEARMAN_CLIENT_STATE_IDLE; |
591 | 1463 | break; | 1473 | break; |
592 | 1464 | } | 1474 | } |
595 | 1465 | assert_msg(client == client->impl()->task->impl()->client, "Programmer error, client and task member client are not the same"); | 1475 | gearman_return_t local_ret= _client_run_task(client->task->impl()); |
594 | 1466 | gearman_return_t local_ret= _client_run_task(client->impl()->task->impl()); | ||
596 | 1467 | if (local_ret == GEARMAN_COULD_NOT_CONNECT) | 1476 | if (local_ret == GEARMAN_COULD_NOT_CONNECT) |
597 | 1468 | { | 1477 | { |
599 | 1469 | client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; | 1478 | client->state= GEARMAN_CLIENT_STATE_IDLE; |
600 | 1470 | return local_ret; | 1479 | return local_ret; |
601 | 1471 | } | 1480 | } |
602 | 1472 | else if (gearman_failed(local_ret) and local_ret != GEARMAN_IO_WAIT) | 1481 | else if (gearman_failed(local_ret) and local_ret != GEARMAN_IO_WAIT) |
603 | 1473 | { | 1482 | { |
605 | 1474 | client->impl()->state= GEARMAN_CLIENT_STATE_SUBMIT; | 1483 | client->state= GEARMAN_CLIENT_STATE_SUBMIT; |
606 | 1475 | return local_ret; | 1484 | return local_ret; |
607 | 1476 | } | 1485 | } |
608 | 1477 | } | 1486 | } |
609 | 1478 | 1487 | ||
610 | 1479 | /* Connection errors are fatal. */ | 1488 | /* Connection errors are fatal. */ |
612 | 1480 | if (client->impl()->con->revents & (POLLERR | POLLHUP | POLLNVAL)) | 1489 | if (client->con->revents & (POLLERR | POLLHUP | POLLNVAL)) |
613 | 1481 | { | 1490 | { |
617 | 1482 | gearman_error(client->impl()->universal, GEARMAN_LOST_CONNECTION, "detected lost connection in _client_run_tasks()"); | 1491 | gearman_error(client->universal, GEARMAN_LOST_CONNECTION, "detected lost connection in _client_run_tasks()"); |
618 | 1483 | client->impl()->con->close_socket(); | 1492 | client->con->close_socket(); |
619 | 1484 | client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; | 1493 | client->state= GEARMAN_CLIENT_STATE_IDLE; |
620 | 1485 | return GEARMAN_LOST_CONNECTION; | 1494 | return GEARMAN_LOST_CONNECTION; |
621 | 1486 | } | 1495 | } |
622 | 1487 | } | 1496 | } |
623 | 1488 | 1497 | ||
625 | 1489 | if ((client->impl()->con->revents & POLLIN) == 0) | 1498 | if ((client->con->revents & POLLIN) == 0) |
626 | 1490 | { | 1499 | { |
627 | 1491 | continue; | 1500 | continue; |
628 | 1492 | } | 1501 | } |
629 | @@ -1495,17 +1504,17 @@ | |||
630 | 1495 | while (1) | 1504 | while (1) |
631 | 1496 | { | 1505 | { |
632 | 1497 | /* Read packet on connection and find which task it belongs to. */ | 1506 | /* Read packet on connection and find which task it belongs to. */ |
634 | 1498 | if (client->impl()->options.unbuffered_result) | 1507 | if (client->options.unbuffered_result) |
635 | 1499 | { | 1508 | { |
636 | 1500 | /* If client is handling the data read, make sure it's complete. */ | 1509 | /* If client is handling the data read, make sure it's complete. */ |
638 | 1501 | if (client->impl()->con->recv_state == GEARMAN_CON_RECV_STATE_READ_DATA) | 1510 | if (client->con->recv_state == GEARMAN_CON_RECV_STATE_READ_DATA) |
639 | 1502 | { | 1511 | { |
642 | 1503 | for (client->impl()->task= client->impl()->task_list; client->impl()->task; | 1512 | for (client->task= client->task_list; client->task; |
643 | 1504 | client->impl()->task= client->impl()->task->impl()->next) | 1513 | client->task= client->task->impl()->next) |
644 | 1505 | { | 1514 | { |
648 | 1506 | if (client->impl()->task->impl()->con == client->impl()->con && | 1515 | if (client->task->impl()->con == client->con && |
649 | 1507 | (client->impl()->task->impl()->state == GEARMAN_TASK_STATE_DATA or | 1516 | (client->task->impl()->state == GEARMAN_TASK_STATE_DATA or |
650 | 1508 | client->impl()->task->impl()->state == GEARMAN_TASK_STATE_COMPLETE)) | 1517 | client->task->impl()->state == GEARMAN_TASK_STATE_COMPLETE)) |
651 | 1509 | { | 1518 | { |
652 | 1510 | break; | 1519 | break; |
653 | 1511 | } | 1520 | } |
654 | @@ -1515,24 +1524,24 @@ | |||
655 | 1515 | Someone has set GEARMAN_CLIENT_UNBUFFERED_RESULT but hasn't setup the client to fetch data correctly. | 1524 | Someone has set GEARMAN_CLIENT_UNBUFFERED_RESULT but hasn't setup the client to fetch data correctly. |
656 | 1516 | Fatal error :( | 1525 | Fatal error :( |
657 | 1517 | */ | 1526 | */ |
659 | 1518 | return gearman_universal_set_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, GEARMAN_AT, | 1527 | return gearman_universal_set_error(client->universal, GEARMAN_INVALID_ARGUMENT, GEARMAN_AT, |
660 | 1519 | "client created with GEARMAN_CLIENT_UNBUFFERED_RESULT, but was not setup to use it. %s", __func__); | 1528 | "client created with GEARMAN_CLIENT_UNBUFFERED_RESULT, but was not setup to use it. %s", __func__); |
661 | 1520 | } | 1529 | } |
662 | 1521 | else | 1530 | else |
663 | 1522 | { | 1531 | { |
664 | 1523 | /* Read the next packet, without buffering the data part. */ | 1532 | /* Read the next packet, without buffering the data part. */ |
667 | 1524 | client->impl()->task= NULL; | 1533 | client->task= NULL; |
668 | 1525 | (void)client->impl()->con->receiving(client->impl()->con->_packet, ret, false); | 1534 | (void)client->con->receiving(client->con->_packet, ret, false); |
669 | 1526 | } | 1535 | } |
670 | 1527 | } | 1536 | } |
671 | 1528 | else | 1537 | else |
672 | 1529 | { | 1538 | { |
673 | 1530 | /* Read the next packet, buffering the data part. */ | 1539 | /* Read the next packet, buffering the data part. */ |
676 | 1531 | client->impl()->task= NULL; | 1540 | client->task= NULL; |
677 | 1532 | (void)client->impl()->con->receiving(client->impl()->con->_packet, ret, true); | 1541 | (void)client->con->receiving(client->con->_packet, ret, true); |
678 | 1533 | } | 1542 | } |
679 | 1534 | 1543 | ||
681 | 1535 | if (client->impl()->task == NULL) | 1544 | if (client->task == NULL) |
682 | 1536 | { | 1545 | { |
683 | 1537 | assert(ret != GEARMAN_MAX_RETURN); | 1546 | assert(ret != GEARMAN_MAX_RETURN); |
684 | 1538 | 1547 | ||
685 | @@ -1544,71 +1553,71 @@ | |||
686 | 1544 | break; | 1553 | break; |
687 | 1545 | } | 1554 | } |
688 | 1546 | 1555 | ||
690 | 1547 | client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; | 1556 | client->state= GEARMAN_CLIENT_STATE_IDLE; |
691 | 1548 | return ret; | 1557 | return ret; |
692 | 1549 | } | 1558 | } |
693 | 1550 | 1559 | ||
695 | 1551 | client->impl()->con->options.packet_in_use= true; | 1560 | client->con->options.packet_in_use= true; |
696 | 1552 | 1561 | ||
697 | 1553 | /* We have a packet, see which task it belongs to. */ | 1562 | /* We have a packet, see which task it belongs to. */ |
700 | 1554 | for (client->impl()->task= client->impl()->task_list; client->impl()->task; | 1563 | for (client->task= client->task_list; client->task; |
701 | 1555 | client->impl()->task= client->impl()->task->impl()->next) | 1564 | client->task= client->task->impl()->next) |
702 | 1556 | { | 1565 | { |
704 | 1557 | if (client->impl()->task->impl()->con != client->impl()->con) | 1566 | if (client->task->impl()->con != client->con) |
705 | 1558 | { | 1567 | { |
706 | 1559 | continue; | 1568 | continue; |
707 | 1560 | } | 1569 | } |
708 | 1561 | 1570 | ||
710 | 1562 | if (client->impl()->con->_packet.command == GEARMAN_COMMAND_JOB_CREATED) | 1571 | if (client->con->_packet.command == GEARMAN_COMMAND_JOB_CREATED) |
711 | 1563 | { | 1572 | { |
713 | 1564 | if (client->impl()->task->impl()->created_id != client->impl()->con->created_id) | 1573 | if (client->task->impl()->created_id != client->con->created_id) |
714 | 1565 | { | 1574 | { |
715 | 1566 | continue; | 1575 | continue; |
716 | 1567 | } | 1576 | } |
717 | 1568 | 1577 | ||
718 | 1569 | /* New job created, drop through below and notify task. */ | 1578 | /* New job created, drop through below and notify task. */ |
720 | 1570 | client->impl()->con->created_id++; | 1579 | client->con->created_id++; |
721 | 1571 | } | 1580 | } |
723 | 1572 | else if (client->impl()->con->_packet.command == GEARMAN_COMMAND_ERROR) | 1581 | else if (client->con->_packet.command == GEARMAN_COMMAND_ERROR) |
724 | 1573 | { | 1582 | { |
726 | 1574 | gearman_return_t maybe_server_error= string2return_code(static_cast<char *>(client->impl()->con->_packet.arg[0]), int(client->impl()->con->_packet.arg_size[0])); | 1583 | gearman_return_t maybe_server_error= string2return_code(static_cast<char *>(client->con->_packet.arg[0]), int(client->con->_packet.arg_size[0])); |
727 | 1575 | 1584 | ||
728 | 1576 | if (maybe_server_error == GEARMAN_MAX_RETURN) | 1585 | if (maybe_server_error == GEARMAN_MAX_RETURN) |
729 | 1577 | { | 1586 | { |
730 | 1578 | maybe_server_error= GEARMAN_SERVER_ERROR; | 1587 | maybe_server_error= GEARMAN_SERVER_ERROR; |
731 | 1579 | } | 1588 | } |
732 | 1580 | 1589 | ||
734 | 1581 | gearman_universal_set_error(client->impl()->universal, maybe_server_error, GEARMAN_AT, | 1590 | gearman_universal_set_error(client->universal, maybe_server_error, GEARMAN_AT, |
735 | 1582 | "%s:%.*s", | 1591 | "%s:%.*s", |
739 | 1583 | static_cast<char *>(client->impl()->con->_packet.arg[0]), | 1592 | static_cast<char *>(client->con->_packet.arg[0]), |
740 | 1584 | int(client->impl()->con->_packet.arg_size[1]), | 1593 | int(client->con->_packet.arg_size[1]), |
741 | 1585 | static_cast<char *>(client->impl()->con->_packet.arg[1])); | 1594 | static_cast<char *>(client->con->_packet.arg[1])); |
742 | 1586 | 1595 | ||
743 | 1587 | /* | 1596 | /* |
744 | 1588 | Packet cleanup copied from "Clean up the packet" below, and must | 1597 | Packet cleanup copied from "Clean up the packet" below, and must |
745 | 1589 | remain in sync with its reference. | 1598 | remain in sync with its reference. |
746 | 1590 | */ | 1599 | */ |
749 | 1591 | gearman_packet_free(&(client->impl()->con->_packet)); | 1600 | gearman_packet_free(&(client->con->_packet)); |
750 | 1592 | client->impl()->con->options.packet_in_use= false; | 1601 | client->con->options.packet_in_use= false; |
751 | 1593 | 1602 | ||
752 | 1594 | /* This step copied from _client_run_tasks() above: */ | 1603 | /* This step copied from _client_run_tasks() above: */ |
753 | 1595 | /* Increment this value because new job created then failed. */ | 1604 | /* Increment this value because new job created then failed. */ |
755 | 1596 | client->impl()->con->created_id++; | 1605 | client->con->created_id++; |
756 | 1597 | 1606 | ||
757 | 1598 | return maybe_server_error; | 1607 | return maybe_server_error; |
758 | 1599 | } | 1608 | } |
763 | 1600 | else if (client->impl()->con->_packet.command == GEARMAN_COMMAND_STATUS_RES_UNIQUE and | 1609 | else if (client->con->_packet.command == GEARMAN_COMMAND_STATUS_RES_UNIQUE and |
764 | 1601 | (strncmp(gearman_task_unique(client->impl()->task), | 1610 | (strncmp(gearman_task_unique(client->task), |
765 | 1602 | static_cast<char *>(client->impl()->con->_packet.arg[0]), | 1611 | static_cast<char *>(client->con->_packet.arg[0]), |
766 | 1603 | client->impl()->con->_packet.arg_size[0]) == 0)) | 1612 | client->con->_packet.arg_size[0]) == 0)) |
767 | 1604 | { } | 1613 | { } |
775 | 1605 | else if (strncmp(client->impl()->task->impl()->job_handle, | 1614 | else if (strncmp(client->task->impl()->job_handle, |
776 | 1606 | static_cast<char *>(client->impl()->con->_packet.arg[0]), | 1615 | static_cast<char *>(client->con->_packet.arg[0]), |
777 | 1607 | client->impl()->con->_packet.arg_size[0]) || | 1616 | client->con->_packet.arg_size[0]) || |
778 | 1608 | (client->impl()->con->_packet.failed() == false && | 1617 | (client->con->_packet.failed() == false && |
779 | 1609 | strlen(client->impl()->task->impl()->job_handle) != client->impl()->con->_packet.arg_size[0] - 1) || | 1618 | strlen(client->task->impl()->job_handle) != client->con->_packet.arg_size[0] - 1) || |
780 | 1610 | (client->impl()->con->_packet.failed() && | 1619 | (client->con->_packet.failed() && |
781 | 1611 | strlen(client->impl()->task->impl()->job_handle) != client->impl()->con->_packet.arg_size[0])) | 1620 | strlen(client->task->impl()->job_handle) != client->con->_packet.arg_size[0])) |
782 | 1612 | { | 1621 | { |
783 | 1613 | continue; | 1622 | continue; |
784 | 1614 | } | 1623 | } |
785 | @@ -1618,20 +1627,19 @@ | |||
786 | 1618 | break; | 1627 | break; |
787 | 1619 | } | 1628 | } |
788 | 1620 | 1629 | ||
790 | 1621 | if (client->impl()->task == NULL) | 1630 | if (client->task == NULL) |
791 | 1622 | { | 1631 | { |
792 | 1623 | /* The client has stopped waiting for the response, ignore it. */ | 1632 | /* The client has stopped waiting for the response, ignore it. */ |
794 | 1624 | client->impl()->con->free_private_packet(); | 1633 | client->con->free_private_packet(); |
795 | 1625 | continue; | 1634 | continue; |
796 | 1626 | } | 1635 | } |
797 | 1627 | 1636 | ||
799 | 1628 | client->impl()->task->impl()->recv= &(client->impl()->con->_packet); | 1637 | client->task->impl()->recv= &(client->con->_packet); |
800 | 1629 | } | 1638 | } |
801 | 1630 | 1639 | ||
802 | 1631 | case GEARMAN_CLIENT_STATE_PACKET: | 1640 | case GEARMAN_CLIENT_STATE_PACKET: |
803 | 1632 | /* Let task process job created or result packet. */ | 1641 | /* Let task process job created or result packet. */ |
806 | 1633 | assert_msg(client == client->impl()->task->impl()->client, "Programmer error, client and task member client are not the same"); | 1642 | gearman_return_t local_ret= _client_run_task(client->task->impl()); |
805 | 1634 | gearman_return_t local_ret= _client_run_task(client->impl()->task->impl()); | ||
807 | 1635 | if (local_ret == GEARMAN_IO_WAIT) | 1643 | if (local_ret == GEARMAN_IO_WAIT) |
808 | 1636 | { | 1644 | { |
809 | 1637 | break; | 1645 | break; |
810 | @@ -1639,56 +1647,56 @@ | |||
811 | 1639 | 1647 | ||
812 | 1640 | if (gearman_failed(local_ret)) | 1648 | if (gearman_failed(local_ret)) |
813 | 1641 | { | 1649 | { |
815 | 1642 | client->impl()->state= GEARMAN_CLIENT_STATE_PACKET; | 1650 | client->state= GEARMAN_CLIENT_STATE_PACKET; |
816 | 1643 | return local_ret; | 1651 | return local_ret; |
817 | 1644 | } | 1652 | } |
818 | 1645 | 1653 | ||
819 | 1646 | /* Clean up the packet. */ | 1654 | /* Clean up the packet. */ |
821 | 1647 | client->impl()->con->free_private_packet(); | 1655 | client->con->free_private_packet(); |
822 | 1648 | 1656 | ||
823 | 1649 | /* If exit task is set and matched, exit */ | 1657 | /* If exit task is set and matched, exit */ |
824 | 1650 | if (exit_task) | 1658 | if (exit_task) |
825 | 1651 | { | 1659 | { |
826 | 1652 | if (exit_task->impl()->result_rc != GEARMAN_UNKNOWN_STATE) | 1660 | if (exit_task->impl()->result_rc != GEARMAN_UNKNOWN_STATE) |
827 | 1653 | { | 1661 | { |
829 | 1654 | client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; | 1662 | client->state= GEARMAN_CLIENT_STATE_IDLE; |
830 | 1655 | return GEARMAN_SUCCESS; | 1663 | return GEARMAN_SUCCESS; |
831 | 1656 | } | 1664 | } |
832 | 1657 | } | 1665 | } |
833 | 1658 | 1666 | ||
834 | 1659 | /* If all tasks are done, return. */ | 1667 | /* If all tasks are done, return. */ |
836 | 1660 | if (client->impl()->running_tasks == 0) | 1668 | if (client->running_tasks == 0) |
837 | 1661 | { | 1669 | { |
839 | 1662 | client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; | 1670 | client->state= GEARMAN_CLIENT_STATE_IDLE; |
840 | 1663 | return GEARMAN_SUCCESS; | 1671 | return GEARMAN_SUCCESS; |
841 | 1664 | } | 1672 | } |
842 | 1665 | } | 1673 | } |
843 | 1666 | } | 1674 | } |
844 | 1667 | 1675 | ||
845 | 1668 | /* If all tasks are done, return. */ | 1676 | /* If all tasks are done, return. */ |
847 | 1669 | if (client->impl()->running_tasks == 0) | 1677 | if (client->running_tasks == 0) |
848 | 1670 | { | 1678 | { |
849 | 1671 | break; | 1679 | break; |
850 | 1672 | } | 1680 | } |
851 | 1673 | 1681 | ||
853 | 1674 | if (client->impl()->new_tasks > 0 and ! (client->impl()->options.no_new)) | 1682 | if (client->new_tasks > 0 and ! (client->options.no_new)) |
854 | 1675 | { | 1683 | { |
855 | 1676 | continue; | 1684 | continue; |
856 | 1677 | } | 1685 | } |
857 | 1678 | 1686 | ||
859 | 1679 | if (client->impl()->options.non_blocking) | 1687 | if (client->options.non_blocking) |
860 | 1680 | { | 1688 | { |
861 | 1681 | /* Let the caller wait for activity. */ | 1689 | /* Let the caller wait for activity. */ |
863 | 1682 | client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; | 1690 | client->state= GEARMAN_CLIENT_STATE_IDLE; |
864 | 1683 | 1691 | ||
866 | 1684 | return gearman_gerror(client->impl()->universal, GEARMAN_IO_WAIT); | 1692 | return gearman_gerror(client->universal, GEARMAN_IO_WAIT); |
867 | 1685 | } | 1693 | } |
868 | 1686 | 1694 | ||
869 | 1687 | /* Wait for activity on one of the connections. */ | 1695 | /* Wait for activity on one of the connections. */ |
871 | 1688 | gearman_return_t local_ret= gearman_wait(client->impl()->universal); | 1696 | gearman_return_t local_ret= gearman_wait(client->universal); |
872 | 1689 | if (gearman_failed(local_ret) and local_ret != GEARMAN_IO_WAIT) | 1697 | if (gearman_failed(local_ret) and local_ret != GEARMAN_IO_WAIT) |
873 | 1690 | { | 1698 | { |
875 | 1691 | client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; | 1699 | client->state= GEARMAN_CLIENT_STATE_IDLE; |
876 | 1692 | 1700 | ||
877 | 1693 | return local_ret; | 1701 | return local_ret; |
878 | 1694 | } | 1702 | } |
879 | @@ -1697,73 +1705,76 @@ | |||
880 | 1697 | break; | 1705 | break; |
881 | 1698 | } | 1706 | } |
882 | 1699 | 1707 | ||
884 | 1700 | client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; | 1708 | client->state= GEARMAN_CLIENT_STATE_IDLE; |
885 | 1701 | 1709 | ||
886 | 1702 | return GEARMAN_SUCCESS; | 1710 | return GEARMAN_SUCCESS; |
887 | 1703 | } | 1711 | } |
888 | 1704 | 1712 | ||
939 | 1705 | gearman_return_t gearman_client_run_tasks(gearman_client_st *client) | 1713 | gearman_return_t gearman_client_run_tasks(gearman_client_st *client_shell) |
940 | 1706 | { | 1714 | { |
941 | 1707 | if (client == NULL or client->impl() == NULL) | 1715 | if (client_shell and client_shell->impl()) |
942 | 1708 | { | 1716 | { |
943 | 1709 | return GEARMAN_INVALID_ARGUMENT; | 1717 | Client* client= client_shell->impl(); |
944 | 1710 | } | 1718 | |
945 | 1711 | 1719 | if (client->task_list == NULL) // We are immediatly successful if all tasks are completed | |
946 | 1712 | if (client->impl()->task_list == NULL) // We are immediatly successful if all tasks are completed | 1720 | { |
947 | 1713 | { | 1721 | return GEARMAN_SUCCESS; |
948 | 1714 | return GEARMAN_SUCCESS; | 1722 | } |
949 | 1715 | } | 1723 | |
950 | 1716 | 1724 | gearman_return_t rc; | |
951 | 1717 | gearman_return_t rc; | 1725 | { |
952 | 1718 | { | 1726 | PUSH_NON_BLOCKING(client->universal); |
953 | 1719 | PUSH_NON_BLOCKING(client->impl()->universal); | 1727 | |
954 | 1720 | 1728 | rc= _client_run_tasks(client_shell, NULL); | |
955 | 1721 | rc= _client_run_tasks(client, NULL); | 1729 | } |
956 | 1722 | } | 1730 | |
907 | 1723 | |||
908 | 1724 | if (rc == GEARMAN_COULD_NOT_CONNECT) | ||
909 | 1725 | { | ||
910 | 1726 | gearman_reset(client->impl()->universal); | ||
911 | 1727 | } | ||
912 | 1728 | |||
913 | 1729 | return rc; | ||
914 | 1730 | } | ||
915 | 1731 | |||
916 | 1732 | gearman_return_t gearman_client_run_block_tasks(gearman_client_st *shell, gearman_task_st* exit_task) | ||
917 | 1733 | { | ||
918 | 1734 | if (shell == NULL) | ||
919 | 1735 | { | ||
920 | 1736 | return GEARMAN_INVALID_ARGUMENT; | ||
921 | 1737 | } | ||
922 | 1738 | Client *client= shell->impl(); | ||
923 | 1739 | |||
924 | 1740 | if (client->task_list == NULL) // We are immediatly successful if all tasks are completed | ||
925 | 1741 | { | ||
926 | 1742 | return GEARMAN_SUCCESS; | ||
927 | 1743 | } | ||
928 | 1744 | |||
929 | 1745 | |||
930 | 1746 | gearman_return_t rc; | ||
931 | 1747 | { | ||
932 | 1748 | PUSH_BLOCKING(client->universal); | ||
933 | 1749 | |||
934 | 1750 | rc= _client_run_tasks(shell, exit_task); | ||
935 | 1751 | } | ||
936 | 1752 | |||
937 | 1753 | if (gearman_failed(rc)) | ||
938 | 1754 | { | ||
957 | 1755 | if (rc == GEARMAN_COULD_NOT_CONNECT) | 1731 | if (rc == GEARMAN_COULD_NOT_CONNECT) |
958 | 1756 | { | 1732 | { |
959 | 1757 | gearman_reset(client->universal); | 1733 | gearman_reset(client->universal); |
960 | 1758 | } | 1734 | } |
961 | 1759 | 1735 | ||
969 | 1760 | if (client->universal.error_code() != rc and rc != GEARMAN_COULD_NOT_CONNECT) | 1736 | return rc; |
970 | 1761 | { | 1737 | } |
971 | 1762 | assert(client->universal.error_code() == rc); | 1738 | |
972 | 1763 | } | 1739 | return GEARMAN_INVALID_ARGUMENT; |
973 | 1764 | } | 1740 | } |
974 | 1765 | 1741 | ||
975 | 1766 | return rc; | 1742 | gearman_return_t gearman_client_run_block_tasks(gearman_client_st *client_shell, gearman_task_st* exit_task) |
976 | 1743 | { | ||
977 | 1744 | if (client_shell and client_shell->impl()) | ||
978 | 1745 | { | ||
979 | 1746 | Client *client= client_shell->impl(); | ||
980 | 1747 | |||
981 | 1748 | if (client->task_list == NULL) // We are immediatly successful if all tasks are completed | ||
982 | 1749 | { | ||
983 | 1750 | return GEARMAN_SUCCESS; | ||
984 | 1751 | } | ||
985 | 1752 | |||
986 | 1753 | |||
987 | 1754 | gearman_return_t rc; | ||
988 | 1755 | { | ||
989 | 1756 | PUSH_BLOCKING(client->universal); | ||
990 | 1757 | |||
991 | 1758 | rc= _client_run_tasks(client_shell, exit_task); | ||
992 | 1759 | } | ||
993 | 1760 | |||
994 | 1761 | if (gearman_failed(rc)) | ||
995 | 1762 | { | ||
996 | 1763 | if (rc == GEARMAN_COULD_NOT_CONNECT) | ||
997 | 1764 | { | ||
998 | 1765 | gearman_reset(client->universal); | ||
999 | 1766 | } | ||
1000 | 1767 | |||
1001 | 1768 | if (client->universal.error_code() != rc and rc != GEARMAN_COULD_NOT_CONNECT) | ||
1002 | 1769 | { | ||
1003 | 1770 | assert(client->universal.error_code() == rc); | ||
1004 | 1771 | } | ||
1005 | 1772 | } | ||
1006 | 1773 | |||
1007 | 1774 | return rc; | ||
1008 | 1775 | } | ||
1009 | 1776 | |||
1010 | 1777 | return GEARMAN_INVALID_ARGUMENT; | ||
1011 | 1767 | } | 1778 | } |
1012 | 1768 | 1779 | ||
1013 | 1769 | /* | 1780 | /* |
1014 | 1770 | 1781 | ||
1015 | === modified file 'libgearman/interface/task.hpp' | |||
1016 | --- libgearman/interface/task.hpp 2013-07-06 01:22:31 +0000 | |||
1017 | +++ libgearman/interface/task.hpp 2013-07-06 19:18:28 +0000 | |||
1018 | @@ -2,7 +2,7 @@ | |||
1019 | 2 | * | 2 | * |
1020 | 3 | * Gearmand client and server library. | 3 | * Gearmand client and server library. |
1021 | 4 | * | 4 | * |
1023 | 5 | * Copyright (C) 2012 Data Differential, http://datadifferential.com/ | 5 | * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ |
1024 | 6 | * All rights reserved. | 6 | * All rights reserved. |
1025 | 7 | * | 7 | * |
1026 | 8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
1027 | @@ -69,7 +69,7 @@ | |||
1028 | 69 | uint32_t numerator; | 69 | uint32_t numerator; |
1029 | 70 | uint32_t denominator; | 70 | uint32_t denominator; |
1030 | 71 | uint32_t client_count; | 71 | uint32_t client_count; |
1032 | 72 | gearman_client_st *client; | 72 | Client *client; |
1033 | 73 | gearman_task_st *next; | 73 | gearman_task_st *next; |
1034 | 74 | gearman_task_st *prev; | 74 | gearman_task_st *prev; |
1035 | 75 | void *context; | 75 | void *context; |
1036 | @@ -97,7 +97,7 @@ | |||
1037 | 97 | numerator(0), | 97 | numerator(0), |
1038 | 98 | denominator(0), | 98 | denominator(0), |
1039 | 99 | client_count(0), | 99 | client_count(0), |
1041 | 100 | client(&client_), | 100 | client(client_.impl()), |
1042 | 101 | next(NULL), | 101 | next(NULL), |
1043 | 102 | prev(NULL), | 102 | prev(NULL), |
1044 | 103 | context(NULL), | 103 | context(NULL), |
1045 | 104 | 104 | ||
1046 | === modified file 'libgearman/run.cc' | |||
1047 | --- libgearman/run.cc 2013-07-06 17:00:51 +0000 | |||
1048 | +++ libgearman/run.cc 2013-07-06 19:18:28 +0000 | |||
1049 | @@ -51,7 +51,7 @@ | |||
1050 | 51 | assert_msg(task->client, "Programmer error, somehow an invalid task was specified"); | 51 | assert_msg(task->client, "Programmer error, somehow an invalid task was specified"); |
1051 | 52 | if (task->client == NULL) | 52 | if (task->client == NULL) |
1052 | 53 | { | 53 | { |
1054 | 54 | return gearman_universal_set_error(task->client->impl()->universal, GEARMAN_INVALID_ARGUMENT, GEARMAN_AT, | 54 | return gearman_universal_set_error(task->client->universal, GEARMAN_INVALID_ARGUMENT, GEARMAN_AT, |
1055 | 55 | "Programmer error, somehow an invalid task was specified"); | 55 | "Programmer error, somehow an invalid task was specified"); |
1056 | 56 | } | 56 | } |
1057 | 57 | 57 | ||
1058 | @@ -59,16 +59,16 @@ | |||
1059 | 59 | { | 59 | { |
1060 | 60 | case GEARMAN_TASK_STATE_NEW: | 60 | case GEARMAN_TASK_STATE_NEW: |
1061 | 61 | 61 | ||
1063 | 62 | if (task->client->impl()->universal.has_connections() == false) | 62 | if (task->client->universal.has_connections() == false) |
1064 | 63 | { | 63 | { |
1070 | 64 | assert(task->client->impl()->universal.con_count == 0); | 64 | assert(task->client->universal.con_count == 0); |
1071 | 65 | assert(task->client->impl()->universal.con_list == NULL); | 65 | assert(task->client->universal.con_list == NULL); |
1072 | 66 | task->client->impl()->new_tasks--; | 66 | task->client->new_tasks--; |
1073 | 67 | task->client->impl()->running_tasks--; | 67 | task->client->running_tasks--; |
1074 | 68 | return gearman_universal_set_error(task->client->impl()->universal, GEARMAN_NO_SERVERS, GEARMAN_AT, "no servers provided"); | 68 | return gearman_universal_set_error(task->client->universal, GEARMAN_NO_SERVERS, GEARMAN_AT, "no servers provided"); |
1075 | 69 | } | 69 | } |
1076 | 70 | 70 | ||
1078 | 71 | for (task->con= task->client->impl()->universal.con_list; task->con; | 71 | for (task->con= task->client->universal.con_list; task->con; |
1079 | 72 | task->con= task->con->next_connection()) | 72 | task->con= task->con->next_connection()) |
1080 | 73 | { | 73 | { |
1081 | 74 | if (task->con->send_state == GEARMAN_CON_SEND_STATE_NONE) | 74 | if (task->con->send_state == GEARMAN_CON_SEND_STATE_NONE) |
1082 | @@ -79,11 +79,11 @@ | |||
1083 | 79 | 79 | ||
1084 | 80 | if (task->con == NULL) | 80 | if (task->con == NULL) |
1085 | 81 | { | 81 | { |
1088 | 82 | task->client->impl()->options.no_new= true; | 82 | task->client->options.no_new= true; |
1089 | 83 | return gearman_gerror(task->client->impl()->universal, GEARMAN_IO_WAIT); | 83 | return gearman_gerror(task->client->universal, GEARMAN_IO_WAIT); |
1090 | 84 | } | 84 | } |
1091 | 85 | 85 | ||
1093 | 86 | task->client->impl()->new_tasks--; | 86 | task->client->new_tasks--; |
1094 | 87 | 87 | ||
1095 | 88 | if (task->send.command != GEARMAN_COMMAND_GET_STATUS) | 88 | if (task->send.command != GEARMAN_COMMAND_GET_STATUS) |
1096 | 89 | { | 89 | { |
1097 | @@ -95,7 +95,7 @@ | |||
1098 | 95 | while (1) | 95 | while (1) |
1099 | 96 | { | 96 | { |
1100 | 97 | assert(task->con); | 97 | assert(task->con); |
1102 | 98 | gearman_return_t ret= task->con->send_packet(task->send, task->client->impl()->new_tasks == 0 ? true : false); | 98 | gearman_return_t ret= task->con->send_packet(task->send, task->client->new_tasks == 0 ? true : false); |
1103 | 99 | 99 | ||
1104 | 100 | if (gearman_success(ret)) | 100 | if (gearman_success(ret)) |
1105 | 101 | { | 101 | { |
1106 | @@ -134,13 +134,23 @@ | |||
1107 | 134 | 134 | ||
1108 | 135 | if (ret == GEARMAN_COULD_NOT_CONNECT) // If no connection is found, we will let the user try again | 135 | if (ret == GEARMAN_COULD_NOT_CONNECT) // If no connection is found, we will let the user try again |
1109 | 136 | { | 136 | { |
1110 | 137 | <<<<<<< TREE | ||
1111 | 137 | task->set_state(GEARMAN_TASK_STATE_NEW); | 138 | task->set_state(GEARMAN_TASK_STATE_NEW); |
1112 | 138 | task->client->impl()->new_tasks++; | 139 | task->client->impl()->new_tasks++; |
1113 | 140 | ======= | ||
1114 | 141 | task->set_state(GEARMAN_TASK_STATE_NEW); | ||
1115 | 142 | task->client->new_tasks++; | ||
1116 | 143 | >>>>>>> MERGE-SOURCE | ||
1117 | 139 | } | 144 | } |
1118 | 140 | else | 145 | else |
1119 | 141 | { | 146 | { |
1120 | 147 | <<<<<<< TREE | ||
1121 | 142 | task->set_state(GEARMAN_TASK_STATE_FAIL); | 148 | task->set_state(GEARMAN_TASK_STATE_FAIL); |
1122 | 143 | task->client->impl()->running_tasks--; | 149 | task->client->impl()->running_tasks--; |
1123 | 150 | ======= | ||
1124 | 151 | task->set_state(GEARMAN_TASK_STATE_FAIL); | ||
1125 | 152 | task->client->running_tasks--; | ||
1126 | 153 | >>>>>>> MERGE-SOURCE | ||
1127 | 144 | } | 154 | } |
1128 | 145 | return ret; | 155 | return ret; |
1129 | 146 | } | 156 | } |
1130 | @@ -157,7 +167,7 @@ | |||
1131 | 157 | { | 167 | { |
1132 | 158 | if (not task->func.workload_fn) | 168 | if (not task->func.workload_fn) |
1133 | 159 | { | 169 | { |
1135 | 160 | gearman_error(task->client->impl()->universal, GEARMAN_NEED_WORKLOAD_FN, | 170 | gearman_error(task->client->universal, GEARMAN_NEED_WORKLOAD_FN, |
1136 | 161 | "workload size > 0, but no data pointer or workload_fn was given"); | 171 | "workload size > 0, but no data pointer or workload_fn was given"); |
1137 | 162 | return GEARMAN_NEED_WORKLOAD_FN; | 172 | return GEARMAN_NEED_WORKLOAD_FN; |
1138 | 163 | } | 173 | } |
1139 | @@ -171,8 +181,13 @@ | |||
1140 | 171 | } | 181 | } |
1141 | 172 | } | 182 | } |
1142 | 173 | 183 | ||
1143 | 184 | <<<<<<< TREE | ||
1144 | 174 | task->client->impl()->options.no_new= false; | 185 | task->client->impl()->options.no_new= false; |
1145 | 175 | task->set_state(GEARMAN_TASK_STATE_WORK); | 186 | task->set_state(GEARMAN_TASK_STATE_WORK); |
1146 | 187 | ======= | ||
1147 | 188 | task->client->options.no_new= false; | ||
1148 | 189 | task->set_state(GEARMAN_TASK_STATE_WORK); | ||
1149 | 190 | >>>>>>> MERGE-SOURCE | ||
1150 | 176 | task->con->set_events(POLLIN); | 191 | task->con->set_events(POLLIN); |
1151 | 177 | return GEARMAN_SUCCESS; | 192 | return GEARMAN_SUCCESS; |
1152 | 178 | 193 | ||
1153 | @@ -407,6 +422,7 @@ | |||
1154 | 407 | break; | 422 | break; |
1155 | 408 | } | 423 | } |
1156 | 409 | 424 | ||
1157 | 425 | <<<<<<< TREE | ||
1158 | 410 | task->client->impl()->running_tasks--; | 426 | task->client->impl()->running_tasks--; |
1159 | 411 | task->set_state(GEARMAN_TASK_STATE_FINISHED); | 427 | task->set_state(GEARMAN_TASK_STATE_FINISHED); |
1160 | 412 | 428 | ||
1161 | @@ -414,6 +430,14 @@ | |||
1162 | 414 | assert(task->result_rc != GEARMAN_UNKNOWN_STATE); | 430 | assert(task->result_rc != GEARMAN_UNKNOWN_STATE); |
1163 | 415 | 431 | ||
1164 | 416 | if (task->client->impl()->options.free_tasks and task->type == GEARMAN_TASK_KIND_ADD_TASK) | 432 | if (task->client->impl()->options.free_tasks and task->type == GEARMAN_TASK_KIND_ADD_TASK) |
1165 | 433 | ======= | ||
1166 | 434 | task->client->running_tasks--; | ||
1167 | 435 | task->set_state(GEARMAN_TASK_STATE_FINISHED); | ||
1168 | 436 | |||
1169 | 437 | assert(task->result_rc != GEARMAN_UNKNOWN_STATE); | ||
1170 | 438 | |||
1171 | 439 | if (task->client->options.free_tasks and task->type == GEARMAN_TASK_KIND_ADD_TASK) | ||
1172 | 440 | >>>>>>> MERGE-SOURCE | ||
1173 | 417 | { | 441 | { |
1174 | 418 | gearman_task_free(task->shell()); | 442 | gearman_task_free(task->shell()); |
1175 | 419 | } | 443 | } |
1176 | 420 | 444 | ||
1177 | === modified file 'libgearman/task.cc' | |||
1178 | --- libgearman/task.cc 2013-05-11 11:15:03 +0000 | |||
1179 | +++ libgearman/task.cc 2013-07-06 19:18:28 +0000 | |||
1180 | @@ -59,7 +59,6 @@ | |||
1181 | 59 | Task* task= new (std::nothrow) Task(client, task_shell); | 59 | Task* task= new (std::nothrow) Task(client, task_shell); |
1182 | 60 | if (task) | 60 | if (task) |
1183 | 61 | { | 61 | { |
1184 | 62 | assert(task->client == &client); | ||
1185 | 63 | return task->shell(); | 62 | return task->shell(); |
1186 | 64 | } | 63 | } |
1187 | 65 | 64 | ||
1188 | @@ -69,6 +68,10 @@ | |||
1189 | 69 | return NULL; | 68 | return NULL; |
1190 | 70 | } | 69 | } |
1191 | 71 | 70 | ||
1192 | 71 | void gearman_task_free(Task* task) | ||
1193 | 72 | { | ||
1194 | 73 | gearman_task_free(task->shell()); | ||
1195 | 74 | } | ||
1196 | 72 | 75 | ||
1197 | 73 | void gearman_task_free(gearman_task_st *task_shell) | 76 | void gearman_task_free(gearman_task_st *task_shell) |
1198 | 74 | { | 77 | { |
1199 | @@ -91,14 +94,14 @@ | |||
1200 | 91 | gearman_packet_free(&(task->send)); | 94 | gearman_packet_free(&(task->send)); |
1201 | 92 | } | 95 | } |
1202 | 93 | 96 | ||
1204 | 94 | if (task->type != GEARMAN_TASK_KIND_DO and task->context and task->client->impl()->task_context_free_fn) | 97 | if (task->type != GEARMAN_TASK_KIND_DO and task->context and task->client->task_context_free_fn) |
1205 | 95 | { | 98 | { |
1207 | 96 | task->client->impl()->task_context_free_fn(task_shell, static_cast<void *>(task->context)); | 99 | task->client->task_context_free_fn(task_shell, static_cast<void *>(task->context)); |
1208 | 97 | } | 100 | } |
1209 | 98 | 101 | ||
1211 | 99 | if (task->client->impl()->task_list == task_shell) | 102 | if (task->client->task_list == task_shell) |
1212 | 100 | { | 103 | { |
1214 | 101 | task->client->impl()->task_list= task->next; | 104 | task->client->task_list= task->next; |
1215 | 102 | } | 105 | } |
1216 | 103 | 106 | ||
1217 | 104 | if (task->prev) | 107 | if (task->prev) |
1218 | @@ -111,13 +114,13 @@ | |||
1219 | 111 | task->next->impl()->prev= task->prev; | 114 | task->next->impl()->prev= task->prev; |
1220 | 112 | } | 115 | } |
1221 | 113 | 116 | ||
1223 | 114 | task->client->impl()->task_count--; | 117 | task->client->task_count--; |
1224 | 115 | 118 | ||
1225 | 116 | // If the task we are removing is a current task, remove it from the client | 119 | // If the task we are removing is a current task, remove it from the client |
1226 | 117 | // structures. | 120 | // structures. |
1228 | 118 | if (task->client->impl()->task == task_shell) | 121 | if (task->client->task == task_shell) |
1229 | 119 | { | 122 | { |
1231 | 120 | task->client->impl()->task= NULL; | 123 | task->client->task= NULL; |
1232 | 121 | } | 124 | } |
1233 | 122 | task->client= NULL; | 125 | task->client= NULL; |
1234 | 123 | } | 126 | } |
1235 | 124 | 127 | ||
1236 | === modified file 'libgearman/task.hpp' | |||
1237 | --- libgearman/task.hpp 2013-01-31 05:27:46 +0000 | |||
1238 | +++ libgearman/task.hpp 2013-07-06 19:18:28 +0000 | |||
1239 | @@ -49,6 +49,8 @@ | |||
1240 | 49 | gearman_task_st *gearman_task_internal_create(gearman_client_st& client, | 49 | gearman_task_st *gearman_task_internal_create(gearman_client_st& client, |
1241 | 50 | gearman_task_st *task); | 50 | gearman_task_st *task); |
1242 | 51 | 51 | ||
1243 | 52 | void gearman_task_free(Task* task); | ||
1244 | 53 | |||
1245 | 52 | void gearman_task_clear_fn(gearman_task_st *task); | 54 | void gearman_task_clear_fn(gearman_task_st *task); |
1246 | 53 | 55 | ||
1247 | 54 | bool gearman_task_is_active(const gearman_task_st *self); | 56 | bool gearman_task_is_active(const gearman_task_st *self); |