Merge lp:~brianaker/gearmand/merge-july into lp:gearmand
- merge-july
- Merge into 1.2
Proposed by
Brian Aker
Status: | Merged |
---|---|
Merged at revision: | 811 |
Proposed branch: | lp:~brianaker/gearmand/merge-july |
Merge into: | lp:gearmand |
Diff against target: |
1226 lines (+271/-256) 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 (+18/-18) libgearman/task.cc (+11/-8) libgearman/task.hpp (+2/-0) |
To merge this branch: | bzr merge lp:~brianaker/gearmand/merge-july |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tangent Trunk | Pending | ||
Review via email: mp+173329@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 20:13:28 +0000 |
4 | @@ -68,7 +68,7 @@ |
5 | { |
6 | if (task->create_result(gearman_task_data_size(shell)) == false) |
7 | { |
8 | - return gearman_error(task->client->impl()->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Failed to create result_st"); |
9 | + return gearman_error(task->client->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Failed to create result_st"); |
10 | } |
11 | } |
12 | assert_msg(task->result(), "programmer error, result_ptr has not been allocated for task"); |
13 | @@ -137,7 +137,7 @@ |
14 | { |
15 | if (task->create_result(gearman_task_data_size(shell)) == false) |
16 | { |
17 | - return gearman_error(task->client->impl()->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Failed to create result_st"); |
18 | + return gearman_error(task->client->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Failed to create result_st"); |
19 | } |
20 | } |
21 | |
22 | @@ -158,7 +158,7 @@ |
23 | { |
24 | if (task->create_result(gearman_task_data_size(shell)) == false) |
25 | { |
26 | - return gearman_error(task->client->impl()->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Failed to create result_st"); |
27 | + return gearman_error(task->client->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Failed to create result_st"); |
28 | } |
29 | } |
30 | |
31 | |
32 | === modified file 'libgearman/add.cc' |
33 | --- libgearman/add.cc 2013-07-03 09:00:14 +0000 |
34 | +++ libgearman/add.cc 2013-07-06 20:13:28 +0000 |
35 | @@ -202,7 +202,6 @@ |
36 | return NULL; |
37 | } |
38 | assert(task_shell->impl()->client); |
39 | - assert(task_shell->impl()->client == &client); |
40 | |
41 | Task* task= task_shell->impl(); |
42 | |
43 | @@ -229,7 +228,7 @@ |
44 | { |
45 | if (safe_uuid_generate(task->unique, task->unique_length) == -1) |
46 | { |
47 | - gearman_log_debug(task->client->impl()->universal, "uuid_generate_time_safe() failed or does not exist on this platform"); |
48 | + gearman_log_debug(task->client->universal, "uuid_generate_time_safe() failed or does not exist on this platform"); |
49 | } |
50 | } |
51 | else |
52 | @@ -242,7 +241,6 @@ |
53 | gearman_unique_t final_unique= gearman_unique_make(task->unique, task->unique_length); |
54 | |
55 | assert(task->client); |
56 | - assert(task->client == &client); |
57 | |
58 | gearman_return_t rc= GEARMAN_INVALID_ARGUMENT; |
59 | switch (command) |
60 | @@ -250,7 +248,7 @@ |
61 | case GEARMAN_COMMAND_SUBMIT_JOB: |
62 | case GEARMAN_COMMAND_SUBMIT_JOB_LOW: |
63 | case GEARMAN_COMMAND_SUBMIT_JOB_HIGH: |
64 | - rc= libgearman::protocol::submit(task->client->impl()->universal, |
65 | + rc= libgearman::protocol::submit(task->client->universal, |
66 | task->send, |
67 | final_unique, |
68 | command, |
69 | @@ -259,7 +257,7 @@ |
70 | break; |
71 | |
72 | case GEARMAN_COMMAND_SUBMIT_JOB_EPOCH: |
73 | - rc= libgearman::protocol::submit_epoch(task->client->impl()->universal, |
74 | + rc= libgearman::protocol::submit_epoch(task->client->universal, |
75 | task->send, |
76 | final_unique, |
77 | function, |
78 | @@ -270,7 +268,7 @@ |
79 | case GEARMAN_COMMAND_SUBMIT_JOB_BG: |
80 | case GEARMAN_COMMAND_SUBMIT_JOB_LOW_BG: |
81 | case GEARMAN_COMMAND_SUBMIT_JOB_HIGH_BG: |
82 | - rc= libgearman::protocol::submit_background(task->client->impl()->universal, |
83 | + rc= libgearman::protocol::submit_background(task->client->universal, |
84 | task->send, |
85 | final_unique, |
86 | command, |
87 | @@ -379,15 +377,16 @@ |
88 | return NULL; |
89 | } |
90 | |
91 | - gearman_task_st *task= gearman_task_internal_create(*client, NULL); |
92 | - if (task == NULL) |
93 | + gearman_task_st *task_shell= gearman_task_internal_create(*client, NULL); |
94 | + if (task_shell == NULL) |
95 | { |
96 | assert(client->impl()->universal.error_code()); |
97 | return NULL; |
98 | } |
99 | |
100 | - task->impl()->context= context; |
101 | - task->impl()->func= actions; |
102 | + Task* task= task_shell->impl(); |
103 | + task->context= context; |
104 | + task->func= actions; |
105 | |
106 | /** |
107 | @todo fix it so that NULL is done by default by the API not by happenstance. |
108 | @@ -413,33 +412,33 @@ |
109 | |
110 | if (gearman_unique_is_hash(unique)) |
111 | { |
112 | - task->impl()->unique_length= snprintf(task->impl()->unique, GEARMAN_MAX_UNIQUE_SIZE, "%u", libhashkit_murmur3(gearman_string_param(workload))); |
113 | + task->unique_length= snprintf(task->unique, GEARMAN_MAX_UNIQUE_SIZE, "%u", libhashkit_murmur3(gearman_string_param(workload))); |
114 | } |
115 | - else if ((task->impl()->unique_length= gearman_size(unique))) |
116 | + else if ((task->unique_length= gearman_size(unique))) |
117 | { |
118 | - if (task->impl()->unique_length >= GEARMAN_MAX_UNIQUE_SIZE) |
119 | + if (task->unique_length >= GEARMAN_MAX_UNIQUE_SIZE) |
120 | { |
121 | - task->impl()->unique_length= GEARMAN_MAX_UNIQUE_SIZE -1; // Leave space for NULL byte |
122 | + task->unique_length= GEARMAN_MAX_UNIQUE_SIZE -1; // Leave space for NULL byte |
123 | } |
124 | |
125 | - strncpy(task->impl()->unique, gearman_c_str(unique), GEARMAN_MAX_UNIQUE_SIZE); |
126 | - task->impl()->unique[task->impl()->unique_length]= 0; |
127 | + strncpy(task->unique, gearman_c_str(unique), GEARMAN_MAX_UNIQUE_SIZE); |
128 | + task->unique[task->unique_length]= 0; |
129 | } |
130 | else |
131 | { |
132 | if (client->impl()->options.generate_unique or is_background(command)) |
133 | { |
134 | - safe_uuid_generate(task->impl()->unique, task->impl()->unique_length); |
135 | + safe_uuid_generate(task->unique, task->unique_length); |
136 | } |
137 | else |
138 | { |
139 | - task->impl()->unique_length= 0; |
140 | - task->impl()->unique[0]= 0; |
141 | + task->unique_length= 0; |
142 | + task->unique[0]= 0; |
143 | } |
144 | } |
145 | |
146 | - args[1]= task->impl()->unique; |
147 | - args_size[1]= task->impl()->unique_length +1; // +1 is for the needed null |
148 | + args[1]= task->unique; |
149 | + args_size[1]= task->unique_length +1; // +1 is for the needed null |
150 | |
151 | assert_msg(command == GEARMAN_COMMAND_SUBMIT_REDUCE_JOB or command == GEARMAN_COMMAND_SUBMIT_REDUCE_JOB_BACKGROUND, |
152 | "Command was not appropriate for request"); |
153 | @@ -474,14 +473,14 @@ |
154 | args_size[4]= gearman_size(workload); |
155 | |
156 | gearman_return_t rc; |
157 | - if (gearman_success(rc= gearman_packet_create_args(client->impl()->universal, task->impl()->send, |
158 | + if (gearman_success(rc= gearman_packet_create_args(client->impl()->universal, task->send, |
159 | GEARMAN_MAGIC_REQUEST, command, |
160 | args, args_size, |
161 | 5))) |
162 | { |
163 | client->impl()->new_tasks++; |
164 | client->impl()->running_tasks++; |
165 | - task->impl()->options.send_in_use= true; |
166 | + task->options.send_in_use= true; |
167 | } |
168 | else |
169 | { |
170 | @@ -489,7 +488,7 @@ |
171 | gearman_task_free(task); |
172 | task= NULL; |
173 | } |
174 | - task->impl()->type= GEARMAN_TASK_KIND_EXECUTE; |
175 | + task->type= GEARMAN_TASK_KIND_EXECUTE; |
176 | |
177 | - return task; |
178 | + return task->shell(); |
179 | } |
180 | |
181 | === modified file 'libgearman/client.cc' |
182 | --- libgearman/client.cc 2013-07-06 08:02:19 +0000 |
183 | +++ libgearman/client.cc 2013-07-06 20:13:28 +0000 |
184 | @@ -89,7 +89,7 @@ |
185 | /** |
186 | * Real do function. |
187 | */ |
188 | -static void *_client_do(gearman_client_st *client, gearman_command_t command, |
189 | +static void *_client_do(gearman_client_st *client_shell, gearman_command_t command, |
190 | const char *function_name, |
191 | const char *unique, |
192 | const void *workload_str, size_t workload_size, |
193 | @@ -101,13 +101,15 @@ |
194 | ret_ptr= &unused; |
195 | } |
196 | |
197 | - if (client == NULL or client->impl() == NULL) |
198 | + if (client_shell == NULL or client_shell->impl() == NULL) |
199 | { |
200 | *ret_ptr= GEARMAN_INVALID_ARGUMENT; |
201 | return NULL; |
202 | } |
203 | |
204 | - client->impl()->universal.reset_error(); |
205 | + Client* client= client_shell->impl(); |
206 | + |
207 | + client->universal.reset_error(); |
208 | |
209 | size_t unused_size; |
210 | if (result_size == NULL) |
211 | @@ -122,17 +124,17 @@ |
212 | |
213 | gearman_task_st do_task; |
214 | { |
215 | - client->impl()->universal.options.no_new_data= true; |
216 | - gearman_task_st *do_task_ptr= add_task(*client, &do_task, NULL, command, |
217 | + client->universal.options.no_new_data= true; |
218 | + gearman_task_st *do_task_ptr= add_task(*(client->shell()), &do_task, NULL, command, |
219 | function, |
220 | local_unique, |
221 | workload, |
222 | time_t(0), |
223 | gearman_actions_do_default()); |
224 | - client->impl()->universal.options.no_new_data= false; |
225 | + client->universal.options.no_new_data= false; |
226 | if (do_task_ptr == NULL) |
227 | { |
228 | - *ret_ptr= client->impl()->universal.error_code(); |
229 | + *ret_ptr= client->universal.error_code(); |
230 | return NULL; |
231 | } |
232 | assert_msg(do_task.impl(), "Bad return by add_task()"); |
233 | @@ -141,10 +143,10 @@ |
234 | |
235 | do_task.impl()->type= GEARMAN_TASK_KIND_DO; |
236 | |
237 | - gearman_return_t ret= gearman_client_run_block_tasks(client, &do_task); |
238 | + gearman_return_t ret= gearman_client_run_block_tasks(client->shell(), &do_task); |
239 | |
240 | // gearman_client_run_tasks failed |
241 | - assert(client->impl()->task_list); // Programmer error, we should always have the task that we used for do |
242 | + assert(client->task_list); // Programmer error, we should always have the task that we used for do |
243 | |
244 | char *returnable= NULL; |
245 | if (gearman_failed(ret)) |
246 | @@ -153,7 +155,7 @@ |
247 | { } |
248 | else |
249 | { |
250 | - gearman_error(client->impl()->universal, ret, "occured during gearman_client_run_tasks()"); |
251 | + gearman_error(client->universal, ret, "occured during gearman_client_run_tasks()"); |
252 | } |
253 | |
254 | *ret_ptr= ret; |
255 | @@ -164,13 +166,13 @@ |
256 | *ret_ptr= do_task.impl()->result_rc; |
257 | if (gearman_task_result(&do_task)) |
258 | { |
259 | - if (gearman_has_allocator(client->impl()->universal)) |
260 | + if (gearman_has_allocator(client->universal)) |
261 | { |
262 | gearman_string_t result= gearman_result_string(do_task.impl()->result()); |
263 | - returnable= static_cast<char *>(gearman_malloc(client->impl()->universal, gearman_size(result) +1)); |
264 | + returnable= static_cast<char *>(gearman_malloc(client->universal, gearman_size(result) +1)); |
265 | if (returnable == NULL) |
266 | { |
267 | - gearman_error(client->impl()->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "custom workload_fn failed to allocate memory"); |
268 | + gearman_error(client->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "custom workload_fn failed to allocate memory"); |
269 | *result_size= 0; |
270 | } |
271 | else // NULL terminate |
272 | @@ -194,15 +196,15 @@ |
273 | } |
274 | else // gearman_client_run_tasks() was successful, but the task was not |
275 | { |
276 | - gearman_error(client->impl()->universal, do_task.impl()->result_rc, "occured during gearman_client_run_tasks()"); |
277 | + gearman_error(client->universal, do_task.impl()->result_rc, "occured during gearman_client_run_tasks()"); |
278 | |
279 | *ret_ptr= do_task.impl()->result_rc; |
280 | *result_size= 0; |
281 | } |
282 | |
283 | gearman_task_free(&do_task); |
284 | - client->impl()->new_tasks= 0; |
285 | - client->impl()->running_tasks= 0; |
286 | + client->new_tasks= 0; |
287 | + client->running_tasks= 0; |
288 | |
289 | return returnable; |
290 | } |
291 | @@ -210,31 +212,32 @@ |
292 | /* |
293 | Real background do function. |
294 | */ |
295 | -static gearman_return_t _client_do_background(gearman_client_st *client, |
296 | +static gearman_return_t _client_do_background(gearman_client_st* client_shell, |
297 | gearman_command_t command, |
298 | gearman_string_t &function, |
299 | gearman_unique_t &unique, |
300 | gearman_string_t &workload, |
301 | gearman_job_handle_t job_handle) |
302 | { |
303 | - if (client == NULL) |
304 | + if (client_shell == NULL or client_shell->impl() == NULL) |
305 | { |
306 | return GEARMAN_INVALID_ARGUMENT; |
307 | } |
308 | |
309 | - client->impl()->universal.reset_error(); |
310 | + Client* client= client_shell->impl(); |
311 | + client->universal.reset_error(); |
312 | |
313 | if (gearman_size(function) == 0) |
314 | { |
315 | - return gearman_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, "function argument was empty"); |
316 | + return gearman_error(client->universal, GEARMAN_INVALID_ARGUMENT, "function argument was empty"); |
317 | } |
318 | |
319 | - client->impl()->_do_handle[0]= 0; // Reset the job_handle we store in client |
320 | + client->_do_handle[0]= 0; // Reset the job_handle we store in client |
321 | |
322 | gearman_task_st do_task; |
323 | { |
324 | - client->impl()->universal.options.no_new_data= true; |
325 | - gearman_task_st* do_task_ptr= add_task(*client, &do_task, |
326 | + client->universal.options.no_new_data= true; |
327 | + gearman_task_st* do_task_ptr= add_task(*client_shell, &do_task, |
328 | client, |
329 | command, |
330 | function, |
331 | @@ -242,26 +245,26 @@ |
332 | workload, |
333 | time_t(0), |
334 | gearman_actions_do_default()); |
335 | - client->impl()->universal.options.no_new_data= false; |
336 | + client->universal.options.no_new_data= false; |
337 | |
338 | if (do_task_ptr == NULL) |
339 | { |
340 | - return client->impl()->universal.error_code(); |
341 | + return client->universal.error_code(); |
342 | } |
343 | assert(do_task_ptr); |
344 | assert(&do_task == do_task_ptr); |
345 | } |
346 | do_task.impl()->type= GEARMAN_TASK_KIND_DO; |
347 | |
348 | - gearman_return_t ret= gearman_client_run_block_tasks(client, &do_task); |
349 | + gearman_return_t ret= gearman_client_run_block_tasks(client_shell, &do_task); |
350 | |
351 | if (job_handle) |
352 | { |
353 | strncpy(job_handle, do_task.impl()->job_handle, GEARMAN_JOB_HANDLE_SIZE); |
354 | } |
355 | - strncpy(client->impl()->_do_handle, do_task.impl()->job_handle, GEARMAN_JOB_HANDLE_SIZE); |
356 | - client->impl()->new_tasks= 0; |
357 | - client->impl()->running_tasks= 0; |
358 | + strncpy(client->_do_handle, do_task.impl()->job_handle, GEARMAN_JOB_HANDLE_SIZE); |
359 | + client->new_tasks= 0; |
360 | + client->running_tasks= 0; |
361 | gearman_task_free(&do_task); |
362 | |
363 | return ret; |
364 | @@ -393,31 +396,33 @@ |
365 | { |
366 | if (client_shell and client_shell->impl()) |
367 | { |
368 | + Client* client= client_shell->impl(); |
369 | + |
370 | switch (option) |
371 | { |
372 | case GEARMAN_CLIENT_ALLOCATED: |
373 | return gearman_is_allocated(client_shell); |
374 | |
375 | case GEARMAN_CLIENT_NON_BLOCKING: |
376 | - return client_shell->impl()->options.non_blocking; |
377 | + return client->options.non_blocking; |
378 | |
379 | case GEARMAN_CLIENT_UNBUFFERED_RESULT: |
380 | - return client_shell->impl()->options.unbuffered_result; |
381 | + return client->options.unbuffered_result; |
382 | |
383 | case GEARMAN_CLIENT_NO_NEW: |
384 | - return client_shell->impl()->options.no_new; |
385 | + return client->options.no_new; |
386 | |
387 | case GEARMAN_CLIENT_FREE_TASKS: |
388 | - return client_shell->impl()->options.free_tasks; |
389 | + return client->options.free_tasks; |
390 | |
391 | case GEARMAN_CLIENT_GENERATE_UNIQUE: |
392 | - return client_shell->impl()->options.generate_unique; |
393 | + return client->options.generate_unique; |
394 | |
395 | case GEARMAN_CLIENT_EXCEPTION: |
396 | - return client_shell->impl()->options.exceptions; |
397 | + return client->options.exceptions; |
398 | |
399 | case GEARMAN_CLIENT_SSL: |
400 | - return client_shell->impl()->ssl(); |
401 | + return client->ssl(); |
402 | |
403 | default: |
404 | case GEARMAN_CLIENT_TASK_IN_USE: |
405 | @@ -463,35 +468,36 @@ |
406 | { |
407 | if (client_shell and client_shell->impl()) |
408 | { |
409 | + Client* client= client_shell->impl(); |
410 | if (options & GEARMAN_CLIENT_NON_BLOCKING) |
411 | { |
412 | - gearman_universal_add_options(client_shell->impl()->universal, GEARMAN_UNIVERSAL_NON_BLOCKING); |
413 | - client_shell->impl()->options.non_blocking= true; |
414 | + gearman_universal_add_options(client->universal, GEARMAN_UNIVERSAL_NON_BLOCKING); |
415 | + client->options.non_blocking= true; |
416 | } |
417 | |
418 | if (options & GEARMAN_CLIENT_UNBUFFERED_RESULT) |
419 | { |
420 | - client_shell->impl()->options.unbuffered_result= true; |
421 | + client->options.unbuffered_result= true; |
422 | } |
423 | |
424 | if (options & GEARMAN_CLIENT_FREE_TASKS) |
425 | { |
426 | - client_shell->impl()->options.free_tasks= true; |
427 | + client->options.free_tasks= true; |
428 | } |
429 | |
430 | if (options & GEARMAN_CLIENT_GENERATE_UNIQUE) |
431 | { |
432 | - client_shell->impl()->options.generate_unique= true; |
433 | + client->options.generate_unique= true; |
434 | } |
435 | |
436 | if (options & GEARMAN_CLIENT_EXCEPTION) |
437 | { |
438 | - client_shell->impl()->options.exceptions= gearman_client_set_server_option(client_shell, gearman_literal_param("exceptions")); |
439 | + client->options.exceptions= gearman_client_set_server_option(client_shell, gearman_literal_param("exceptions")); |
440 | } |
441 | |
442 | if (options & GEARMAN_CLIENT_SSL) |
443 | { |
444 | - client_shell->impl()->ssl(true); |
445 | + client->ssl(true); |
446 | } |
447 | } |
448 | } |
449 | @@ -501,25 +507,27 @@ |
450 | { |
451 | if (client_shell and client_shell->impl()) |
452 | { |
453 | + Client* client= client_shell->impl(); |
454 | + |
455 | if (options & GEARMAN_CLIENT_NON_BLOCKING) |
456 | { |
457 | - gearman_universal_remove_options(client_shell->impl()->universal, GEARMAN_UNIVERSAL_NON_BLOCKING); |
458 | - client_shell->impl()->options.non_blocking= false; |
459 | + gearman_universal_remove_options(client->universal, GEARMAN_UNIVERSAL_NON_BLOCKING); |
460 | + client->options.non_blocking= false; |
461 | } |
462 | |
463 | if (options & GEARMAN_CLIENT_UNBUFFERED_RESULT) |
464 | { |
465 | - client_shell->impl()->options.unbuffered_result= false; |
466 | + client->options.unbuffered_result= false; |
467 | } |
468 | |
469 | if (options & GEARMAN_CLIENT_FREE_TASKS) |
470 | { |
471 | - client_shell->impl()->options.free_tasks= false; |
472 | + client->options.free_tasks= false; |
473 | } |
474 | |
475 | if (options & GEARMAN_CLIENT_GENERATE_UNIQUE) |
476 | { |
477 | - client_shell->impl()->options.generate_unique= false; |
478 | + client->options.generate_unique= false; |
479 | } |
480 | } |
481 | } |
482 | @@ -988,13 +996,14 @@ |
483 | return gearman_echo(client->impl()->universal, workload, workload_size); |
484 | } |
485 | |
486 | -void gearman_client_task_free_all(gearman_client_st *client) |
487 | +void gearman_client_task_free_all(gearman_client_st *client_shell) |
488 | { |
489 | - if (client and client->impl() and client->impl()->task_list) |
490 | + if (client_shell and client_shell->impl() and client_shell->impl()->task_list) |
491 | { |
492 | - while (client->impl()->task_list) |
493 | + Client* client= client_shell->impl(); |
494 | + while (client->task_list) |
495 | { |
496 | - gearman_task_free(client->impl()->task_list); |
497 | + gearman_task_free(client->task_list); |
498 | } |
499 | } |
500 | } |
501 | @@ -1397,96 +1406,96 @@ |
502 | } |
503 | } |
504 | |
505 | -static inline gearman_return_t _client_run_tasks(gearman_client_st *client, gearman_task_st* exit_task) |
506 | +static inline gearman_return_t _client_run_tasks(gearman_client_st *client_shell, gearman_task_st* exit_task) |
507 | { |
508 | gearman_return_t ret= GEARMAN_MAX_RETURN; |
509 | |
510 | - switch(client->impl()->state) |
511 | + Client* client= client_shell->impl(); |
512 | + |
513 | + switch(client->state) |
514 | { |
515 | case GEARMAN_CLIENT_STATE_IDLE: |
516 | while (1) |
517 | { |
518 | /* Start any new tasks. */ |
519 | - if (client->impl()->new_tasks > 0 && ! (client->impl()->options.no_new)) |
520 | + if (client->new_tasks > 0 && ! (client->options.no_new)) |
521 | { |
522 | - for (client->impl()->task= client->impl()->task_list; client->impl()->task; |
523 | - client->impl()->task= client->impl()->task->impl()->next) |
524 | + for (client->task= client->task_list; client->task; |
525 | + client->task= client->task->impl()->next) |
526 | { |
527 | - if (client->impl()->task->impl()->state != GEARMAN_TASK_STATE_NEW) |
528 | + if (client->task->impl()->state != GEARMAN_TASK_STATE_NEW) |
529 | { |
530 | continue; |
531 | } |
532 | |
533 | case GEARMAN_CLIENT_STATE_NEW: |
534 | - if (client->impl()->task == NULL) |
535 | + if (client->task == NULL) |
536 | { |
537 | - client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
538 | + client->state= GEARMAN_CLIENT_STATE_IDLE; |
539 | break; |
540 | } |
541 | |
542 | - assert_msg(client == client->impl()->task->impl()->client, "Programmer error, client and task member client are not the same"); |
543 | - gearman_return_t local_ret= _client_run_task(client->impl()->task->impl()); |
544 | + gearman_return_t local_ret= _client_run_task(client->task->impl()); |
545 | if (gearman_failed(local_ret) and local_ret != GEARMAN_IO_WAIT) |
546 | { |
547 | - client->impl()->state= GEARMAN_CLIENT_STATE_NEW; |
548 | + client->state= GEARMAN_CLIENT_STATE_NEW; |
549 | |
550 | return local_ret; |
551 | } |
552 | } |
553 | |
554 | - if (client->impl()->new_tasks == 0) |
555 | + if (client->new_tasks == 0) |
556 | { |
557 | - gearman_flush_all(client->impl()->universal); |
558 | + gearman_flush_all(client->universal); |
559 | } |
560 | } |
561 | |
562 | /* See if there are any connections ready for I/O. */ |
563 | - while ((client->impl()->con= gearman_ready(client->impl()->universal))) |
564 | + while ((client->con= gearman_ready(client->universal))) |
565 | { |
566 | - if (client->impl()->con->revents & (POLLOUT | POLLERR | POLLHUP | POLLNVAL)) |
567 | + if (client->con->revents & (POLLOUT | POLLERR | POLLHUP | POLLNVAL)) |
568 | { |
569 | /* Socket is ready for writing, continue submitting jobs. */ |
570 | - for (client->impl()->task= client->impl()->task_list; client->impl()->task; |
571 | - client->impl()->task= client->impl()->task->impl()->next) |
572 | + for (client->task= client->task_list; client->task; |
573 | + client->task= client->task->impl()->next) |
574 | { |
575 | - if (client->impl()->task->impl()->con != client->impl()->con or |
576 | - (client->impl()->task->impl()->state != GEARMAN_TASK_STATE_SUBMIT and |
577 | - client->impl()->task->impl()->state != GEARMAN_TASK_STATE_WORKLOAD)) |
578 | + if (client->task->impl()->con != client->con or |
579 | + (client->task->impl()->state != GEARMAN_TASK_STATE_SUBMIT and |
580 | + client->task->impl()->state != GEARMAN_TASK_STATE_WORKLOAD)) |
581 | { |
582 | continue; |
583 | } |
584 | |
585 | case GEARMAN_CLIENT_STATE_SUBMIT: |
586 | - if (client->impl()->task == NULL) |
587 | + if (client->task == NULL) |
588 | { |
589 | - client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
590 | + client->state= GEARMAN_CLIENT_STATE_IDLE; |
591 | break; |
592 | } |
593 | - assert_msg(client == client->impl()->task->impl()->client, "Programmer error, client and task member client are not the same"); |
594 | - gearman_return_t local_ret= _client_run_task(client->impl()->task->impl()); |
595 | + gearman_return_t local_ret= _client_run_task(client->task->impl()); |
596 | if (local_ret == GEARMAN_COULD_NOT_CONNECT) |
597 | { |
598 | - client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
599 | + client->state= GEARMAN_CLIENT_STATE_IDLE; |
600 | return local_ret; |
601 | } |
602 | else if (gearman_failed(local_ret) and local_ret != GEARMAN_IO_WAIT) |
603 | { |
604 | - client->impl()->state= GEARMAN_CLIENT_STATE_SUBMIT; |
605 | + client->state= GEARMAN_CLIENT_STATE_SUBMIT; |
606 | return local_ret; |
607 | } |
608 | } |
609 | |
610 | /* Connection errors are fatal. */ |
611 | - if (client->impl()->con->revents & (POLLERR | POLLHUP | POLLNVAL)) |
612 | + if (client->con->revents & (POLLERR | POLLHUP | POLLNVAL)) |
613 | { |
614 | - gearman_error(client->impl()->universal, GEARMAN_LOST_CONNECTION, "detected lost connection in _client_run_tasks()"); |
615 | - client->impl()->con->close_socket(); |
616 | - client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
617 | + gearman_error(client->universal, GEARMAN_LOST_CONNECTION, "detected lost connection in _client_run_tasks()"); |
618 | + client->con->close_socket(); |
619 | + client->state= GEARMAN_CLIENT_STATE_IDLE; |
620 | return GEARMAN_LOST_CONNECTION; |
621 | } |
622 | } |
623 | |
624 | - if ((client->impl()->con->revents & POLLIN) == 0) |
625 | + if ((client->con->revents & POLLIN) == 0) |
626 | { |
627 | continue; |
628 | } |
629 | @@ -1495,17 +1504,17 @@ |
630 | while (1) |
631 | { |
632 | /* Read packet on connection and find which task it belongs to. */ |
633 | - if (client->impl()->options.unbuffered_result) |
634 | + if (client->options.unbuffered_result) |
635 | { |
636 | /* If client is handling the data read, make sure it's complete. */ |
637 | - if (client->impl()->con->recv_state == GEARMAN_CON_RECV_STATE_READ_DATA) |
638 | + if (client->con->recv_state == GEARMAN_CON_RECV_STATE_READ_DATA) |
639 | { |
640 | - for (client->impl()->task= client->impl()->task_list; client->impl()->task; |
641 | - client->impl()->task= client->impl()->task->impl()->next) |
642 | + for (client->task= client->task_list; client->task; |
643 | + client->task= client->task->impl()->next) |
644 | { |
645 | - if (client->impl()->task->impl()->con == client->impl()->con && |
646 | - (client->impl()->task->impl()->state == GEARMAN_TASK_STATE_DATA or |
647 | - client->impl()->task->impl()->state == GEARMAN_TASK_STATE_COMPLETE)) |
648 | + if (client->task->impl()->con == client->con && |
649 | + (client->task->impl()->state == GEARMAN_TASK_STATE_DATA or |
650 | + client->task->impl()->state == GEARMAN_TASK_STATE_COMPLETE)) |
651 | { |
652 | break; |
653 | } |
654 | @@ -1515,24 +1524,24 @@ |
655 | Someone has set GEARMAN_CLIENT_UNBUFFERED_RESULT but hasn't setup the client to fetch data correctly. |
656 | Fatal error :( |
657 | */ |
658 | - return gearman_universal_set_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, GEARMAN_AT, |
659 | + return gearman_universal_set_error(client->universal, GEARMAN_INVALID_ARGUMENT, GEARMAN_AT, |
660 | "client created with GEARMAN_CLIENT_UNBUFFERED_RESULT, but was not setup to use it. %s", __func__); |
661 | } |
662 | else |
663 | { |
664 | /* Read the next packet, without buffering the data part. */ |
665 | - client->impl()->task= NULL; |
666 | - (void)client->impl()->con->receiving(client->impl()->con->_packet, ret, false); |
667 | + client->task= NULL; |
668 | + (void)client->con->receiving(client->con->_packet, ret, false); |
669 | } |
670 | } |
671 | else |
672 | { |
673 | /* Read the next packet, buffering the data part. */ |
674 | - client->impl()->task= NULL; |
675 | - (void)client->impl()->con->receiving(client->impl()->con->_packet, ret, true); |
676 | + client->task= NULL; |
677 | + (void)client->con->receiving(client->con->_packet, ret, true); |
678 | } |
679 | |
680 | - if (client->impl()->task == NULL) |
681 | + if (client->task == NULL) |
682 | { |
683 | assert(ret != GEARMAN_MAX_RETURN); |
684 | |
685 | @@ -1544,71 +1553,71 @@ |
686 | break; |
687 | } |
688 | |
689 | - client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
690 | + client->state= GEARMAN_CLIENT_STATE_IDLE; |
691 | return ret; |
692 | } |
693 | |
694 | - client->impl()->con->options.packet_in_use= true; |
695 | + client->con->options.packet_in_use= true; |
696 | |
697 | /* We have a packet, see which task it belongs to. */ |
698 | - for (client->impl()->task= client->impl()->task_list; client->impl()->task; |
699 | - client->impl()->task= client->impl()->task->impl()->next) |
700 | + for (client->task= client->task_list; client->task; |
701 | + client->task= client->task->impl()->next) |
702 | { |
703 | - if (client->impl()->task->impl()->con != client->impl()->con) |
704 | + if (client->task->impl()->con != client->con) |
705 | { |
706 | continue; |
707 | } |
708 | |
709 | - if (client->impl()->con->_packet.command == GEARMAN_COMMAND_JOB_CREATED) |
710 | + if (client->con->_packet.command == GEARMAN_COMMAND_JOB_CREATED) |
711 | { |
712 | - if (client->impl()->task->impl()->created_id != client->impl()->con->created_id) |
713 | + if (client->task->impl()->created_id != client->con->created_id) |
714 | { |
715 | continue; |
716 | } |
717 | |
718 | /* New job created, drop through below and notify task. */ |
719 | - client->impl()->con->created_id++; |
720 | + client->con->created_id++; |
721 | } |
722 | - else if (client->impl()->con->_packet.command == GEARMAN_COMMAND_ERROR) |
723 | + else if (client->con->_packet.command == GEARMAN_COMMAND_ERROR) |
724 | { |
725 | - 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])); |
726 | + gearman_return_t maybe_server_error= string2return_code(static_cast<char *>(client->con->_packet.arg[0]), int(client->con->_packet.arg_size[0])); |
727 | |
728 | if (maybe_server_error == GEARMAN_MAX_RETURN) |
729 | { |
730 | maybe_server_error= GEARMAN_SERVER_ERROR; |
731 | } |
732 | |
733 | - gearman_universal_set_error(client->impl()->universal, maybe_server_error, GEARMAN_AT, |
734 | + gearman_universal_set_error(client->universal, maybe_server_error, GEARMAN_AT, |
735 | "%s:%.*s", |
736 | - static_cast<char *>(client->impl()->con->_packet.arg[0]), |
737 | - int(client->impl()->con->_packet.arg_size[1]), |
738 | - static_cast<char *>(client->impl()->con->_packet.arg[1])); |
739 | + static_cast<char *>(client->con->_packet.arg[0]), |
740 | + int(client->con->_packet.arg_size[1]), |
741 | + static_cast<char *>(client->con->_packet.arg[1])); |
742 | |
743 | /* |
744 | Packet cleanup copied from "Clean up the packet" below, and must |
745 | remain in sync with its reference. |
746 | */ |
747 | - gearman_packet_free(&(client->impl()->con->_packet)); |
748 | - client->impl()->con->options.packet_in_use= false; |
749 | + gearman_packet_free(&(client->con->_packet)); |
750 | + client->con->options.packet_in_use= false; |
751 | |
752 | /* This step copied from _client_run_tasks() above: */ |
753 | /* Increment this value because new job created then failed. */ |
754 | - client->impl()->con->created_id++; |
755 | + client->con->created_id++; |
756 | |
757 | return maybe_server_error; |
758 | } |
759 | - else if (client->impl()->con->_packet.command == GEARMAN_COMMAND_STATUS_RES_UNIQUE and |
760 | - (strncmp(gearman_task_unique(client->impl()->task), |
761 | - static_cast<char *>(client->impl()->con->_packet.arg[0]), |
762 | - client->impl()->con->_packet.arg_size[0]) == 0)) |
763 | + else if (client->con->_packet.command == GEARMAN_COMMAND_STATUS_RES_UNIQUE and |
764 | + (strncmp(gearman_task_unique(client->task), |
765 | + static_cast<char *>(client->con->_packet.arg[0]), |
766 | + client->con->_packet.arg_size[0]) == 0)) |
767 | { } |
768 | - else if (strncmp(client->impl()->task->impl()->job_handle, |
769 | - static_cast<char *>(client->impl()->con->_packet.arg[0]), |
770 | - client->impl()->con->_packet.arg_size[0]) || |
771 | - (client->impl()->con->_packet.failed() == false && |
772 | - strlen(client->impl()->task->impl()->job_handle) != client->impl()->con->_packet.arg_size[0] - 1) || |
773 | - (client->impl()->con->_packet.failed() && |
774 | - strlen(client->impl()->task->impl()->job_handle) != client->impl()->con->_packet.arg_size[0])) |
775 | + else if (strncmp(client->task->impl()->job_handle, |
776 | + static_cast<char *>(client->con->_packet.arg[0]), |
777 | + client->con->_packet.arg_size[0]) || |
778 | + (client->con->_packet.failed() == false && |
779 | + strlen(client->task->impl()->job_handle) != client->con->_packet.arg_size[0] - 1) || |
780 | + (client->con->_packet.failed() && |
781 | + strlen(client->task->impl()->job_handle) != client->con->_packet.arg_size[0])) |
782 | { |
783 | continue; |
784 | } |
785 | @@ -1618,20 +1627,19 @@ |
786 | break; |
787 | } |
788 | |
789 | - if (client->impl()->task == NULL) |
790 | + if (client->task == NULL) |
791 | { |
792 | /* The client has stopped waiting for the response, ignore it. */ |
793 | - client->impl()->con->free_private_packet(); |
794 | + client->con->free_private_packet(); |
795 | continue; |
796 | } |
797 | |
798 | - client->impl()->task->impl()->recv= &(client->impl()->con->_packet); |
799 | + client->task->impl()->recv= &(client->con->_packet); |
800 | } |
801 | |
802 | case GEARMAN_CLIENT_STATE_PACKET: |
803 | /* Let task process job created or result packet. */ |
804 | - assert_msg(client == client->impl()->task->impl()->client, "Programmer error, client and task member client are not the same"); |
805 | - gearman_return_t local_ret= _client_run_task(client->impl()->task->impl()); |
806 | + gearman_return_t local_ret= _client_run_task(client->task->impl()); |
807 | if (local_ret == GEARMAN_IO_WAIT) |
808 | { |
809 | break; |
810 | @@ -1639,56 +1647,56 @@ |
811 | |
812 | if (gearman_failed(local_ret)) |
813 | { |
814 | - client->impl()->state= GEARMAN_CLIENT_STATE_PACKET; |
815 | + client->state= GEARMAN_CLIENT_STATE_PACKET; |
816 | return local_ret; |
817 | } |
818 | |
819 | /* Clean up the packet. */ |
820 | - client->impl()->con->free_private_packet(); |
821 | + client->con->free_private_packet(); |
822 | |
823 | /* If exit task is set and matched, exit */ |
824 | if (exit_task) |
825 | { |
826 | if (exit_task->impl()->result_rc != GEARMAN_UNKNOWN_STATE) |
827 | { |
828 | - client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
829 | + client->state= GEARMAN_CLIENT_STATE_IDLE; |
830 | return GEARMAN_SUCCESS; |
831 | } |
832 | } |
833 | |
834 | /* If all tasks are done, return. */ |
835 | - if (client->impl()->running_tasks == 0) |
836 | + if (client->running_tasks == 0) |
837 | { |
838 | - client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
839 | + client->state= GEARMAN_CLIENT_STATE_IDLE; |
840 | return GEARMAN_SUCCESS; |
841 | } |
842 | } |
843 | } |
844 | |
845 | /* If all tasks are done, return. */ |
846 | - if (client->impl()->running_tasks == 0) |
847 | + if (client->running_tasks == 0) |
848 | { |
849 | break; |
850 | } |
851 | |
852 | - if (client->impl()->new_tasks > 0 and ! (client->impl()->options.no_new)) |
853 | + if (client->new_tasks > 0 and ! (client->options.no_new)) |
854 | { |
855 | continue; |
856 | } |
857 | |
858 | - if (client->impl()->options.non_blocking) |
859 | + if (client->options.non_blocking) |
860 | { |
861 | /* Let the caller wait for activity. */ |
862 | - client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
863 | + client->state= GEARMAN_CLIENT_STATE_IDLE; |
864 | |
865 | - return gearman_gerror(client->impl()->universal, GEARMAN_IO_WAIT); |
866 | + return gearman_gerror(client->universal, GEARMAN_IO_WAIT); |
867 | } |
868 | |
869 | /* Wait for activity on one of the connections. */ |
870 | - gearman_return_t local_ret= gearman_wait(client->impl()->universal); |
871 | + gearman_return_t local_ret= gearman_wait(client->universal); |
872 | if (gearman_failed(local_ret) and local_ret != GEARMAN_IO_WAIT) |
873 | { |
874 | - client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
875 | + client->state= GEARMAN_CLIENT_STATE_IDLE; |
876 | |
877 | return local_ret; |
878 | } |
879 | @@ -1697,73 +1705,76 @@ |
880 | break; |
881 | } |
882 | |
883 | - client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
884 | + client->state= GEARMAN_CLIENT_STATE_IDLE; |
885 | |
886 | return GEARMAN_SUCCESS; |
887 | } |
888 | |
889 | -gearman_return_t gearman_client_run_tasks(gearman_client_st *client) |
890 | -{ |
891 | - if (client == NULL or client->impl() == NULL) |
892 | - { |
893 | - return GEARMAN_INVALID_ARGUMENT; |
894 | - } |
895 | - |
896 | - if (client->impl()->task_list == NULL) // We are immediatly successful if all tasks are completed |
897 | - { |
898 | - return GEARMAN_SUCCESS; |
899 | - } |
900 | - |
901 | - gearman_return_t rc; |
902 | - { |
903 | - PUSH_NON_BLOCKING(client->impl()->universal); |
904 | - |
905 | - rc= _client_run_tasks(client, NULL); |
906 | - } |
907 | - |
908 | - if (rc == GEARMAN_COULD_NOT_CONNECT) |
909 | - { |
910 | - gearman_reset(client->impl()->universal); |
911 | - } |
912 | - |
913 | - return rc; |
914 | -} |
915 | - |
916 | -gearman_return_t gearman_client_run_block_tasks(gearman_client_st *shell, gearman_task_st* exit_task) |
917 | -{ |
918 | - if (shell == NULL) |
919 | - { |
920 | - return GEARMAN_INVALID_ARGUMENT; |
921 | - } |
922 | - Client *client= shell->impl(); |
923 | - |
924 | - if (client->task_list == NULL) // We are immediatly successful if all tasks are completed |
925 | - { |
926 | - return GEARMAN_SUCCESS; |
927 | - } |
928 | - |
929 | - |
930 | - gearman_return_t rc; |
931 | - { |
932 | - PUSH_BLOCKING(client->universal); |
933 | - |
934 | - rc= _client_run_tasks(shell, exit_task); |
935 | - } |
936 | - |
937 | - if (gearman_failed(rc)) |
938 | - { |
939 | +gearman_return_t gearman_client_run_tasks(gearman_client_st *client_shell) |
940 | +{ |
941 | + if (client_shell and client_shell->impl()) |
942 | + { |
943 | + Client* client= client_shell->impl(); |
944 | + |
945 | + if (client->task_list == NULL) // We are immediatly successful if all tasks are completed |
946 | + { |
947 | + return GEARMAN_SUCCESS; |
948 | + } |
949 | + |
950 | + gearman_return_t rc; |
951 | + { |
952 | + PUSH_NON_BLOCKING(client->universal); |
953 | + |
954 | + rc= _client_run_tasks(client_shell, NULL); |
955 | + } |
956 | + |
957 | if (rc == GEARMAN_COULD_NOT_CONNECT) |
958 | { |
959 | gearman_reset(client->universal); |
960 | } |
961 | |
962 | - if (client->universal.error_code() != rc and rc != GEARMAN_COULD_NOT_CONNECT) |
963 | - { |
964 | - assert(client->universal.error_code() == rc); |
965 | - } |
966 | - } |
967 | - |
968 | - return rc; |
969 | + return rc; |
970 | + } |
971 | + |
972 | + return GEARMAN_INVALID_ARGUMENT; |
973 | +} |
974 | + |
975 | +gearman_return_t gearman_client_run_block_tasks(gearman_client_st *client_shell, gearman_task_st* exit_task) |
976 | +{ |
977 | + if (client_shell and client_shell->impl()) |
978 | + { |
979 | + Client *client= client_shell->impl(); |
980 | + |
981 | + if (client->task_list == NULL) // We are immediatly successful if all tasks are completed |
982 | + { |
983 | + return GEARMAN_SUCCESS; |
984 | + } |
985 | + |
986 | + |
987 | + gearman_return_t rc; |
988 | + { |
989 | + PUSH_BLOCKING(client->universal); |
990 | + |
991 | + rc= _client_run_tasks(client_shell, exit_task); |
992 | + } |
993 | + |
994 | + if (gearman_failed(rc)) |
995 | + { |
996 | + if (rc == GEARMAN_COULD_NOT_CONNECT) |
997 | + { |
998 | + gearman_reset(client->universal); |
999 | + } |
1000 | + |
1001 | + if (client->universal.error_code() != rc and rc != GEARMAN_COULD_NOT_CONNECT) |
1002 | + { |
1003 | + assert(client->universal.error_code() == rc); |
1004 | + } |
1005 | + } |
1006 | + |
1007 | + return rc; |
1008 | + } |
1009 | + |
1010 | + return GEARMAN_INVALID_ARGUMENT; |
1011 | } |
1012 | |
1013 | /* |
1014 | |
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 20:13:28 +0000 |
1018 | @@ -2,7 +2,7 @@ |
1019 | * |
1020 | * Gearmand client and server library. |
1021 | * |
1022 | - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ |
1023 | + * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ |
1024 | * All rights reserved. |
1025 | * |
1026 | * Redistribution and use in source and binary forms, with or without |
1027 | @@ -69,7 +69,7 @@ |
1028 | uint32_t numerator; |
1029 | uint32_t denominator; |
1030 | uint32_t client_count; |
1031 | - gearman_client_st *client; |
1032 | + Client *client; |
1033 | gearman_task_st *next; |
1034 | gearman_task_st *prev; |
1035 | void *context; |
1036 | @@ -97,7 +97,7 @@ |
1037 | numerator(0), |
1038 | denominator(0), |
1039 | client_count(0), |
1040 | - client(&client_), |
1041 | + client(client_.impl()), |
1042 | next(NULL), |
1043 | prev(NULL), |
1044 | context(NULL), |
1045 | |
1046 | === modified file 'libgearman/run.cc' |
1047 | --- libgearman/run.cc 2013-07-06 17:00:51 +0000 |
1048 | +++ libgearman/run.cc 2013-07-06 20:13:28 +0000 |
1049 | @@ -51,7 +51,7 @@ |
1050 | assert_msg(task->client, "Programmer error, somehow an invalid task was specified"); |
1051 | if (task->client == NULL) |
1052 | { |
1053 | - return gearman_universal_set_error(task->client->impl()->universal, GEARMAN_INVALID_ARGUMENT, GEARMAN_AT, |
1054 | + return gearman_universal_set_error(task->client->universal, GEARMAN_INVALID_ARGUMENT, GEARMAN_AT, |
1055 | "Programmer error, somehow an invalid task was specified"); |
1056 | } |
1057 | |
1058 | @@ -59,16 +59,16 @@ |
1059 | { |
1060 | case GEARMAN_TASK_STATE_NEW: |
1061 | |
1062 | - if (task->client->impl()->universal.has_connections() == false) |
1063 | + if (task->client->universal.has_connections() == false) |
1064 | { |
1065 | - assert(task->client->impl()->universal.con_count == 0); |
1066 | - assert(task->client->impl()->universal.con_list == NULL); |
1067 | - task->client->impl()->new_tasks--; |
1068 | - task->client->impl()->running_tasks--; |
1069 | - return gearman_universal_set_error(task->client->impl()->universal, GEARMAN_NO_SERVERS, GEARMAN_AT, "no servers provided"); |
1070 | + assert(task->client->universal.con_count == 0); |
1071 | + assert(task->client->universal.con_list == NULL); |
1072 | + task->client->new_tasks--; |
1073 | + task->client->running_tasks--; |
1074 | + return gearman_universal_set_error(task->client->universal, GEARMAN_NO_SERVERS, GEARMAN_AT, "no servers provided"); |
1075 | } |
1076 | |
1077 | - for (task->con= task->client->impl()->universal.con_list; task->con; |
1078 | + for (task->con= task->client->universal.con_list; task->con; |
1079 | task->con= task->con->next_connection()) |
1080 | { |
1081 | if (task->con->send_state == GEARMAN_CON_SEND_STATE_NONE) |
1082 | @@ -79,11 +79,11 @@ |
1083 | |
1084 | if (task->con == NULL) |
1085 | { |
1086 | - task->client->impl()->options.no_new= true; |
1087 | - return gearman_gerror(task->client->impl()->universal, GEARMAN_IO_WAIT); |
1088 | + task->client->options.no_new= true; |
1089 | + return gearman_gerror(task->client->universal, GEARMAN_IO_WAIT); |
1090 | } |
1091 | |
1092 | - task->client->impl()->new_tasks--; |
1093 | + task->client->new_tasks--; |
1094 | |
1095 | if (task->send.command != GEARMAN_COMMAND_GET_STATUS) |
1096 | { |
1097 | @@ -95,7 +95,7 @@ |
1098 | while (1) |
1099 | { |
1100 | assert(task->con); |
1101 | - gearman_return_t ret= task->con->send_packet(task->send, task->client->impl()->new_tasks == 0 ? true : false); |
1102 | + gearman_return_t ret= task->con->send_packet(task->send, task->client->new_tasks == 0 ? true : false); |
1103 | |
1104 | if (gearman_success(ret)) |
1105 | { |
1106 | @@ -135,12 +135,12 @@ |
1107 | if (ret == GEARMAN_COULD_NOT_CONNECT) // If no connection is found, we will let the user try again |
1108 | { |
1109 | task->set_state(GEARMAN_TASK_STATE_NEW); |
1110 | - task->client->impl()->new_tasks++; |
1111 | + task->client->new_tasks++; |
1112 | } |
1113 | else |
1114 | { |
1115 | task->set_state(GEARMAN_TASK_STATE_FAIL); |
1116 | - task->client->impl()->running_tasks--; |
1117 | + task->client->running_tasks--; |
1118 | } |
1119 | return ret; |
1120 | } |
1121 | @@ -157,7 +157,7 @@ |
1122 | { |
1123 | if (not task->func.workload_fn) |
1124 | { |
1125 | - gearman_error(task->client->impl()->universal, GEARMAN_NEED_WORKLOAD_FN, |
1126 | + gearman_error(task->client->universal, GEARMAN_NEED_WORKLOAD_FN, |
1127 | "workload size > 0, but no data pointer or workload_fn was given"); |
1128 | return GEARMAN_NEED_WORKLOAD_FN; |
1129 | } |
1130 | @@ -171,7 +171,7 @@ |
1131 | } |
1132 | } |
1133 | |
1134 | - task->client->impl()->options.no_new= false; |
1135 | + task->client->options.no_new= false; |
1136 | task->set_state(GEARMAN_TASK_STATE_WORK); |
1137 | task->con->set_events(POLLIN); |
1138 | return GEARMAN_SUCCESS; |
1139 | @@ -407,13 +407,13 @@ |
1140 | break; |
1141 | } |
1142 | |
1143 | - task->client->impl()->running_tasks--; |
1144 | + task->client->running_tasks--; |
1145 | task->set_state(GEARMAN_TASK_STATE_FINISHED); |
1146 | |
1147 | // @todo this should never happen... but background tasks can signal it. |
1148 | assert(task->result_rc != GEARMAN_UNKNOWN_STATE); |
1149 | |
1150 | - if (task->client->impl()->options.free_tasks and task->type == GEARMAN_TASK_KIND_ADD_TASK) |
1151 | + if (task->client->options.free_tasks and task->type == GEARMAN_TASK_KIND_ADD_TASK) |
1152 | { |
1153 | gearman_task_free(task->shell()); |
1154 | } |
1155 | |
1156 | === modified file 'libgearman/task.cc' |
1157 | --- libgearman/task.cc 2013-05-11 11:15:03 +0000 |
1158 | +++ libgearman/task.cc 2013-07-06 20:13:28 +0000 |
1159 | @@ -59,7 +59,6 @@ |
1160 | Task* task= new (std::nothrow) Task(client, task_shell); |
1161 | if (task) |
1162 | { |
1163 | - assert(task->client == &client); |
1164 | return task->shell(); |
1165 | } |
1166 | |
1167 | @@ -69,6 +68,10 @@ |
1168 | return NULL; |
1169 | } |
1170 | |
1171 | +void gearman_task_free(Task* task) |
1172 | +{ |
1173 | + gearman_task_free(task->shell()); |
1174 | +} |
1175 | |
1176 | void gearman_task_free(gearman_task_st *task_shell) |
1177 | { |
1178 | @@ -91,14 +94,14 @@ |
1179 | gearman_packet_free(&(task->send)); |
1180 | } |
1181 | |
1182 | - if (task->type != GEARMAN_TASK_KIND_DO and task->context and task->client->impl()->task_context_free_fn) |
1183 | + if (task->type != GEARMAN_TASK_KIND_DO and task->context and task->client->task_context_free_fn) |
1184 | { |
1185 | - task->client->impl()->task_context_free_fn(task_shell, static_cast<void *>(task->context)); |
1186 | + task->client->task_context_free_fn(task_shell, static_cast<void *>(task->context)); |
1187 | } |
1188 | |
1189 | - if (task->client->impl()->task_list == task_shell) |
1190 | + if (task->client->task_list == task_shell) |
1191 | { |
1192 | - task->client->impl()->task_list= task->next; |
1193 | + task->client->task_list= task->next; |
1194 | } |
1195 | |
1196 | if (task->prev) |
1197 | @@ -111,13 +114,13 @@ |
1198 | task->next->impl()->prev= task->prev; |
1199 | } |
1200 | |
1201 | - task->client->impl()->task_count--; |
1202 | + task->client->task_count--; |
1203 | |
1204 | // If the task we are removing is a current task, remove it from the client |
1205 | // structures. |
1206 | - if (task->client->impl()->task == task_shell) |
1207 | + if (task->client->task == task_shell) |
1208 | { |
1209 | - task->client->impl()->task= NULL; |
1210 | + task->client->task= NULL; |
1211 | } |
1212 | task->client= NULL; |
1213 | } |
1214 | |
1215 | === modified file 'libgearman/task.hpp' |
1216 | --- libgearman/task.hpp 2013-01-31 05:27:46 +0000 |
1217 | +++ libgearman/task.hpp 2013-07-06 20:13:28 +0000 |
1218 | @@ -49,6 +49,8 @@ |
1219 | gearman_task_st *gearman_task_internal_create(gearman_client_st& client, |
1220 | gearman_task_st *task); |
1221 | |
1222 | +void gearman_task_free(Task* task); |
1223 | + |
1224 | void gearman_task_clear_fn(gearman_task_st *task); |
1225 | |
1226 | bool gearman_task_is_active(const gearman_task_st *self); |