Merge lp:~tangent-org/gearmand/build into lp:gearmand/1.0
- build
- Merge into 1.0
Proposed by
Brian Aker
Status: | Merged |
---|---|
Merge reported by: | Brian Aker |
Merged at revision: | not available |
Proposed branch: | lp:~tangent-org/gearmand/build |
Merge into: | lp:gearmand/1.0 |
Diff against target: |
8550 lines (+2639/-1811) (has conflicts) 72 files modified
ChangeLog (+6/-0) bin/client.h (+4/-0) bin/gearman.cc (+2/-2) bin/worker.h (+3/-0) configure.ac (+5/-1) libgearman-1.0/client.h (+5/-26) libgearman-1.0/constants.h (+0/-1) libgearman-1.0/core.h (+0/-2) libgearman-1.0/include.am (+2/-2) libgearman-1.0/interface/client.h (+62/-0) libgearman-1.0/interface/task.h (+17/-26) libgearman-1.0/interface/worker.h (+63/-0) libgearman-1.0/job.h (+0/-18) libgearman-1.0/task_attr.h (+2/-1) libgearman-1.0/util.h (+1/-1) libgearman-1.0/worker.h (+2/-33) libgearman/actions.cc (+25/-18) libgearman/actions.hpp (+0/-4) libgearman/add.cc (+51/-33) libgearman/allocator.hpp (+2/-6) libgearman/client.cc (+428/-390) libgearman/common.h (+10/-0) libgearman/connection.cc (+59/-24) libgearman/connection.hpp (+9/-6) libgearman/do.cc (+40/-33) libgearman/error.cc (+27/-34) libgearman/error.hpp (+3/-0) libgearman/execute.cc (+8/-8) libgearman/function/function_v1.hpp (+1/-1) libgearman/include.am (+7/-0) libgearman/interface/client.hpp (+118/-0) libgearman/interface/packet.hpp (+26/-4) libgearman/interface/push.hpp (+102/-0) libgearman/interface/task.hpp (+143/-0) libgearman/interface/universal.hpp (+140/-8) libgearman/interface/worker.hpp (+124/-0) libgearman/is.hpp (+1/-0) libgearman/job.cc (+31/-25) libgearman/job.hpp (+56/-0) libgearman/packet.cc (+3/-3) libgearman/protocol/submit.cc (+13/-12) libgearman/protocol/submit.h (+3/-3) libgearman/run.cc (+26/-26) libgearman/run.hpp (+1/-1) libgearman/task.cc (+320/-371) libgearman/task.hpp (+1/-1) libgearman/task_attr.cc (+10/-0) libgearman/universal.cc (+1/-40) libgearman/universal.hpp (+2/-97) libgearman/worker.cc (+299/-266) libtest/collection.cc (+11/-0) libtest/signal.cc (+9/-0) support/gearmand.spec.in (+4/-4) tests/basic.cc (+1/-0) tests/burnin.cc (+6/-4) tests/client.h (+4/-0) tests/gearmand.cc (+1/-1) tests/httpd_test.cc (+3/-0) tests/libgearman-1.0/client_test.cc (+117/-110) tests/libgearman-1.0/internals.cc (+9/-33) tests/libgearman-1.0/regression.cc (+1/-2) tests/libgearman-1.0/task.cc (+11/-9) tests/libgearman-1.0/unique.cc (+9/-9) tests/libgearman-1.0/worker_test.cc (+171/-106) tests/round_robin.cc (+3/-3) tests/runner.h (+1/-1) tests/start_worker.cc (+2/-2) tests/stress_worker.cc (+2/-0) tests/worker.h (+4/-0) tests/workers/v1/unique.cc (+2/-0) tests/workers/v2/split.cc (+2/-0) tests/workers/v2/unique.cc (+2/-0) Text conflict in ChangeLog Text conflict in configure.ac Text conflict in libgearman/add.cc Text conflict in libgearman/client.cc Text conflict in libgearman/error.hpp Text conflict in libgearman/job.cc Text conflict in libgearman/worker.cc Text conflict in libtest/collection.cc Text conflict in libtest/signal.cc Text conflict in tests/libgearman-1.0/worker_test.cc |
To merge this branch: | bzr merge lp:~tangent-org/gearmand/build |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tangent Trunk | Pending | ||
Review via email: mp+125390@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 'ChangeLog' |
2 | --- ChangeLog 2012-09-19 07:36:20 +0000 |
3 | +++ ChangeLog 2012-09-20 02:21:22 +0000 |
4 | @@ -1,3 +1,4 @@ |
5 | +<<<<<<< TREE |
6 | 0.39 Wed Sep 19 03:36:06 EDT 2012 |
7 | * Added gearman_job_error() interface. |
8 | * gearman_client_errno() and gearman_worker_errno() now return EINVAL if client or worker is invalid. |
9 | @@ -6,6 +7,11 @@ |
10 | * Updates for compiling on different platforms. |
11 | * UUID portability fixes. |
12 | |
13 | +======= |
14 | +1.0 |
15 | +* Fix for ABI compatibility issues. |
16 | + |
17 | +>>>>>>> MERGE-SOURCE |
18 | 0.37 Sun Sep 2 22:51:08 EDT 2012 |
19 | * Fix compiler issues around older compilers. Bug 1039629. |
20 | |
21 | |
22 | === modified file 'bin/client.h' |
23 | --- bin/client.h 2011-04-28 17:46:16 +0000 |
24 | +++ bin/client.h 2012-09-20 02:21:22 +0000 |
25 | @@ -37,6 +37,8 @@ |
26 | |
27 | #pragma once |
28 | |
29 | +namespace bin { |
30 | + |
31 | class Client |
32 | { |
33 | public: |
34 | @@ -63,3 +65,5 @@ |
35 | private: |
36 | gearman_client_st _client; |
37 | }; |
38 | + |
39 | +} // namespace bin |
40 | |
41 | === modified file 'bin/gearman.cc' |
42 | --- bin/gearman.cc 2012-07-12 00:08:17 +0000 |
43 | +++ bin/gearman.cc 2012-09-20 02:21:22 +0000 |
44 | @@ -237,7 +237,7 @@ |
45 | |
46 | void _client(Args &args) |
47 | { |
48 | - Client local_client; |
49 | + bin::Client local_client; |
50 | gearman_client_st &client= local_client.client(); |
51 | Bytes workload; |
52 | if (args.timeout() >= 0) |
53 | @@ -482,7 +482,7 @@ |
54 | |
55 | void _worker(Args &args) |
56 | { |
57 | - Worker local_worker; |
58 | + bin::Worker local_worker; |
59 | gearman_worker_st &worker= local_worker.worker(); |
60 | |
61 | if (args.timeout() >= 0) |
62 | |
63 | === modified file 'bin/worker.h' |
64 | --- bin/worker.h 2011-04-28 17:46:16 +0000 |
65 | +++ bin/worker.h 2012-09-20 02:21:22 +0000 |
66 | @@ -37,6 +37,8 @@ |
67 | |
68 | #pragma once |
69 | |
70 | +namespace bin { |
71 | + |
72 | class Worker |
73 | { |
74 | public: |
75 | @@ -63,3 +65,4 @@ |
76 | private: |
77 | gearman_worker_st _worker; |
78 | }; |
79 | +} //namespace bin |
80 | |
81 | === modified file 'configure.ac' |
82 | --- configure.ac 2012-09-19 21:51:59 +0000 |
83 | +++ configure.ac 2012-09-20 02:21:22 +0000 |
84 | @@ -6,7 +6,11 @@ |
85 | # Use and distribution licensed under the BSD license. See |
86 | # the COPYING file in this directory for full text. |
87 | |
88 | +<<<<<<< TREE |
89 | AC_INIT([gearmand],[0.39],[https://bugs.launchpad.net/gearmand],[gearmand],[http://gearman.info/]) |
90 | +======= |
91 | +AC_INIT([gearmand],[1.0],[https://bugs.launchpad.net/gearmand],[gearmand],[http://gearman.info/]) |
92 | +>>>>>>> MERGE-SOURCE |
93 | AC_CONFIG_AUX_DIR([config]) |
94 | AC_CONFIG_MACRO_DIR([m4]) |
95 | |
96 | @@ -21,7 +25,7 @@ |
97 | AC_CONFIG_HEADERS([config.h:config.in])dnl Keep filename to 8.3 for MS-DOS. |
98 | AC_CONFIG_SRCDIR(libgearman/gearman.cc) |
99 | |
100 | -GEARMAN_LIBRARY_VERSION=7:0:0 |
101 | +GEARMAN_LIBRARY_VERSION=8:0:0 |
102 | # | | | |
103 | # +------+ | +---+ |
104 | # | | | |
105 | |
106 | === modified file 'libgearman-1.0/client.h' |
107 | --- libgearman-1.0/client.h 2012-06-28 01:28:50 +0000 |
108 | +++ libgearman-1.0/client.h 2012-09-20 02:21:22 +0000 |
109 | @@ -43,6 +43,8 @@ |
110 | |
111 | #pragma once |
112 | |
113 | +#include <libgearman-1.0/interface/client.h> |
114 | + |
115 | /** @addtogroup gearman_client Client Declarations |
116 | * |
117 | * This is the interface gearman clients should use. You can run tasks one at a |
118 | @@ -59,32 +61,6 @@ |
119 | GEARMAN_CLIENT_STATE_PACKET |
120 | }; |
121 | |
122 | -/** |
123 | - * @ingroup gearman_client |
124 | - */ |
125 | -struct gearman_client_st |
126 | -{ |
127 | - struct { |
128 | - bool allocated; |
129 | - bool non_blocking; |
130 | - bool unbuffered_result; |
131 | - bool no_new; |
132 | - bool free_tasks; |
133 | - } options; |
134 | - enum gearman_client_t state; |
135 | - uint32_t new_tasks; |
136 | - uint32_t running_tasks; |
137 | - uint32_t task_count; |
138 | - void *context; |
139 | - gearman_connection_st *con; |
140 | - gearman_task_st *task; |
141 | - gearman_task_st *task_list; |
142 | - gearman_task_context_free_fn *task_context_free_fn; |
143 | - struct gearman_universal_st universal; |
144 | - struct gearman_actions_t actions; |
145 | - gearman_job_handle_t _do_handle; // Backwards compatible |
146 | -}; |
147 | - |
148 | #ifdef __cplusplus |
149 | extern "C" { |
150 | #endif |
151 | @@ -740,6 +716,9 @@ |
152 | |
153 | const char *gearman_client_namespace(gearman_client_st *self); |
154 | |
155 | +GEARMAN_API |
156 | +bool gearman_client_has_tasks(const gearman_client_st *client); |
157 | + |
158 | /** @} */ |
159 | |
160 | #ifdef __cplusplus |
161 | |
162 | === modified file 'libgearman-1.0/constants.h' |
163 | --- libgearman-1.0/constants.h 2012-05-27 00:47:14 +0000 |
164 | +++ libgearman-1.0/constants.h 2012-09-20 02:21:22 +0000 |
165 | @@ -133,7 +133,6 @@ |
166 | } gearman_worker_options_t; |
167 | |
168 | /* Types. */ |
169 | -typedef struct gearman_packet_st gearman_packet_st; |
170 | typedef struct gearman_task_st gearman_task_st; |
171 | typedef struct gearman_client_st gearman_client_st; |
172 | typedef struct gearman_job_st gearman_job_st; |
173 | |
174 | === modified file 'libgearman-1.0/core.h' |
175 | --- libgearman-1.0/core.h 2012-08-13 08:16:56 +0000 |
176 | +++ libgearman-1.0/core.h 2012-09-20 02:21:22 +0000 |
177 | @@ -39,5 +39,3 @@ |
178 | #pragma once |
179 | |
180 | #include <libgearman-1.0/allocator.h> |
181 | -#include <libgearman-1.0/universal.h> |
182 | -#include <libgearman-1.0/packet.h> |
183 | |
184 | === modified file 'libgearman-1.0/include.am' |
185 | --- libgearman-1.0/include.am 2012-07-05 18:59:46 +0000 |
186 | +++ libgearman-1.0/include.am 2012-09-20 02:21:22 +0000 |
187 | @@ -4,8 +4,10 @@ |
188 | |
189 | include libgearman-1.0/t/include.am |
190 | |
191 | +nobase_include_HEADERS+= libgearman-1.0/interface/client.h |
192 | nobase_include_HEADERS+= libgearman-1.0/interface/status.h |
193 | nobase_include_HEADERS+= libgearman-1.0/interface/task.h |
194 | +nobase_include_HEADERS+= libgearman-1.0/interface/worker.h |
195 | nobase_include_HEADERS+= libgearman-1.0/status.h |
196 | nobase_include_HEADERS+= \ |
197 | libgearman-1.0/actions.h \ |
198 | @@ -26,7 +28,6 @@ |
199 | libgearman-1.0/kill.h \ |
200 | libgearman-1.0/limits.h \ |
201 | libgearman-1.0/ostream.hpp \ |
202 | - libgearman-1.0/packet.h \ |
203 | libgearman-1.0/parse.h \ |
204 | libgearman-1.0/priority.h \ |
205 | libgearman-1.0/protocol.h \ |
206 | @@ -37,7 +38,6 @@ |
207 | libgearman-1.0/string.h \ |
208 | libgearman-1.0/task.h \ |
209 | libgearman-1.0/task_attr.h \ |
210 | - libgearman-1.0/universal.h \ |
211 | libgearman-1.0/util.h \ |
212 | libgearman-1.0/version.h \ |
213 | libgearman-1.0/visibility.h \ |
214 | |
215 | === added file 'libgearman-1.0/interface/client.h' |
216 | --- libgearman-1.0/interface/client.h 1970-01-01 00:00:00 +0000 |
217 | +++ libgearman-1.0/interface/client.h 2012-09-20 02:21:22 +0000 |
218 | @@ -0,0 +1,62 @@ |
219 | +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
220 | + * |
221 | + * Gearmand client and server library. |
222 | + * |
223 | + * Copyright (C) 2012 Data Differential, http://datadifferential.com/ |
224 | + * All rights reserved. |
225 | + * |
226 | + * Redistribution and use in source and binary forms, with or without |
227 | + * modification, are permitted provided that the following conditions are |
228 | + * met: |
229 | + * |
230 | + * * Redistributions of source code must retain the above copyright |
231 | + * notice, this list of conditions and the following disclaimer. |
232 | + * |
233 | + * * Redistributions in binary form must reproduce the above |
234 | + * copyright notice, this list of conditions and the following disclaimer |
235 | + * in the documentation and/or other materials provided with the |
236 | + * distribution. |
237 | + * |
238 | + * * The names of its contributors may not be used to endorse or |
239 | + * promote products derived from this software without specific prior |
240 | + * written permission. |
241 | + * |
242 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
243 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
244 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
245 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
246 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
247 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
248 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
249 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
250 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
251 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
252 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
253 | + * |
254 | + */ |
255 | + |
256 | +#pragma once |
257 | + |
258 | +#ifdef __cplusplus |
259 | +struct Client; |
260 | +#endif |
261 | + |
262 | +struct gearman_client_st |
263 | +{ |
264 | + struct { |
265 | + bool is_allocated; |
266 | + bool is_initialized; |
267 | + } options; |
268 | + void *_impl; |
269 | +#ifdef __cplusplus |
270 | + struct Client* impl() const |
271 | + { |
272 | + return (Client*)(_impl); |
273 | + } |
274 | + |
275 | + void impl(Client* impl_) |
276 | + { |
277 | + _impl= impl_; |
278 | + } |
279 | +#endif |
280 | +}; |
281 | |
282 | === modified file 'libgearman-1.0/interface/task.h' |
283 | --- libgearman-1.0/interface/task.h 2012-07-09 09:07:43 +0000 |
284 | +++ libgearman-1.0/interface/task.h 2012-09-20 02:21:22 +0000 |
285 | @@ -58,35 +58,26 @@ |
286 | GEARMAN_TASK_KIND_DO |
287 | }; |
288 | |
289 | +#ifdef __cplusplus |
290 | +struct Task; |
291 | +#endif |
292 | + |
293 | struct gearman_task_st |
294 | { |
295 | struct { |
296 | - bool allocated; |
297 | - bool send_in_use; |
298 | - bool is_known; |
299 | - bool is_running; |
300 | - bool was_reduced; |
301 | - bool is_paused; |
302 | + bool is_allocated; |
303 | bool is_initialized; |
304 | } options; |
305 | - enum gearman_task_kind_t type; |
306 | - enum gearman_task_state_t state; |
307 | - uint32_t magic_; |
308 | - uint32_t created_id; |
309 | - uint32_t numerator; |
310 | - uint32_t denominator; |
311 | - uint32_t client_count; |
312 | - gearman_client_st *client; |
313 | - gearman_task_st *next; |
314 | - gearman_task_st *prev; |
315 | - void *context; |
316 | - gearman_connection_st *con; |
317 | - gearman_packet_st *recv; |
318 | - gearman_packet_st send; |
319 | - struct gearman_actions_t func; |
320 | - gearman_return_t result_rc; |
321 | - struct gearman_result_st *result_ptr; |
322 | - char job_handle[GEARMAN_JOB_HANDLE_SIZE]; |
323 | - size_t unique_length; |
324 | - char unique[GEARMAN_MAX_UNIQUE_SIZE]; |
325 | + void *_impl; |
326 | +#ifdef __cplusplus |
327 | + struct Task* impl() const |
328 | + { |
329 | + return (Task*)(_impl); |
330 | + } |
331 | + |
332 | + void impl(Task* impl_) |
333 | + { |
334 | + _impl= impl_; |
335 | + } |
336 | +#endif |
337 | }; |
338 | |
339 | === added file 'libgearman-1.0/interface/worker.h' |
340 | --- libgearman-1.0/interface/worker.h 1970-01-01 00:00:00 +0000 |
341 | +++ libgearman-1.0/interface/worker.h 2012-09-20 02:21:22 +0000 |
342 | @@ -0,0 +1,63 @@ |
343 | +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
344 | + * |
345 | + * Gearmand client and server library. |
346 | + * |
347 | + * Copyright (C) 2012 Data Differential, http://datadifferential.com/ |
348 | + * All rights reserved. |
349 | + * |
350 | + * Redistribution and use in source and binary forms, with or without |
351 | + * modification, are permitted provided that the following conditions are |
352 | + * met: |
353 | + * |
354 | + * * Redistributions of source code must retain the above copyright |
355 | + * notice, this list of conditions and the following disclaimer. |
356 | + * |
357 | + * * Redistributions in binary form must reproduce the above |
358 | + * copyright notice, this list of conditions and the following disclaimer |
359 | + * in the documentation and/or other materials provided with the |
360 | + * distribution. |
361 | + * |
362 | + * * The names of its contributors may not be used to endorse or |
363 | + * promote products derived from this software without specific prior |
364 | + * written permission. |
365 | + * |
366 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
367 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
368 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
369 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
370 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
371 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
372 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
373 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
374 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
375 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
376 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
377 | + * |
378 | + */ |
379 | + |
380 | +#pragma once |
381 | + |
382 | +#ifdef __cplusplus |
383 | +struct Worker; |
384 | +#endif |
385 | + |
386 | +struct gearman_worker_st |
387 | +{ |
388 | + struct { |
389 | + bool is_allocated; |
390 | + bool is_initialized; |
391 | + } options; |
392 | + void *_impl; |
393 | +#ifdef __cplusplus |
394 | + struct Worker* impl() const |
395 | + { |
396 | + return (Worker*)(_impl); |
397 | + } |
398 | + |
399 | + void impl(Worker* impl_) |
400 | + { |
401 | + _impl= impl_; |
402 | + } |
403 | +#endif |
404 | +}; |
405 | + |
406 | |
407 | === modified file 'libgearman-1.0/job.h' |
408 | --- libgearman-1.0/job.h 2012-09-16 00:30:28 +0000 |
409 | +++ libgearman-1.0/job.h 2012-09-20 02:21:22 +0000 |
410 | @@ -43,24 +43,6 @@ |
411 | |
412 | #pragma once |
413 | |
414 | -struct gearman_job_st |
415 | -{ |
416 | - struct { |
417 | - bool allocated; |
418 | - bool assigned_in_use; |
419 | - bool work_in_use; |
420 | - bool finished; |
421 | - } options; |
422 | - gearman_worker_st *worker; |
423 | - gearman_job_st *next; |
424 | - gearman_job_st *prev; |
425 | - gearman_connection_st *con; |
426 | - gearman_packet_st assigned; |
427 | - gearman_packet_st work; |
428 | - struct gearman_job_reducer_st *reducer; |
429 | - gearman_return_t error_code; |
430 | -}; |
431 | - |
432 | #ifdef __cplusplus |
433 | extern "C" { |
434 | #endif |
435 | |
436 | === modified file 'libgearman-1.0/task_attr.h' |
437 | --- libgearman-1.0/task_attr.h 2012-04-15 21:57:52 +0000 |
438 | +++ libgearman-1.0/task_attr.h 2012-09-20 02:21:22 +0000 |
439 | @@ -66,7 +66,8 @@ |
440 | extern "C" { |
441 | #endif |
442 | |
443 | -#define gearman_next(X) (X) ? (X)->next : NULL |
444 | +GEARMAN_API |
445 | + gearman_task_st *gearman_next(gearman_task_st *task); |
446 | |
447 | GEARMAN_API |
448 | gearman_task_attr_t gearman_task_attr_init(gearman_job_priority_t priority); |
449 | |
450 | === modified file 'libgearman-1.0/util.h' |
451 | --- libgearman-1.0/util.h 2011-11-03 07:35:45 +0000 |
452 | +++ libgearman-1.0/util.h 2012-09-20 02:21:22 +0000 |
453 | @@ -50,7 +50,7 @@ |
454 | GEARMAN_API |
455 | const char *gearman_verbose_name(gearman_verbose_t verbose); |
456 | |
457 | -#define gearman_timeout(__object) ((__object)->universal.timeout) |
458 | +#define gearman_timeout(__object) ((__object)->impl()->universal.timeout) |
459 | |
460 | #define gearman_set_timeout(__object, __value) ((__object)->universal.timeout)=(__value); |
461 | |
462 | |
463 | === modified file 'libgearman-1.0/worker.h' |
464 | --- libgearman-1.0/worker.h 2012-06-28 01:28:50 +0000 |
465 | +++ libgearman-1.0/worker.h 2012-09-20 02:21:22 +0000 |
466 | @@ -43,6 +43,8 @@ |
467 | |
468 | #pragma once |
469 | |
470 | +#include <libgearman-1.0/interface/worker.h> |
471 | + |
472 | /** @addtogroup gearman_worker Worker Declarations |
473 | * |
474 | * This is the interface gearman workers should use. |
475 | @@ -67,39 +69,6 @@ |
476 | GEARMAN_WORKER_WORK_UNIVERSAL_FAIL |
477 | }; |
478 | |
479 | -/** |
480 | - * @ingroup gearman_worker |
481 | - */ |
482 | -struct gearman_worker_st |
483 | -{ |
484 | - struct { |
485 | - bool allocated; |
486 | - bool non_blocking; |
487 | - bool packet_init; |
488 | - bool change; |
489 | - bool grab_uniq; |
490 | - bool grab_all; |
491 | - bool timeout_return; |
492 | - } options; |
493 | - enum gearman_worker_state_t state; |
494 | - enum gearman_worker_universal_t work_state; |
495 | - uint32_t function_count; |
496 | - uint32_t job_count; |
497 | - size_t work_result_size; |
498 | - void *context; |
499 | - gearman_connection_st *con; |
500 | - gearman_job_st *job; |
501 | - gearman_job_st *job_list; |
502 | - struct _worker_function_st *function; |
503 | - struct _worker_function_st *function_list; |
504 | - struct _worker_function_st *work_function; |
505 | - void *work_result; |
506 | - struct gearman_universal_st universal; |
507 | - gearman_packet_st grab_job; |
508 | - gearman_packet_st pre_sleep; |
509 | - gearman_job_st *work_job; |
510 | -}; |
511 | - |
512 | #ifdef __cplusplus |
513 | #define gearman_has_reducer(A) (A) ? static_cast<bool>((A)->reducer.final_fn) : false |
514 | #else |
515 | |
516 | === modified file 'libgearman/actions.cc' |
517 | --- libgearman/actions.cc 2012-08-02 05:44:19 +0000 |
518 | +++ libgearman/actions.cc 2012-09-20 02:21:22 +0000 |
519 | @@ -47,27 +47,28 @@ |
520 | |
521 | struct gearman_result_st; |
522 | |
523 | -static gearman_return_t _client_pause_data(gearman_task_st *task) |
524 | +static gearman_return_t _client_pause_data(gearman_task_st* shell) |
525 | { |
526 | + Task* task= shell->impl(); |
527 | if (task->options.is_paused) |
528 | { |
529 | task->options.is_paused= false; |
530 | return GEARMAN_SUCCESS; |
531 | } |
532 | |
533 | - if (gearman_task_data_size(task)) |
534 | + if (gearman_task_data_size(shell)) |
535 | { |
536 | - if (gearman_task_result(task)) |
537 | + if (gearman_task_result(shell)) |
538 | { |
539 | - gearman_task_result(task)->clear(); |
540 | + gearman_task_result(shell)->clear(); |
541 | } |
542 | else |
543 | { |
544 | - task->result_ptr= new (std::nothrow) gearman_result_st(gearman_task_data_size(task)); |
545 | + task->result_ptr= new (std::nothrow) gearman_result_st(gearman_task_data_size(shell)); |
546 | } |
547 | assert_msg(task->result_ptr, "programmer error, result_ptr has not been allocated for task"); |
548 | |
549 | - gearman_string_append(gearman_task_mutable_result(task)->string(), static_cast<const char*>(gearman_task_data(task)), gearman_task_data_size(task)); |
550 | + gearman_string_append(gearman_task_mutable_result(shell)->string(), static_cast<const char*>(gearman_task_data(shell)), gearman_task_data_size(shell)); |
551 | } |
552 | |
553 | if (task->recv->command == GEARMAN_COMMAND_WORK_DATA) |
554 | @@ -92,8 +93,9 @@ |
555 | } |
556 | |
557 | |
558 | -static gearman_return_t _client_pause_status(gearman_task_st *task) |
559 | +static gearman_return_t _client_pause_status(gearman_task_st* shell) |
560 | { |
561 | + Task* task= shell->impl(); |
562 | assert_msg(task->recv->command == GEARMAN_COMMAND_WORK_STATUS or |
563 | task->recv->command == GEARMAN_COMMAND_STATUS_RES_UNIQUE or |
564 | task->recv->command == GEARMAN_COMMAND_STATUS_RES, "status has been called out of order for task, or was registered to run on non-status callback, see gearman_actions_t(3)"); |
565 | @@ -107,8 +109,9 @@ |
566 | return GEARMAN_PAUSE; |
567 | } |
568 | |
569 | -static gearman_return_t _client_pause_fail(gearman_task_st *task) |
570 | +static gearman_return_t _client_pause_fail(gearman_task_st* shell) |
571 | { |
572 | + Task* task= shell->impl(); |
573 | assert_msg(task->recv->command == GEARMAN_COMMAND_WORK_FAIL, |
574 | "fail callback has been called out of order for task, or was registered to run on non-fail callback, see gearman_actions_t(3)"); |
575 | if (task->options.is_paused) |
576 | @@ -121,39 +124,43 @@ |
577 | return GEARMAN_PAUSE; |
578 | } |
579 | |
580 | -static gearman_return_t _client_do_data(gearman_task_st *task) |
581 | +static gearman_return_t _client_do_data(gearman_task_st* shell) |
582 | { |
583 | - if (gearman_task_data_size(task)) |
584 | + Task* task= shell->impl(); |
585 | + |
586 | + if (gearman_task_data_size(shell)) |
587 | { |
588 | - if (gearman_task_result(task) == NULL) |
589 | + if (gearman_task_result(shell) == NULL) |
590 | { |
591 | - task->result_ptr= new (std::nothrow) gearman_result_st(gearman_task_data_size(task)); |
592 | + task->result_ptr= new (std::nothrow) gearman_result_st(gearman_task_data_size(shell)); |
593 | if (task->result_ptr == NULL) |
594 | { |
595 | return GEARMAN_MEMORY_ALLOCATION_FAILURE; |
596 | } |
597 | } |
598 | |
599 | - gearman_string_append(gearman_task_mutable_result(task)->string(), static_cast<const char*>(gearman_task_data(task)), gearman_task_data_size(task)); |
600 | + gearman_string_append(gearman_task_mutable_result(shell)->string(), static_cast<const char*>(gearman_task_data(shell)), gearman_task_data_size(shell)); |
601 | } |
602 | |
603 | return GEARMAN_SUCCESS; |
604 | } |
605 | |
606 | -static gearman_return_t _client_do_complete(gearman_task_st *task) |
607 | +static gearman_return_t _client_do_complete(gearman_task_st *shell) |
608 | { |
609 | - if (gearman_task_data_size(task)) |
610 | + Task* task= shell->impl(); |
611 | + |
612 | + if (gearman_task_data_size(shell)) |
613 | { |
614 | - if (gearman_task_result(task) == NULL) |
615 | + if (gearman_task_result(shell) == NULL) |
616 | { |
617 | - task->result_ptr= new (std::nothrow) gearman_result_st(gearman_task_data_size(task)); |
618 | + task->result_ptr= new (std::nothrow) gearman_result_st(gearman_task_data_size(shell)); |
619 | if (task->result_ptr == NULL) |
620 | { |
621 | return GEARMAN_MEMORY_ALLOCATION_FAILURE; |
622 | } |
623 | } |
624 | |
625 | - gearman_string_append(gearman_task_mutable_result(task)->string(), static_cast<const char*>(gearman_task_data(task)), gearman_task_data_size(task)); |
626 | + gearman_string_append(gearman_task_mutable_result(shell)->string(), static_cast<const char*>(gearman_task_data(shell)), gearman_task_data_size(shell)); |
627 | } |
628 | |
629 | task->result_rc= GEARMAN_SUCCESS; |
630 | |
631 | === modified file 'libgearman/actions.hpp' |
632 | --- libgearman/actions.hpp 2012-08-13 08:16:56 +0000 |
633 | +++ libgearman/actions.hpp 2012-09-20 02:21:22 +0000 |
634 | @@ -39,17 +39,13 @@ |
635 | |
636 | #ifdef __cplusplus // Local only |
637 | |
638 | -GEARMAN_LOCAL |
639 | const gearman_actions_t &gearman_actions_default(); |
640 | |
641 | -GEARMAN_LOCAL |
642 | const gearman_actions_t &gearman_actions_do_default(); |
643 | |
644 | -GEARMAN_LOCAL |
645 | const gearman_actions_t &gearman_actions_execute_defaults(); |
646 | |
647 | GEARMAN_API |
648 | const gearman_actions_t &gearman_actions_pause(); |
649 | |
650 | #endif |
651 | - |
652 | |
653 | === modified file 'libgearman/add.cc' |
654 | --- libgearman/add.cc 2012-09-12 09:17:38 +0000 |
655 | +++ libgearman/add.cc 2012-09-20 02:21:22 +0000 |
656 | @@ -89,7 +89,7 @@ |
657 | task= add_task(client, task, context, command, function, local_unique, workload, when, actions); |
658 | if (task == NULL) |
659 | { |
660 | - *ret_ptr= gearman_universal_error_code(client.universal); |
661 | + *ret_ptr= client.impl()->universal.error_code(); |
662 | return NULL; |
663 | } |
664 | |
665 | @@ -99,7 +99,7 @@ |
666 | } |
667 | |
668 | gearman_task_st *add_task(gearman_client_st& client, |
669 | - gearman_task_st *task, |
670 | + gearman_task_st *task_shell, |
671 | void *context, |
672 | gearman_command_t command, |
673 | const gearman_string_t &function, |
674 | @@ -112,11 +112,11 @@ |
675 | { |
676 | if (gearman_size(function) > GEARMAN_FUNCTION_MAX_SIZE) |
677 | { |
678 | - gearman_error(client.universal, GEARMAN_INVALID_ARGUMENT, "function name longer then GEARMAN_MAX_FUNCTION_SIZE"); |
679 | + gearman_error(client.impl()->universal, GEARMAN_INVALID_ARGUMENT, "function name longer then GEARMAN_MAX_FUNCTION_SIZE"); |
680 | } |
681 | else |
682 | { |
683 | - gearman_error(client.universal, GEARMAN_INVALID_ARGUMENT, "invalid function"); |
684 | + gearman_error(client.impl()->universal, GEARMAN_INVALID_ARGUMENT, "invalid function"); |
685 | } |
686 | |
687 | return NULL; |
688 | @@ -124,23 +124,27 @@ |
689 | |
690 | if (gearman_size(unique) > GEARMAN_MAX_UNIQUE_SIZE) |
691 | { |
692 | - gearman_error(client.universal, GEARMAN_INVALID_ARGUMENT, "unique name longer then GEARMAN_MAX_UNIQUE_SIZE"); |
693 | + gearman_error(client.impl()->universal, GEARMAN_INVALID_ARGUMENT, "unique name longer then GEARMAN_MAX_UNIQUE_SIZE"); |
694 | |
695 | return NULL; |
696 | } |
697 | |
698 | if ((gearman_size(workload) && gearman_c_str(workload) == NULL) or (gearman_size(workload) == 0 && gearman_c_str(workload))) |
699 | { |
700 | - gearman_error(client.universal, GEARMAN_INVALID_ARGUMENT, "invalid workload"); |
701 | + gearman_error(client.impl()->universal, GEARMAN_INVALID_ARGUMENT, "invalid workload"); |
702 | return NULL; |
703 | } |
704 | |
705 | - task= gearman_task_internal_create(&client, task); |
706 | - if (task == NULL) |
707 | + task_shell= gearman_task_internal_create(client, task_shell); |
708 | + if (task_shell == NULL or task_shell->impl() == NULL) |
709 | { |
710 | - gearman_error(client.universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, ""); |
711 | + gearman_error(client.impl()->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, ""); |
712 | return NULL; |
713 | } |
714 | + assert(task_shell->impl()->client); |
715 | + assert(task_shell->impl()->client == &client); |
716 | + |
717 | + Task* task= task_shell->impl(); |
718 | |
719 | task->context= context; |
720 | task->func= actions; |
721 | @@ -239,14 +243,14 @@ |
722 | |
723 | if (gearman_success(rc)) |
724 | { |
725 | - client.new_tasks++; |
726 | - client.running_tasks++; |
727 | + client.impl()->new_tasks++; |
728 | + client.impl()->running_tasks++; |
729 | task->options.send_in_use= true; |
730 | |
731 | - return task; |
732 | + return task->shell(); |
733 | } |
734 | |
735 | - gearman_task_free(task); |
736 | + gearman_task_free(task->shell()); |
737 | |
738 | return NULL; |
739 | } |
740 | @@ -269,11 +273,11 @@ |
741 | { |
742 | if (gearman_size(function) > GEARMAN_FUNCTION_MAX_SIZE) |
743 | { |
744 | - gearman_error(client->universal, GEARMAN_INVALID_ARGUMENT, "function name longer then GEARMAN_MAX_FUNCTION_SIZE"); |
745 | + gearman_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, "function name longer then GEARMAN_MAX_FUNCTION_SIZE"); |
746 | } |
747 | else |
748 | { |
749 | - gearman_error(client->universal, GEARMAN_INVALID_ARGUMENT, "invalid function"); |
750 | + gearman_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, "invalid function"); |
751 | } |
752 | |
753 | return NULL; |
754 | @@ -281,36 +285,36 @@ |
755 | |
756 | if (gearman_size(unique) > GEARMAN_MAX_UNIQUE_SIZE) |
757 | { |
758 | - gearman_error(client->universal, GEARMAN_INVALID_ARGUMENT, "unique name longer then GEARMAN_MAX_UNIQUE_SIZE"); |
759 | + gearman_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, "unique name longer then GEARMAN_MAX_UNIQUE_SIZE"); |
760 | |
761 | return NULL; |
762 | } |
763 | |
764 | if ((gearman_size(workload) and not gearman_c_str(workload)) or (gearman_size(workload) == 0 && gearman_c_str(workload))) |
765 | { |
766 | - gearman_error(client->universal, GEARMAN_INVALID_ARGUMENT, "invalid workload"); |
767 | + gearman_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, "invalid workload"); |
768 | return NULL; |
769 | } |
770 | |
771 | - gearman_task_st *task= gearman_task_internal_create(client, NULL); |
772 | + gearman_task_st *task= gearman_task_internal_create(*client, NULL); |
773 | if (task == NULL) |
774 | { |
775 | - gearman_error(client->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, ""); |
776 | + gearman_error(client->impl()->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, ""); |
777 | return NULL; |
778 | } |
779 | |
780 | - task->context= context; |
781 | - task->func= actions; |
782 | + task->impl()->context= context; |
783 | + task->impl()->func= actions; |
784 | |
785 | /** |
786 | @todo fix it so that NULL is done by default by the API not by happenstance. |
787 | */ |
788 | char function_buffer[1024]; |
789 | - if (client->universal._namespace) |
790 | + if (client->impl()->universal._namespace) |
791 | { |
792 | char *ptr= function_buffer; |
793 | - memcpy(ptr, gearman_string_value(client->universal._namespace), gearman_string_length(client->universal._namespace)); |
794 | - ptr+= gearman_string_length(client->universal._namespace); |
795 | + memcpy(ptr, gearman_string_value(client->impl()->universal._namespace), gearman_string_length(client->impl()->universal._namespace)); |
796 | + ptr+= gearman_string_length(client->impl()->universal._namespace); |
797 | |
798 | memcpy(ptr, gearman_c_str(function), gearman_size(function) +1); |
799 | ptr+= gearman_size(function); |
800 | @@ -326,6 +330,7 @@ |
801 | |
802 | if ((task->unique_length= gearman_size(unique))) |
803 | { |
804 | +<<<<<<< TREE |
805 | if (task->unique_length >= GEARMAN_MAX_UNIQUE_SIZE) |
806 | { |
807 | task->unique_length= GEARMAN_MAX_UNIQUE_SIZE -1; // Leave space for NULL byte |
808 | @@ -333,10 +338,23 @@ |
809 | |
810 | strncpy(task->unique, gearman_c_str(unique), GEARMAN_MAX_UNIQUE_SIZE); |
811 | task->unique[task->unique_length]= 0; |
812 | +======= |
813 | + args[1]= gearman_c_str(unique); |
814 | + args_size[1]= gearman_size(unique) + 1; |
815 | + strncpy(task->impl()->unique, gearman_c_str(unique), gearman_size(unique)); |
816 | +>>>>>>> MERGE-SOURCE |
817 | } |
818 | else |
819 | { |
820 | +<<<<<<< TREE |
821 | safe_uuid_generate(task->unique, task->unique_length); |
822 | +======= |
823 | + safe_uuid_generate(uuid); |
824 | + uuid_unparse(uuid, task->impl()->unique); |
825 | + task->impl()->unique[GEARMAN_MAX_UUID_SIZE]= 0; |
826 | + args[1]= task->impl()->unique; |
827 | + args_size[1]= GEARMAN_MAX_UUID_SIZE +1; // +1 is for the needed null |
828 | +>>>>>>> MERGE-SOURCE |
829 | } |
830 | |
831 | args[1]= task->unique; |
832 | @@ -346,11 +364,11 @@ |
833 | "Command was not appropriate for request"); |
834 | |
835 | char reducer_buffer[1024]; |
836 | - if (client->universal._namespace) |
837 | + if (client->impl()->universal._namespace) |
838 | { |
839 | char *ptr= reducer_buffer; |
840 | - memcpy(ptr, gearman_string_value(client->universal._namespace), gearman_string_length(client->universal._namespace)); |
841 | - ptr+= gearman_string_length(client->universal._namespace); |
842 | + memcpy(ptr, gearman_string_value(client->impl()->universal._namespace), gearman_string_length(client->impl()->universal._namespace)); |
843 | + ptr+= gearman_string_length(client->impl()->universal._namespace); |
844 | |
845 | memcpy(ptr, gearman_c_str(reducer), gearman_size(reducer) +1); |
846 | ptr+= gearman_size(reducer); |
847 | @@ -375,22 +393,22 @@ |
848 | args_size[4]= gearman_size(workload); |
849 | |
850 | gearman_return_t rc; |
851 | - if (gearman_success(rc= gearman_packet_create_args(client->universal, task->send, |
852 | + if (gearman_success(rc= gearman_packet_create_args(client->impl()->universal, task->impl()->send, |
853 | GEARMAN_MAGIC_REQUEST, command, |
854 | args, args_size, |
855 | 5))) |
856 | { |
857 | - client->new_tasks++; |
858 | - client->running_tasks++; |
859 | - task->options.send_in_use= true; |
860 | + client->impl()->new_tasks++; |
861 | + client->impl()->running_tasks++; |
862 | + task->impl()->options.send_in_use= true; |
863 | } |
864 | else |
865 | { |
866 | - gearman_gerror(client->universal, rc); |
867 | + gearman_gerror(client->impl()->universal, rc); |
868 | gearman_task_free(task); |
869 | task= NULL; |
870 | } |
871 | - task->type= GEARMAN_TASK_KIND_EXECUTE; |
872 | + task->impl()->type= GEARMAN_TASK_KIND_EXECUTE; |
873 | |
874 | return task; |
875 | } |
876 | |
877 | === modified file 'libgearman/allocator.hpp' |
878 | --- libgearman/allocator.hpp 2011-06-21 09:48:26 +0000 |
879 | +++ libgearman/allocator.hpp 2012-09-20 02:21:22 +0000 |
880 | @@ -36,29 +36,26 @@ |
881 | |
882 | #pragma once |
883 | |
884 | -GEARMAN_LOCAL |
885 | +#include <libgearman-1.0/allocator.h> |
886 | + |
887 | void *gearman_real_malloc(gearman_allocator_t& allocator, size_t size, const char *func, const char *file, int line); |
888 | |
889 | #define gearman_malloc(__gearman_universal_st, __size) gearman_real_malloc(((__gearman_universal_st).allocator), (__size), __func__, __FILE__, __LINE__) |
890 | |
891 | -GEARMAN_LOCAL |
892 | void *gearman_real_calloc(gearman_allocator_t& allocator, size_t nelem, size_t size, const char *func, const char *file, int line); |
893 | |
894 | #define gearman_calloc(__gearman_universal_st, __nelem, __size) gearman_real_calloc(((__gearman_universal_st).allocator), (__nelem), (__size), __func__, __FILE__, __LINE__) |
895 | |
896 | -GEARMAN_LOCAL |
897 | void *gearman_real_realloc(gearman_allocator_t&, void *ptr, size_t size, const char *func, const char *file, int line); |
898 | |
899 | #define gearman_realloc(__gearman_universal_st, __ptr, __size) gearman_real_realloc(((__gearman_universal_st).allocator), (__ptr), (__size), __func__, __FILE__, __LINE__) |
900 | |
901 | -GEARMAN_LOCAL |
902 | void gearman_real_free(gearman_allocator_t& allocator, void *ptr, const char *func, const char *file, int line); |
903 | |
904 | #define gearman_free(__gearman_universal_st, __ptr) gearman_real_free(((__gearman_universal_st).allocator), (__ptr), __func__, __FILE__, __LINE__) |
905 | |
906 | #define gearman_has_allocator(__gearman_universal_st) bool(__gearman_universal_st.allocator.malloc) |
907 | |
908 | -GEARMAN_LOCAL |
909 | gearman_return_t gearman_set_memory_allocator(gearman_allocator_t& allocator, |
910 | gearman_malloc_fn *malloc_fn, |
911 | gearman_free_fn *free_fn, |
912 | @@ -67,6 +64,5 @@ |
913 | void *context); |
914 | |
915 | |
916 | -GEARMAN_LOCAL |
917 | gearman_allocator_t gearman_default_allocator(); |
918 | |
919 | |
920 | === modified file 'libgearman/client.cc' |
921 | --- libgearman/client.cc 2012-09-17 03:07:48 +0000 |
922 | +++ libgearman/client.cc 2012-09-20 02:21:22 +0000 |
923 | @@ -42,6 +42,7 @@ |
924 | #include <libgearman/log.hpp> |
925 | |
926 | #include "libgearman/assert.hpp" |
927 | +#include "libgearman/interface/push.hpp" |
928 | |
929 | #include <arpa/inet.h> |
930 | #include <cerrno> |
931 | @@ -56,45 +57,23 @@ |
932 | /* |
933 | Allocate a client structure. |
934 | */ |
935 | -static gearman_client_st *_client_allocate(gearman_client_st *client, bool is_clone) |
936 | +static gearman_client_st *_client_allocate(gearman_client_st *client_shell, bool is_clone) |
937 | { |
938 | + Client *client= new (std::nothrow) Client(client_shell); |
939 | if (client) |
940 | { |
941 | - client->options.allocated= false; |
942 | - } |
943 | - else |
944 | - { |
945 | - client= new (std::nothrow) gearman_client_st; |
946 | - if (client == NULL) |
947 | + if (is_clone == false) |
948 | { |
949 | - return NULL; |
950 | +#if 0 |
951 | + gearman_universal_initialize(client_shell->impl()->universal); |
952 | + gearman_universal_initialize(universal); |
953 | +#endif |
954 | } |
955 | |
956 | - client->options.allocated= true; |
957 | - } |
958 | - |
959 | - client->options.non_blocking= false; |
960 | - client->options.unbuffered_result= false; |
961 | - client->options.no_new= false; |
962 | - client->options.free_tasks= false; |
963 | - |
964 | - client->state= GEARMAN_CLIENT_STATE_IDLE; |
965 | - client->new_tasks= 0; |
966 | - client->running_tasks= 0; |
967 | - client->task_count= 0; |
968 | - client->context= NULL; |
969 | - client->con= NULL; |
970 | - client->task= NULL; |
971 | - client->task_list= NULL; |
972 | - client->task_context_free_fn= NULL; |
973 | - gearman_client_clear_fn(client); |
974 | - |
975 | - if (is_clone == false) |
976 | - { |
977 | - gearman_universal_initialize(client->universal); |
978 | - } |
979 | - |
980 | - return client; |
981 | + return client->shell(); |
982 | + } |
983 | + |
984 | + return NULL; |
985 | } |
986 | |
987 | /** |
988 | @@ -128,7 +107,7 @@ |
989 | return NULL; |
990 | } |
991 | |
992 | - universal_reset_error(client->universal); |
993 | + client->impl()->universal.reset_error(); |
994 | |
995 | size_t unused_size; |
996 | if (result_size == NULL) |
997 | @@ -142,23 +121,28 @@ |
998 | gearman_string_t workload= { static_cast<const char*>(workload_str), workload_size }; |
999 | |
1000 | gearman_task_st do_task; |
1001 | - gearman_task_st *do_task_ptr= add_task(*client, &do_task, NULL, command, |
1002 | - function, |
1003 | - local_unique, |
1004 | - workload, |
1005 | - time_t(0), |
1006 | - gearman_actions_do_default()); |
1007 | - if (do_task_ptr == NULL) |
1008 | { |
1009 | - *ret_ptr= gearman_universal_error_code(client->universal); |
1010 | - return NULL; |
1011 | + gearman_task_st *do_task_ptr= add_task(*client, &do_task, NULL, command, |
1012 | + function, |
1013 | + local_unique, |
1014 | + workload, |
1015 | + time_t(0), |
1016 | + gearman_actions_do_default()); |
1017 | + if (do_task_ptr == NULL) |
1018 | + { |
1019 | + *ret_ptr= client->impl()->universal.error_code(); |
1020 | + return NULL; |
1021 | + } |
1022 | + assert_msg(do_task.impl(), "Bad return by add_task()"); |
1023 | + assert_msg(&do_task == do_task_ptr, "Bad return by add_task()"); |
1024 | } |
1025 | - do_task_ptr->type= GEARMAN_TASK_KIND_DO; |
1026 | + |
1027 | + do_task.impl()->type= GEARMAN_TASK_KIND_DO; |
1028 | |
1029 | gearman_return_t ret= gearman_client_run_block_tasks(client); |
1030 | |
1031 | // gearman_client_run_tasks failed |
1032 | - assert(client->task_list); // Programmer error, we should always have the task that we used for do |
1033 | + assert(client->impl()->task_list); // Programmer error, we should always have the task that we used for do |
1034 | |
1035 | char *returnable= NULL; |
1036 | if (gearman_failed(ret)) |
1037 | @@ -167,24 +151,24 @@ |
1038 | { } |
1039 | else |
1040 | { |
1041 | - gearman_error(client->universal, ret, "occured during gearman_client_run_tasks()"); |
1042 | + gearman_error(client->impl()->universal, ret, "occured during gearman_client_run_tasks()"); |
1043 | } |
1044 | |
1045 | *ret_ptr= ret; |
1046 | *result_size= 0; |
1047 | } |
1048 | - else if (gearman_success(ret) and do_task_ptr->result_rc == GEARMAN_SUCCESS) |
1049 | + else if (gearman_success(ret) and do_task.impl()->result_rc == GEARMAN_SUCCESS) |
1050 | { |
1051 | - *ret_ptr= do_task_ptr->result_rc; |
1052 | - if (gearman_task_result(do_task_ptr)) |
1053 | + *ret_ptr= do_task.impl()->result_rc; |
1054 | + if (gearman_task_result(&do_task)) |
1055 | { |
1056 | - if (gearman_has_allocator(client->universal)) |
1057 | + if (gearman_has_allocator(client->impl()->universal)) |
1058 | { |
1059 | - gearman_string_t result= gearman_result_string(do_task_ptr->result_ptr); |
1060 | - returnable= static_cast<char *>(gearman_malloc(client->universal, gearman_size(result) +1)); |
1061 | + gearman_string_t result= gearman_result_string(do_task.impl()->result_ptr); |
1062 | + returnable= static_cast<char *>(gearman_malloc(client->impl()->universal, gearman_size(result) +1)); |
1063 | if (returnable == NULL) |
1064 | { |
1065 | - gearman_error(client->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "custom workload_fn failed to allocate memory"); |
1066 | + gearman_error(client->impl()->universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "custom workload_fn failed to allocate memory"); |
1067 | *result_size= 0; |
1068 | } |
1069 | else // NULL terminate |
1070 | @@ -196,7 +180,7 @@ |
1071 | } |
1072 | else |
1073 | { |
1074 | - gearman_string_t result= gearman_result_take_string(do_task_ptr->result_ptr); |
1075 | + gearman_string_t result= gearman_result_take_string(do_task.impl()->result_ptr); |
1076 | *result_size= gearman_size(result); |
1077 | returnable= const_cast<char *>(gearman_c_str(result)); |
1078 | } |
1079 | @@ -208,15 +192,15 @@ |
1080 | } |
1081 | else // gearman_client_run_tasks() was successful, but the task was not |
1082 | { |
1083 | - gearman_error(client->universal, do_task_ptr->result_rc, "occured during gearman_client_run_tasks()"); |
1084 | + gearman_error(client->impl()->universal, do_task.impl()->result_rc, "occured during gearman_client_run_tasks()"); |
1085 | |
1086 | - *ret_ptr= do_task_ptr->result_rc; |
1087 | + *ret_ptr= do_task.impl()->result_rc; |
1088 | *result_size= 0; |
1089 | } |
1090 | |
1091 | gearman_task_free(&do_task); |
1092 | - client->new_tasks= 0; |
1093 | - client->running_tasks= 0; |
1094 | + client->impl()->new_tasks= 0; |
1095 | + client->impl()->running_tasks= 0; |
1096 | |
1097 | return returnable; |
1098 | } |
1099 | @@ -236,39 +220,43 @@ |
1100 | return GEARMAN_INVALID_ARGUMENT; |
1101 | } |
1102 | |
1103 | - universal_reset_error(client->universal); |
1104 | + client->impl()->universal.reset_error(); |
1105 | |
1106 | if (gearman_size(function) == 0) |
1107 | { |
1108 | - return gearman_error(client->universal, GEARMAN_INVALID_ARGUMENT, "function argument was empty"); |
1109 | + return gearman_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, "function argument was empty"); |
1110 | } |
1111 | |
1112 | - client->_do_handle[0]= 0; // Reset the job_handle we store in client |
1113 | + client->impl()->_do_handle[0]= 0; // Reset the job_handle we store in client |
1114 | |
1115 | - gearman_task_st do_task, *do_task_ptr; |
1116 | - do_task_ptr= add_task(*client, &do_task, |
1117 | - client, |
1118 | - command, |
1119 | - function, |
1120 | - unique, |
1121 | - workload, |
1122 | - time_t(0), |
1123 | - gearman_actions_do_default()); |
1124 | - if (not do_task_ptr) |
1125 | + gearman_task_st do_task; |
1126 | { |
1127 | - return gearman_universal_error_code(client->universal); |
1128 | + gearman_task_st* do_task_ptr= add_task(*client, &do_task, |
1129 | + client, |
1130 | + command, |
1131 | + function, |
1132 | + unique, |
1133 | + workload, |
1134 | + time_t(0), |
1135 | + gearman_actions_do_default()); |
1136 | + if (do_task_ptr == NULL) |
1137 | + { |
1138 | + return client->impl()->universal.error_code(); |
1139 | + } |
1140 | + assert(do_task_ptr); |
1141 | + assert(&do_task == do_task_ptr); |
1142 | } |
1143 | - do_task_ptr->type= GEARMAN_TASK_KIND_DO; |
1144 | + do_task.impl()->type= GEARMAN_TASK_KIND_DO; |
1145 | |
1146 | gearman_return_t ret= gearman_client_run_block_tasks(client); |
1147 | |
1148 | if (job_handle) |
1149 | { |
1150 | - strncpy(job_handle, do_task.job_handle, GEARMAN_JOB_HANDLE_SIZE); |
1151 | + strncpy(job_handle, do_task.impl()->job_handle, GEARMAN_JOB_HANDLE_SIZE); |
1152 | } |
1153 | - strncpy(client->_do_handle, do_task.job_handle, GEARMAN_JOB_HANDLE_SIZE); |
1154 | - client->new_tasks= 0; |
1155 | - client->running_tasks= 0; |
1156 | + strncpy(client->impl()->_do_handle, do_task.impl()->job_handle, GEARMAN_JOB_HANDLE_SIZE); |
1157 | + client->impl()->new_tasks= 0; |
1158 | + client->impl()->running_tasks= 0; |
1159 | gearman_task_free(&do_task); |
1160 | |
1161 | return ret; |
1162 | @@ -284,59 +272,56 @@ |
1163 | return _client_allocate(client, false); |
1164 | } |
1165 | |
1166 | -gearman_client_st *gearman_client_clone(gearman_client_st *client, |
1167 | - const gearman_client_st *from) |
1168 | -{ |
1169 | - if (not from) |
1170 | - { |
1171 | - return _client_allocate(client, false); |
1172 | - } |
1173 | - |
1174 | - client= _client_allocate(client, true); |
1175 | - |
1176 | - if (client == NULL) |
1177 | - { |
1178 | - return client; |
1179 | - } |
1180 | - |
1181 | - client->options.non_blocking= from->options.non_blocking; |
1182 | - client->options.unbuffered_result= from->options.unbuffered_result; |
1183 | - client->options.no_new= from->options.no_new; |
1184 | - client->options.free_tasks= from->options.free_tasks; |
1185 | - client->actions= from->actions; |
1186 | - client->_do_handle[0]= 0; |
1187 | - |
1188 | - gearman_universal_clone(client->universal, from->universal); |
1189 | - |
1190 | - return client; |
1191 | -} |
1192 | - |
1193 | -void gearman_client_free(gearman_client_st *client) |
1194 | -{ |
1195 | - if (client) |
1196 | - { |
1197 | - |
1198 | - gearman_client_task_free_all(client); |
1199 | - |
1200 | - gearman_universal_free(client->universal); |
1201 | - |
1202 | - if (client->options.allocated) |
1203 | - { |
1204 | - delete client; |
1205 | - } |
1206 | - } |
1207 | -} |
1208 | - |
1209 | -const char *gearman_client_error(const gearman_client_st *client) |
1210 | -{ |
1211 | - if (client) |
1212 | - { |
1213 | - return gearman_universal_error(client->universal); |
1214 | +gearman_client_st *gearman_client_clone(gearman_client_st *destination, |
1215 | + const gearman_client_st *source) |
1216 | +{ |
1217 | + if (source == NULL) |
1218 | + { |
1219 | + return _client_allocate(destination, false); |
1220 | + } |
1221 | + |
1222 | + destination= _client_allocate(destination, true); |
1223 | + |
1224 | + if (destination == NULL) |
1225 | + { |
1226 | + return destination; |
1227 | + } |
1228 | + |
1229 | + destination->impl()->options.non_blocking= source->impl()->options.non_blocking; |
1230 | + destination->impl()->options.unbuffered_result= source->impl()->options.unbuffered_result; |
1231 | + destination->impl()->options.no_new= source->impl()->options.no_new; |
1232 | + destination->impl()->options.free_tasks= source->impl()->options.free_tasks; |
1233 | + destination->impl()->actions= source->impl()->actions; |
1234 | + destination->impl()->_do_handle[0]= 0; |
1235 | + |
1236 | + gearman_universal_clone(destination->impl()->universal, source->impl()->universal); |
1237 | + |
1238 | + return destination; |
1239 | +} |
1240 | + |
1241 | +void gearman_client_free(gearman_client_st *client_shell) |
1242 | +{ |
1243 | + if (client_shell) |
1244 | + { |
1245 | + gearman_client_task_free_all(client_shell); |
1246 | + |
1247 | + gearman_universal_free(client_shell->impl()->universal); |
1248 | + |
1249 | + delete client_shell->impl(); |
1250 | + } |
1251 | +} |
1252 | + |
1253 | +const char *gearman_client_error(const gearman_client_st *client_shell) |
1254 | +{ |
1255 | + if (client_shell) |
1256 | + { |
1257 | + return client_shell->impl()->universal.error(); |
1258 | } |
1259 | |
1260 | return NULL; |
1261 | } |
1262 | |
1263 | +<<<<<<< TREE |
1264 | gearman_return_t gearman_client_error_code(const gearman_client_st *client) |
1265 | { |
1266 | if (client == NULL) |
1267 | @@ -358,49 +343,72 @@ |
1268 | } |
1269 | |
1270 | gearman_client_options_t gearman_client_options(const gearman_client_st *client) |
1271 | +======= |
1272 | +gearman_return_t gearman_client_error_code(const gearman_client_st *client_shell) |
1273 | +{ |
1274 | + if (client_shell) |
1275 | + { |
1276 | + return client_shell->impl()->universal.error_code(); |
1277 | + } |
1278 | + |
1279 | + return GEARMAN_INVALID_ARGUMENT; |
1280 | +} |
1281 | + |
1282 | +int gearman_client_errno(const gearman_client_st *client_shell) |
1283 | +{ |
1284 | + if (client_shell) |
1285 | + { |
1286 | + return client_shell->impl()->universal.last_errno(); |
1287 | + } |
1288 | + |
1289 | + return 0; |
1290 | +} |
1291 | + |
1292 | +gearman_client_options_t gearman_client_options(const gearman_client_st *client_shell) |
1293 | +>>>>>>> MERGE-SOURCE |
1294 | { |
1295 | int32_t options; |
1296 | memset(&options, 0, sizeof(int32_t)); |
1297 | |
1298 | - if (client->options.allocated) |
1299 | + if (gearman_is_allocated(client_shell)) |
1300 | options|= int(GEARMAN_CLIENT_ALLOCATED); |
1301 | |
1302 | - if (client->options.non_blocking) |
1303 | + if (client_shell->impl()->options.non_blocking) |
1304 | options|= int(GEARMAN_CLIENT_NON_BLOCKING); |
1305 | |
1306 | - if (client->options.unbuffered_result) |
1307 | + if (client_shell->impl()->options.unbuffered_result) |
1308 | options|= int(GEARMAN_CLIENT_UNBUFFERED_RESULT); |
1309 | |
1310 | - if (client->options.no_new) |
1311 | + if (client_shell->impl()->options.no_new) |
1312 | options|= int(GEARMAN_CLIENT_NO_NEW); |
1313 | |
1314 | - if (client->options.free_tasks) |
1315 | + if (client_shell->impl()->options.free_tasks) |
1316 | options|= int(GEARMAN_CLIENT_FREE_TASKS); |
1317 | |
1318 | return gearman_client_options_t(options); |
1319 | } |
1320 | |
1321 | -bool gearman_client_has_option(gearman_client_st *client, |
1322 | +bool gearman_client_has_option(gearman_client_st *client_shell, |
1323 | gearman_client_options_t option) |
1324 | { |
1325 | - if (client) |
1326 | + if (client_shell and client_shell->impl()) |
1327 | { |
1328 | switch (option) |
1329 | { |
1330 | case GEARMAN_CLIENT_ALLOCATED: |
1331 | - return client->options.allocated; |
1332 | + return gearman_is_allocated(client_shell); |
1333 | |
1334 | case GEARMAN_CLIENT_NON_BLOCKING: |
1335 | - return client->options.non_blocking; |
1336 | + return client_shell->impl()->options.non_blocking; |
1337 | |
1338 | case GEARMAN_CLIENT_UNBUFFERED_RESULT: |
1339 | - return client->options.unbuffered_result; |
1340 | + return client_shell->impl()->options.unbuffered_result; |
1341 | |
1342 | case GEARMAN_CLIENT_NO_NEW: |
1343 | - return client->options.no_new; |
1344 | + return client_shell->impl()->options.no_new; |
1345 | |
1346 | case GEARMAN_CLIENT_FREE_TASKS: |
1347 | - return client->options.free_tasks; |
1348 | + return client_shell->impl()->options.free_tasks; |
1349 | |
1350 | default: |
1351 | case GEARMAN_CLIENT_TASK_IN_USE: |
1352 | @@ -412,10 +420,10 @@ |
1353 | return false; |
1354 | } |
1355 | |
1356 | -void gearman_client_set_options(gearman_client_st *client, |
1357 | +void gearman_client_set_options(gearman_client_st *client_shell, |
1358 | gearman_client_options_t options) |
1359 | { |
1360 | - if (client) |
1361 | + if (client_shell) |
1362 | { |
1363 | gearman_client_options_t usable_options[]= { |
1364 | GEARMAN_CLIENT_NON_BLOCKING, |
1365 | @@ -428,130 +436,130 @@ |
1366 | { |
1367 | if (options & *ptr) |
1368 | { |
1369 | - gearman_client_add_options(client, *ptr); |
1370 | + gearman_client_add_options(client_shell, *ptr); |
1371 | } |
1372 | else |
1373 | { |
1374 | - gearman_client_remove_options(client, *ptr); |
1375 | + gearman_client_remove_options(client_shell, *ptr); |
1376 | } |
1377 | } |
1378 | } |
1379 | } |
1380 | |
1381 | -void gearman_client_add_options(gearman_client_st *client, |
1382 | +void gearman_client_add_options(gearman_client_st *client_shell, |
1383 | gearman_client_options_t options) |
1384 | { |
1385 | - if (client) |
1386 | + if (client_shell) |
1387 | { |
1388 | if (options & GEARMAN_CLIENT_NON_BLOCKING) |
1389 | { |
1390 | - gearman_universal_add_options(client->universal, GEARMAN_NON_BLOCKING); |
1391 | - client->options.non_blocking= true; |
1392 | + gearman_universal_add_options(client_shell->impl()->universal, GEARMAN_NON_BLOCKING); |
1393 | + client_shell->impl()->options.non_blocking= true; |
1394 | } |
1395 | |
1396 | if (options & GEARMAN_CLIENT_UNBUFFERED_RESULT) |
1397 | { |
1398 | - client->options.unbuffered_result= true; |
1399 | + client_shell->impl()->options.unbuffered_result= true; |
1400 | } |
1401 | |
1402 | if (options & GEARMAN_CLIENT_FREE_TASKS) |
1403 | { |
1404 | - client->options.free_tasks= true; |
1405 | + client_shell->impl()->options.free_tasks= true; |
1406 | } |
1407 | } |
1408 | } |
1409 | |
1410 | -void gearman_client_remove_options(gearman_client_st *client, |
1411 | +void gearman_client_remove_options(gearman_client_st *client_shell, |
1412 | gearman_client_options_t options) |
1413 | { |
1414 | - if (client) |
1415 | + if (client_shell) |
1416 | { |
1417 | if (options & GEARMAN_CLIENT_NON_BLOCKING) |
1418 | { |
1419 | - gearman_universal_remove_options(client->universal, GEARMAN_NON_BLOCKING); |
1420 | - client->options.non_blocking= false; |
1421 | + gearman_universal_remove_options(client_shell->impl()->universal, GEARMAN_NON_BLOCKING); |
1422 | + client_shell->impl()->options.non_blocking= false; |
1423 | } |
1424 | |
1425 | if (options & GEARMAN_CLIENT_UNBUFFERED_RESULT) |
1426 | { |
1427 | - client->options.unbuffered_result= false; |
1428 | + client_shell->impl()->options.unbuffered_result= false; |
1429 | } |
1430 | |
1431 | if (options & GEARMAN_CLIENT_FREE_TASKS) |
1432 | { |
1433 | - client->options.free_tasks= false; |
1434 | + client_shell->impl()->options.free_tasks= false; |
1435 | } |
1436 | } |
1437 | } |
1438 | |
1439 | -int gearman_client_timeout(gearman_client_st *client) |
1440 | +int gearman_client_timeout(gearman_client_st *client_shell) |
1441 | { |
1442 | - return gearman_universal_timeout(client->universal); |
1443 | + return gearman_universal_timeout(client_shell->impl()->universal); |
1444 | } |
1445 | |
1446 | -void gearman_client_set_timeout(gearman_client_st *client, int timeout) |
1447 | +void gearman_client_set_timeout(gearman_client_st *client_shell, int timeout) |
1448 | { |
1449 | - if (client) |
1450 | + if (client_shell) |
1451 | { |
1452 | - gearman_universal_set_timeout(client->universal, timeout); |
1453 | + gearman_universal_set_timeout(client_shell->impl()->universal, timeout); |
1454 | } |
1455 | } |
1456 | |
1457 | -void *gearman_client_context(const gearman_client_st *client) |
1458 | +void *gearman_client_context(const gearman_client_st *client_shell) |
1459 | { |
1460 | - if (client) |
1461 | + if (client_shell) |
1462 | { |
1463 | - return const_cast<void *>(client->context); |
1464 | + return const_cast<void *>(client_shell->impl()->context); |
1465 | } |
1466 | |
1467 | return NULL; |
1468 | } |
1469 | |
1470 | -void gearman_client_set_context(gearman_client_st *client, void *context) |
1471 | +void gearman_client_set_context(gearman_client_st *client_shell, void *context) |
1472 | { |
1473 | - if (client) |
1474 | + if (client_shell) |
1475 | { |
1476 | - client->context= context; |
1477 | + client_shell->impl()->context= context; |
1478 | } |
1479 | } |
1480 | |
1481 | -void gearman_client_set_log_fn(gearman_client_st *client, |
1482 | +void gearman_client_set_log_fn(gearman_client_st *client_shell, |
1483 | gearman_log_fn *function, void *context, |
1484 | gearman_verbose_t verbose) |
1485 | { |
1486 | - if (client) |
1487 | + if (client_shell) |
1488 | { |
1489 | - gearman_set_log_fn(client->universal, function, context, verbose); |
1490 | + gearman_set_log_fn(client_shell->impl()->universal, function, context, verbose); |
1491 | } |
1492 | } |
1493 | |
1494 | -void gearman_client_set_workload_malloc_fn(gearman_client_st *client, |
1495 | +void gearman_client_set_workload_malloc_fn(gearman_client_st *client_shell, |
1496 | gearman_malloc_fn *function, |
1497 | void *context) |
1498 | { |
1499 | - if (client) |
1500 | + if (client_shell) |
1501 | { |
1502 | - gearman_set_workload_malloc_fn(client->universal, function, context); |
1503 | + gearman_set_workload_malloc_fn(client_shell->impl()->universal, function, context); |
1504 | } |
1505 | } |
1506 | |
1507 | -void gearman_client_set_workload_free_fn(gearman_client_st *client, gearman_free_fn *function, void *context) |
1508 | +void gearman_client_set_workload_free_fn(gearman_client_st *client_shell, gearman_free_fn *function, void *context) |
1509 | { |
1510 | - if (client) |
1511 | + if (client_shell) |
1512 | { |
1513 | - gearman_set_workload_free_fn(client->universal, function, context); |
1514 | + gearman_set_workload_free_fn(client_shell->impl()->universal, function, context); |
1515 | } |
1516 | } |
1517 | |
1518 | -gearman_return_t gearman_client_add_server(gearman_client_st *client, |
1519 | +gearman_return_t gearman_client_add_server(gearman_client_st *client_shell, |
1520 | const char *host, in_port_t port) |
1521 | { |
1522 | - if (client) |
1523 | + if (client_shell) |
1524 | { |
1525 | - if (gearman_connection_create_args(client->universal, host, port) == false) |
1526 | + if (gearman_connection_create_args(client_shell->impl()->universal, host, port) == false) |
1527 | { |
1528 | - assert(client->universal.error.rc != GEARMAN_SUCCESS); |
1529 | - return gearman_universal_error_code(client->universal); |
1530 | + assert(client_shell->impl()->universal.error_code() != GEARMAN_SUCCESS); |
1531 | + return client_shell->impl()->universal.error_code(); |
1532 | } |
1533 | |
1534 | return GEARMAN_SUCCESS; |
1535 | @@ -560,81 +568,92 @@ |
1536 | return GEARMAN_INVALID_ARGUMENT; |
1537 | } |
1538 | |
1539 | -gearman_return_t gearman_client_add_servers(gearman_client_st *client, |
1540 | +gearman_return_t Client::add_server(const char *host, const char* service_) |
1541 | +{ |
1542 | + if (gearman_connection_create_args(universal, host, service_) == false) |
1543 | + { |
1544 | + assert(universal.error_code() != GEARMAN_SUCCESS); |
1545 | + return universal.error_code(); |
1546 | + } |
1547 | + |
1548 | + return GEARMAN_SUCCESS; |
1549 | +} |
1550 | + |
1551 | +gearman_return_t gearman_client_add_servers(gearman_client_st *client_shell, |
1552 | const char *servers) |
1553 | { |
1554 | - return gearman_parse_servers(servers, _client_add_server, client); |
1555 | + return gearman_parse_servers(servers, _client_add_server, client_shell); |
1556 | } |
1557 | |
1558 | -void gearman_client_remove_servers(gearman_client_st *client) |
1559 | +void gearman_client_remove_servers(gearman_client_st *client_shell) |
1560 | { |
1561 | - if (client) |
1562 | + if (client_shell) |
1563 | { |
1564 | - gearman_free_all_cons(client->universal); |
1565 | + gearman_free_all_cons(client_shell->impl()->universal); |
1566 | } |
1567 | } |
1568 | |
1569 | -gearman_return_t gearman_client_wait(gearman_client_st *client) |
1570 | +gearman_return_t gearman_client_wait(gearman_client_st *client_shell) |
1571 | { |
1572 | - if (client) |
1573 | + if (client_shell) |
1574 | { |
1575 | - return gearman_wait(client->universal); |
1576 | + return gearman_wait(client_shell->impl()->universal); |
1577 | } |
1578 | |
1579 | return GEARMAN_INVALID_ARGUMENT; |
1580 | } |
1581 | |
1582 | -void *gearman_client_do(gearman_client_st *client, |
1583 | +void *gearman_client_do(gearman_client_st *client_shell, |
1584 | const char *function, |
1585 | const char *unique, |
1586 | const void *workload, |
1587 | size_t workload_size, size_t *result_size, |
1588 | gearman_return_t *ret_ptr) |
1589 | { |
1590 | - return _client_do(client, GEARMAN_COMMAND_SUBMIT_JOB, |
1591 | + return _client_do(client_shell, GEARMAN_COMMAND_SUBMIT_JOB, |
1592 | function, |
1593 | unique, |
1594 | workload, workload_size, |
1595 | result_size, ret_ptr); |
1596 | } |
1597 | |
1598 | -void *gearman_client_do_high(gearman_client_st *client, |
1599 | +void *gearman_client_do_high(gearman_client_st *client_shell, |
1600 | const char *function, |
1601 | const char *unique, |
1602 | const void *workload, size_t workload_size, |
1603 | size_t *result_size, gearman_return_t *ret_ptr) |
1604 | { |
1605 | - return _client_do(client, GEARMAN_COMMAND_SUBMIT_JOB_HIGH, |
1606 | + return _client_do(client_shell, GEARMAN_COMMAND_SUBMIT_JOB_HIGH, |
1607 | function, |
1608 | unique, |
1609 | workload, workload_size, |
1610 | result_size, ret_ptr); |
1611 | } |
1612 | |
1613 | -void *gearman_client_do_low(gearman_client_st *client, |
1614 | +void *gearman_client_do_low(gearman_client_st *client_shell, |
1615 | const char *function, |
1616 | const char *unique, |
1617 | const void *workload, size_t workload_size, |
1618 | size_t *result_size, gearman_return_t *ret_ptr) |
1619 | { |
1620 | - return _client_do(client, GEARMAN_COMMAND_SUBMIT_JOB_LOW, |
1621 | + return _client_do(client_shell, GEARMAN_COMMAND_SUBMIT_JOB_LOW, |
1622 | function, |
1623 | unique, |
1624 | workload, workload_size, |
1625 | result_size, ret_ptr); |
1626 | } |
1627 | |
1628 | -size_t gearman_client_count_tasks(gearman_client_st *client) |
1629 | +size_t gearman_client_count_tasks(gearman_client_st *client_shell) |
1630 | { |
1631 | - if (client == NULL) |
1632 | + if (client_shell == NULL) |
1633 | { |
1634 | return 0; |
1635 | } |
1636 | |
1637 | size_t count= 1; |
1638 | - gearman_task_st *search= client->task_list; |
1639 | + gearman_task_st *search= client_shell->impl()->task_list; |
1640 | |
1641 | - while ((search= search->next)) |
1642 | + while ((search= search->impl()->next)) |
1643 | { |
1644 | count++; |
1645 | } |
1646 | @@ -643,10 +662,10 @@ |
1647 | } |
1648 | |
1649 | #if 0 |
1650 | -static bool _active_tasks(gearman_client_st *client) |
1651 | +static bool _active_tasks(gearman_client_st *client_shell) |
1652 | { |
1653 | - assert(client); |
1654 | - gearman_task_st *search= client->task_list; |
1655 | + assert(client_shell); |
1656 | + gearman_task_st *search= client_shell->impl()->task_list; |
1657 | |
1658 | if (not search) |
1659 | return false; |
1660 | @@ -667,7 +686,7 @@ |
1661 | { |
1662 | if (self) |
1663 | { |
1664 | - return self->_do_handle; |
1665 | + return self->impl()->_do_handle; |
1666 | } |
1667 | |
1668 | errno= EINVAL; |
1669 | @@ -687,7 +706,7 @@ |
1670 | } |
1671 | } |
1672 | |
1673 | -gearman_return_t gearman_client_do_background(gearman_client_st *client, |
1674 | +gearman_return_t gearman_client_do_background(gearman_client_st *client_shell, |
1675 | const char *function_name, |
1676 | const char *unique, |
1677 | const void *workload_str, |
1678 | @@ -698,14 +717,14 @@ |
1679 | gearman_unique_t local_unique= gearman_unique_make(unique, unique ? strlen(unique) : 0); |
1680 | gearman_string_t workload= { static_cast<const char*>(workload_str), workload_size }; |
1681 | |
1682 | - return _client_do_background(client, GEARMAN_COMMAND_SUBMIT_JOB_BG, |
1683 | + return _client_do_background(client_shell, GEARMAN_COMMAND_SUBMIT_JOB_BG, |
1684 | function, |
1685 | local_unique, |
1686 | workload, |
1687 | job_handle); |
1688 | } |
1689 | |
1690 | -gearman_return_t gearman_client_do_high_background(gearman_client_st *client, |
1691 | +gearman_return_t gearman_client_do_high_background(gearman_client_st *client_shell, |
1692 | const char *function_name, |
1693 | const char *unique, |
1694 | const void *workload_str, |
1695 | @@ -716,14 +735,14 @@ |
1696 | gearman_unique_t local_unique= gearman_unique_make(unique, unique ? strlen(unique) : 0); |
1697 | gearman_string_t workload= { static_cast<const char*>(workload_str), workload_size }; |
1698 | |
1699 | - return _client_do_background(client, GEARMAN_COMMAND_SUBMIT_JOB_HIGH_BG, |
1700 | + return _client_do_background(client_shell, GEARMAN_COMMAND_SUBMIT_JOB_HIGH_BG, |
1701 | function, |
1702 | local_unique, |
1703 | workload, |
1704 | job_handle); |
1705 | } |
1706 | |
1707 | -gearman_return_t gearman_client_do_low_background(gearman_client_st *client, |
1708 | +gearman_return_t gearman_client_do_low_background(gearman_client_st *client_shell, |
1709 | const char *function_name, |
1710 | const char *unique, |
1711 | const void *workload_str, |
1712 | @@ -734,7 +753,7 @@ |
1713 | gearman_unique_t local_unique= gearman_unique_make(unique, unique ? strlen(unique) : 0); |
1714 | gearman_string_t workload= { static_cast<const char*>(workload_str), workload_size }; |
1715 | |
1716 | - return _client_do_background(client, GEARMAN_COMMAND_SUBMIT_JOB_LOW_BG, |
1717 | + return _client_do_background(client_shell, GEARMAN_COMMAND_SUBMIT_JOB_LOW_BG, |
1718 | function, |
1719 | local_unique, |
1720 | workload, |
1721 | @@ -754,22 +773,28 @@ |
1722 | return status; |
1723 | } |
1724 | |
1725 | - universal_reset_error(client->universal); |
1726 | + client->impl()->universal.reset_error(); |
1727 | |
1728 | gearman_return_t ret; |
1729 | gearman_task_st do_task; |
1730 | - gearman_task_st *do_task_ptr= gearman_client_add_task_status_by_unique(client, |
1731 | - &do_task, |
1732 | - unique, &ret); |
1733 | - if (gearman_failed(ret)) |
1734 | { |
1735 | - gearman_status_set_return(status, ret); |
1736 | - return status; |
1737 | + gearman_task_st *do_task_ptr= gearman_client_add_task_status_by_unique(client, |
1738 | + &do_task, |
1739 | + unique, &ret); |
1740 | + if (gearman_failed(ret)) |
1741 | + { |
1742 | + gearman_status_set_return(status, ret); |
1743 | + return status; |
1744 | + } |
1745 | + (void)do_task_ptr; |
1746 | + assert(do_task_ptr); |
1747 | + assert(&do_task == do_task_ptr); |
1748 | } |
1749 | - assert(do_task_ptr); |
1750 | - do_task_ptr->type= GEARMAN_TASK_KIND_DO; |
1751 | - |
1752 | - gearman_task_clear_fn(do_task_ptr); |
1753 | + |
1754 | + Task* task= do_task.impl(); |
1755 | + task->type= GEARMAN_TASK_KIND_DO; |
1756 | + |
1757 | + gearman_task_clear_fn(&do_task); |
1758 | |
1759 | ret= gearman_client_run_block_tasks(client); |
1760 | |
1761 | @@ -779,26 +804,26 @@ |
1762 | if (gearman_success(ret)) |
1763 | { |
1764 | gearman_status_set(status, |
1765 | - do_task.options.is_known, |
1766 | - do_task.options.is_running, |
1767 | - do_task.numerator, |
1768 | - do_task.denominator, |
1769 | - do_task.client_count); |
1770 | + task->options.is_known, |
1771 | + task->options.is_running, |
1772 | + task->numerator, |
1773 | + task->denominator, |
1774 | + task->client_count); |
1775 | |
1776 | if (gearman_status_is_known(status) == false and gearman_status_is_running(status) == false) |
1777 | { |
1778 | - if (do_task.options.is_running) |
1779 | + if (task->options.is_running) |
1780 | { |
1781 | ret= GEARMAN_IN_PROGRESS; |
1782 | } |
1783 | - else if (do_task.options.is_known) |
1784 | + else if (task->options.is_known) |
1785 | { |
1786 | ret= GEARMAN_JOB_EXISTS; |
1787 | } |
1788 | } |
1789 | } |
1790 | |
1791 | - gearman_task_free(do_task_ptr); |
1792 | + gearman_task_free(&do_task); |
1793 | |
1794 | gearman_status_set_return(status, ret); |
1795 | |
1796 | @@ -818,19 +843,21 @@ |
1797 | return GEARMAN_INVALID_ARGUMENT; |
1798 | } |
1799 | |
1800 | - universal_reset_error(client->universal); |
1801 | + client->impl()->universal.reset_error(); |
1802 | |
1803 | gearman_task_st do_task; |
1804 | - gearman_task_st *do_task_ptr= gearman_client_add_task_status(client, &do_task, client, |
1805 | - job_handle, &ret); |
1806 | - if (gearman_failed(ret)) |
1807 | { |
1808 | - return ret; |
1809 | + gearman_task_st *do_task_ptr= gearman_client_add_task_status(client, &do_task, client, |
1810 | + job_handle, &ret); |
1811 | + if (gearman_failed(ret)) |
1812 | + { |
1813 | + return ret; |
1814 | + } |
1815 | + assert_msg(do_task_ptr, "Programming error, a NULL return happend from gearman_client_add_task_status() without an error"); |
1816 | } |
1817 | - assert(do_task_ptr); |
1818 | - do_task_ptr->type= GEARMAN_TASK_KIND_DO; |
1819 | + do_task.impl()->type= GEARMAN_TASK_KIND_DO; |
1820 | |
1821 | - gearman_task_clear_fn(do_task_ptr); |
1822 | + gearman_task_clear_fn(&do_task); |
1823 | |
1824 | ret= gearman_client_run_block_tasks(client); |
1825 | |
1826 | @@ -841,31 +868,31 @@ |
1827 | { |
1828 | if (is_known) |
1829 | { |
1830 | - *is_known= do_task.options.is_known; |
1831 | + *is_known= do_task.impl()->options.is_known; |
1832 | } |
1833 | |
1834 | if (is_running) |
1835 | { |
1836 | - *is_running= do_task.options.is_running; |
1837 | + *is_running= do_task.impl()->options.is_running; |
1838 | } |
1839 | |
1840 | if (numerator) |
1841 | { |
1842 | - *numerator= do_task.numerator; |
1843 | + *numerator= do_task.impl()->numerator; |
1844 | } |
1845 | |
1846 | if (denominator) |
1847 | { |
1848 | - *denominator= do_task.denominator; |
1849 | + *denominator= do_task.impl()->denominator; |
1850 | } |
1851 | |
1852 | if (is_known == false and is_running == false) |
1853 | { |
1854 | - if (do_task.options.is_running) |
1855 | + if (do_task.impl()->options.is_running) |
1856 | { |
1857 | ret= GEARMAN_IN_PROGRESS; |
1858 | } |
1859 | - else if (do_task.options.is_known) |
1860 | + else if (do_task.impl()->options.is_known) |
1861 | { |
1862 | ret= GEARMAN_JOB_EXISTS; |
1863 | } |
1864 | @@ -893,7 +920,7 @@ |
1865 | *denominator= 0; |
1866 | } |
1867 | } |
1868 | - gearman_task_free(do_task_ptr); |
1869 | + gearman_task_free(&do_task); |
1870 | |
1871 | return ret; |
1872 | } |
1873 | @@ -907,16 +934,16 @@ |
1874 | return GEARMAN_INVALID_ARGUMENT; |
1875 | } |
1876 | |
1877 | - return gearman_echo(client->universal, workload, workload_size); |
1878 | + return gearman_echo(client->impl()->universal, workload, workload_size); |
1879 | } |
1880 | |
1881 | void gearman_client_task_free_all(gearman_client_st *client) |
1882 | { |
1883 | - if (client and client->task_list) |
1884 | + if (client and client->impl()->task_list) |
1885 | { |
1886 | - while (client->task_list) |
1887 | + while (client->impl()->task_list) |
1888 | { |
1889 | - gearman_task_free(client->task_list); |
1890 | + gearman_task_free(client->impl()->task_list); |
1891 | } |
1892 | } |
1893 | } |
1894 | @@ -927,7 +954,7 @@ |
1895 | { |
1896 | if (client) |
1897 | { |
1898 | - client->task_context_free_fn= function; |
1899 | + client->impl()->task_context_free_fn= function; |
1900 | } |
1901 | } |
1902 | |
1903 | @@ -943,7 +970,7 @@ |
1904 | return GEARMAN_INVALID_ARGUMENT; |
1905 | } |
1906 | |
1907 | - return gearman_set_memory_allocator(client->universal.allocator, malloc_fn, free_fn, realloc_fn, calloc_fn, context); |
1908 | + return gearman_set_memory_allocator(client->impl()->universal.allocator, malloc_fn, free_fn, realloc_fn, calloc_fn, context); |
1909 | } |
1910 | |
1911 | |
1912 | @@ -975,7 +1002,7 @@ |
1913 | workload, workload_size, |
1914 | time_t(0), |
1915 | ret_ptr, |
1916 | - client->actions); |
1917 | + client->impl()->actions); |
1918 | } |
1919 | |
1920 | gearman_task_st *gearman_client_add_task_high(gearman_client_st *client, |
1921 | @@ -1005,7 +1032,7 @@ |
1922 | workload, workload_size, |
1923 | time_t(0), |
1924 | ret_ptr, |
1925 | - client->actions); |
1926 | + client->impl()->actions); |
1927 | } |
1928 | |
1929 | gearman_task_st *gearman_client_add_task_low(gearman_client_st *client, |
1930 | @@ -1034,7 +1061,7 @@ |
1931 | workload, workload_size, |
1932 | time_t(0), |
1933 | ret_ptr, |
1934 | - client->actions); |
1935 | + client->impl()->actions); |
1936 | } |
1937 | |
1938 | gearman_task_st *gearman_client_add_task_background(gearman_client_st *client, |
1939 | @@ -1063,7 +1090,7 @@ |
1940 | workload, workload_size, |
1941 | time_t(0), |
1942 | ret_ptr, |
1943 | - client->actions); |
1944 | + client->impl()->actions); |
1945 | } |
1946 | |
1947 | gearman_task_st * |
1948 | @@ -1094,7 +1121,7 @@ |
1949 | workload, workload_size, |
1950 | time_t(0), |
1951 | ret_ptr, |
1952 | - client->actions); |
1953 | + client->impl()->actions); |
1954 | } |
1955 | |
1956 | gearman_task_st* gearman_client_add_task_low_background(gearman_client_st *client, |
1957 | @@ -1124,12 +1151,12 @@ |
1958 | workload, workload_size, |
1959 | time_t(0), |
1960 | ret_ptr, |
1961 | - client->actions); |
1962 | + client->impl()->actions); |
1963 | |
1964 | } |
1965 | |
1966 | gearman_task_st *gearman_client_add_task_status(gearman_client_st *client, |
1967 | - gearman_task_st *task, |
1968 | + gearman_task_st *task_shell, |
1969 | void *context, |
1970 | const gearman_job_handle_t job_handle, |
1971 | gearman_return_t *ret_ptr) |
1972 | @@ -1149,34 +1176,36 @@ |
1973 | return NULL; |
1974 | } |
1975 | |
1976 | - if ((task= gearman_task_internal_create(client, task)) == NULL) |
1977 | + if ((task_shell= gearman_task_internal_create(*client, task_shell)) == NULL) |
1978 | { |
1979 | *ret_ptr= GEARMAN_MEMORY_ALLOCATION_FAILURE; |
1980 | return NULL; |
1981 | } |
1982 | |
1983 | + Task* task= task_shell->impl(); |
1984 | + |
1985 | task->context= context; |
1986 | snprintf(task->job_handle, GEARMAN_JOB_HANDLE_SIZE, "%s", job_handle); |
1987 | |
1988 | args[0]= job_handle; |
1989 | args_size[0]= strlen(job_handle); |
1990 | - gearman_return_t rc= gearman_packet_create_args(client->universal, task->send, |
1991 | + gearman_return_t rc= gearman_packet_create_args(client->impl()->universal, task->send, |
1992 | GEARMAN_MAGIC_REQUEST, |
1993 | GEARMAN_COMMAND_GET_STATUS, |
1994 | args, args_size, 1); |
1995 | if (gearman_success(rc)) |
1996 | { |
1997 | - client->new_tasks++; |
1998 | - client->running_tasks++; |
1999 | + client->impl()->new_tasks++; |
2000 | + client->impl()->running_tasks++; |
2001 | task->options.send_in_use= true; |
2002 | } |
2003 | *ret_ptr= rc; |
2004 | |
2005 | - return task; |
2006 | + return task_shell; |
2007 | } |
2008 | |
2009 | gearman_task_st *gearman_client_add_task_status_by_unique(gearman_client_st *client, |
2010 | - gearman_task_st *task_ptr, |
2011 | + gearman_task_st *task_shell, |
2012 | const char *unique_handle, |
2013 | gearman_return_t *ret_ptr) |
2014 | { |
2015 | @@ -1208,32 +1237,33 @@ |
2016 | return NULL; |
2017 | } |
2018 | |
2019 | - gearman_task_st *task; |
2020 | - if ((task= gearman_task_internal_create(client, task_ptr)) == NULL) |
2021 | + if ((task_shell= gearman_task_internal_create(*client, task_shell)) == NULL) |
2022 | { |
2023 | *ret_ptr= GEARMAN_MEMORY_ALLOCATION_FAILURE; |
2024 | return NULL; |
2025 | } |
2026 | |
2027 | + Task* task= task_shell->impl(); |
2028 | + |
2029 | task->unique_length= unique_length; |
2030 | memcpy(task->unique, unique_handle, unique_length); |
2031 | task->unique[task->unique_length]= 0; |
2032 | |
2033 | args[0]= task->unique; |
2034 | args_size[0]= task->unique_length; |
2035 | - gearman_return_t rc= gearman_packet_create_args(client->universal, task->send, |
2036 | + gearman_return_t rc= gearman_packet_create_args(client->impl()->universal, task->send, |
2037 | GEARMAN_MAGIC_REQUEST, |
2038 | GEARMAN_COMMAND_GET_STATUS_UNIQUE, |
2039 | args, args_size, 1); |
2040 | if (gearman_success(rc)) |
2041 | { |
2042 | - client->new_tasks++; |
2043 | - client->running_tasks++; |
2044 | + client->impl()->new_tasks++; |
2045 | + client->impl()->running_tasks++; |
2046 | task->options.send_in_use= true; |
2047 | } |
2048 | *ret_ptr= rc; |
2049 | |
2050 | - return task; |
2051 | + return task_shell; |
2052 | } |
2053 | |
2054 | void gearman_client_set_workload_fn(gearman_client_st *client, |
2055 | @@ -1241,7 +1271,7 @@ |
2056 | { |
2057 | if (client) |
2058 | { |
2059 | - client->actions.workload_fn= function; |
2060 | + client->impl()->actions.workload_fn= function; |
2061 | } |
2062 | } |
2063 | |
2064 | @@ -1250,7 +1280,7 @@ |
2065 | { |
2066 | if (client) |
2067 | { |
2068 | - client->actions.created_fn= function; |
2069 | + client->impl()->actions.created_fn= function; |
2070 | } |
2071 | } |
2072 | |
2073 | @@ -1259,7 +1289,7 @@ |
2074 | { |
2075 | if (client) |
2076 | { |
2077 | - client->actions.data_fn= function; |
2078 | + client->impl()->actions.data_fn= function; |
2079 | } |
2080 | } |
2081 | |
2082 | @@ -1268,7 +1298,7 @@ |
2083 | { |
2084 | if (client) |
2085 | { |
2086 | - client->actions.warning_fn= function; |
2087 | + client->impl()->actions.warning_fn= function; |
2088 | } |
2089 | } |
2090 | |
2091 | @@ -1277,7 +1307,7 @@ |
2092 | { |
2093 | if (client) |
2094 | { |
2095 | - client->actions.status_fn= function; |
2096 | + client->impl()->actions.status_fn= function; |
2097 | } |
2098 | } |
2099 | |
2100 | @@ -1286,7 +1316,7 @@ |
2101 | { |
2102 | if (client) |
2103 | { |
2104 | - client->actions.complete_fn= function; |
2105 | + client->impl()->actions.complete_fn= function; |
2106 | } |
2107 | } |
2108 | |
2109 | @@ -1295,24 +1325,24 @@ |
2110 | { |
2111 | if (client) |
2112 | { |
2113 | - client->actions.exception_fn= function; |
2114 | + client->impl()->actions.exception_fn= function; |
2115 | } |
2116 | } |
2117 | |
2118 | -void gearman_client_set_fail_fn(gearman_client_st *client, |
2119 | +void gearman_client_set_fail_fn(gearman_client_st* client, |
2120 | gearman_fail_fn *function) |
2121 | { |
2122 | if (client) |
2123 | { |
2124 | - client->actions.fail_fn= function; |
2125 | + client->impl()->actions.fail_fn= function; |
2126 | } |
2127 | } |
2128 | |
2129 | -void gearman_client_clear_fn(gearman_client_st *client) |
2130 | +void gearman_client_clear_fn(gearman_client_st* client) |
2131 | { |
2132 | if (client) |
2133 | { |
2134 | - client->actions= gearman_actions_default(); |
2135 | + client->impl()->actions= gearman_actions_default(); |
2136 | } |
2137 | } |
2138 | |
2139 | @@ -1320,42 +1350,42 @@ |
2140 | { |
2141 | gearman_return_t ret= GEARMAN_MAX_RETURN; |
2142 | |
2143 | - switch(client->state) |
2144 | + switch(client->impl()->state) |
2145 | { |
2146 | case GEARMAN_CLIENT_STATE_IDLE: |
2147 | while (1) |
2148 | { |
2149 | /* Start any new tasks. */ |
2150 | - if (client->new_tasks > 0 && ! (client->options.no_new)) |
2151 | + if (client->impl()->new_tasks > 0 && ! (client->impl()->options.no_new)) |
2152 | { |
2153 | - for (client->task= client->task_list; client->task; |
2154 | - client->task= client->task->next) |
2155 | + for (client->impl()->task= client->impl()->task_list; client->impl()->task; |
2156 | + client->impl()->task= client->impl()->task->impl()->next) |
2157 | { |
2158 | - if (client->task->state != GEARMAN_TASK_STATE_NEW) |
2159 | + if (client->impl()->task->impl()->state != GEARMAN_TASK_STATE_NEW) |
2160 | { |
2161 | continue; |
2162 | } |
2163 | |
2164 | case GEARMAN_CLIENT_STATE_NEW: |
2165 | - if (client->task == NULL) |
2166 | + if (client->impl()->task == NULL) |
2167 | { |
2168 | - client->state= GEARMAN_CLIENT_STATE_IDLE; |
2169 | + client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
2170 | break; |
2171 | } |
2172 | |
2173 | - assert_msg(client == client->task->client, "Programmer error, client and task member client are not the same"); |
2174 | - gearman_return_t local_ret= _client_run_task(client->task); |
2175 | + assert_msg(client == client->impl()->task->impl()->client, "Programmer error, client and task member client are not the same"); |
2176 | + gearman_return_t local_ret= _client_run_task(client->impl()->task->impl()); |
2177 | if (gearman_failed(local_ret) and local_ret != GEARMAN_IO_WAIT) |
2178 | { |
2179 | - client->state= GEARMAN_CLIENT_STATE_NEW; |
2180 | + client->impl()->state= GEARMAN_CLIENT_STATE_NEW; |
2181 | |
2182 | return local_ret; |
2183 | } |
2184 | } |
2185 | |
2186 | - if (client->new_tasks == 0) |
2187 | + if (client->impl()->new_tasks == 0) |
2188 | { |
2189 | - gearman_return_t local_ret= gearman_flush_all(client->universal); |
2190 | + gearman_return_t local_ret= gearman_flush_all(client->impl()->universal); |
2191 | if (gearman_failed(local_ret)) |
2192 | { |
2193 | return local_ret; |
2194 | @@ -1364,52 +1394,52 @@ |
2195 | } |
2196 | |
2197 | /* See if there are any connections ready for I/O. */ |
2198 | - while ((client->con= gearman_ready(client->universal))) |
2199 | + while ((client->impl()->con= gearman_ready(client->impl()->universal))) |
2200 | { |
2201 | - if (client->con->revents & (POLLOUT | POLLERR | POLLHUP | POLLNVAL)) |
2202 | + if (client->impl()->con->revents & (POLLOUT | POLLERR | POLLHUP | POLLNVAL)) |
2203 | { |
2204 | /* Socket is ready for writing, continue submitting jobs. */ |
2205 | - for (client->task= client->task_list; client->task; |
2206 | - client->task= client->task->next) |
2207 | + for (client->impl()->task= client->impl()->task_list; client->impl()->task; |
2208 | + client->impl()->task= client->impl()->task->impl()->next) |
2209 | { |
2210 | - if (client->task->con != client->con or |
2211 | - (client->task->state != GEARMAN_TASK_STATE_SUBMIT and |
2212 | - client->task->state != GEARMAN_TASK_STATE_WORKLOAD)) |
2213 | + if (client->impl()->task->impl()->con != client->impl()->con or |
2214 | + (client->impl()->task->impl()->state != GEARMAN_TASK_STATE_SUBMIT and |
2215 | + client->impl()->task->impl()->state != GEARMAN_TASK_STATE_WORKLOAD)) |
2216 | { |
2217 | continue; |
2218 | } |
2219 | |
2220 | case GEARMAN_CLIENT_STATE_SUBMIT: |
2221 | - if (client->task == NULL) |
2222 | + if (client->impl()->task == NULL) |
2223 | { |
2224 | - client->state= GEARMAN_CLIENT_STATE_IDLE; |
2225 | + client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
2226 | break; |
2227 | } |
2228 | - assert_msg(client == client->task->client, "Programmer error, client and task member client are not the same"); |
2229 | - gearman_return_t local_ret= _client_run_task(client->task); |
2230 | + assert_msg(client == client->impl()->task->impl()->client, "Programmer error, client and task member client are not the same"); |
2231 | + gearman_return_t local_ret= _client_run_task(client->impl()->task->impl()); |
2232 | if (local_ret == GEARMAN_COULD_NOT_CONNECT) |
2233 | { |
2234 | - client->state= GEARMAN_CLIENT_STATE_IDLE; |
2235 | + client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
2236 | return local_ret; |
2237 | } |
2238 | else if (gearman_failed(local_ret) and local_ret != GEARMAN_IO_WAIT) |
2239 | { |
2240 | - client->state= GEARMAN_CLIENT_STATE_SUBMIT; |
2241 | + client->impl()->state= GEARMAN_CLIENT_STATE_SUBMIT; |
2242 | return local_ret; |
2243 | } |
2244 | } |
2245 | |
2246 | /* Connection errors are fatal. */ |
2247 | - if (client->con->revents & (POLLERR | POLLHUP | POLLNVAL)) |
2248 | + if (client->impl()->con->revents & (POLLERR | POLLHUP | POLLNVAL)) |
2249 | { |
2250 | - gearman_error(client->universal, GEARMAN_LOST_CONNECTION, "detected lost connection in _client_run_tasks()"); |
2251 | - client->con->close_socket(); |
2252 | - client->state= GEARMAN_CLIENT_STATE_IDLE; |
2253 | + gearman_error(client->impl()->universal, GEARMAN_LOST_CONNECTION, "detected lost connection in _client_run_tasks()"); |
2254 | + client->impl()->con->close_socket(); |
2255 | + client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
2256 | return GEARMAN_LOST_CONNECTION; |
2257 | } |
2258 | } |
2259 | |
2260 | - if ((client->con->revents & POLLIN) == 0) |
2261 | + if ((client->impl()->con->revents & POLLIN) == 0) |
2262 | { |
2263 | continue; |
2264 | } |
2265 | @@ -1418,17 +1448,17 @@ |
2266 | while (1) |
2267 | { |
2268 | /* Read packet on connection and find which task it belongs to. */ |
2269 | - if (client->options.unbuffered_result) |
2270 | + if (client->impl()->options.unbuffered_result) |
2271 | { |
2272 | /* If client is handling the data read, make sure it's complete. */ |
2273 | - if (client->con->recv_state == GEARMAN_CON_RECV_STATE_READ_DATA) |
2274 | + if (client->impl()->con->recv_state == GEARMAN_CON_RECV_STATE_READ_DATA) |
2275 | { |
2276 | - for (client->task= client->task_list; client->task; |
2277 | - client->task= client->task->next) |
2278 | + for (client->impl()->task= client->impl()->task_list; client->impl()->task; |
2279 | + client->impl()->task= client->impl()->task->impl()->next) |
2280 | { |
2281 | - if (client->task->con == client->con && |
2282 | - (client->task->state == GEARMAN_TASK_STATE_DATA or |
2283 | - client->task->state == GEARMAN_TASK_STATE_COMPLETE)) |
2284 | + if (client->impl()->task->impl()->con == client->impl()->con && |
2285 | + (client->impl()->task->impl()->state == GEARMAN_TASK_STATE_DATA or |
2286 | + client->impl()->task->impl()->state == GEARMAN_TASK_STATE_COMPLETE)) |
2287 | { |
2288 | break; |
2289 | } |
2290 | @@ -1438,24 +1468,24 @@ |
2291 | Someone has set GEARMAN_CLIENT_UNBUFFERED_RESULT but hasn't setup the client to fetch data correctly. |
2292 | Fatal error :( |
2293 | */ |
2294 | - return gearman_universal_set_error(client->universal, GEARMAN_INVALID_ARGUMENT, GEARMAN_AT, |
2295 | + return gearman_universal_set_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, GEARMAN_AT, |
2296 | "client created with GEARMAN_CLIENT_UNBUFFERED_RESULT, but was not setup to use it. %s", __func__); |
2297 | } |
2298 | else |
2299 | { |
2300 | /* Read the next packet, without buffering the data part. */ |
2301 | - client->task= NULL; |
2302 | - (void)client->con->receiving(client->con->_packet, ret, false); |
2303 | + client->impl()->task= NULL; |
2304 | + (void)client->impl()->con->receiving(client->impl()->con->_packet, ret, false); |
2305 | } |
2306 | } |
2307 | else |
2308 | { |
2309 | /* Read the next packet, buffering the data part. */ |
2310 | - client->task= NULL; |
2311 | - (void)client->con->receiving(client->con->_packet, ret, true); |
2312 | + client->impl()->task= NULL; |
2313 | + (void)client->impl()->con->receiving(client->impl()->con->_packet, ret, true); |
2314 | } |
2315 | |
2316 | - if (client->task == NULL) |
2317 | + if (client->impl()->task == NULL) |
2318 | { |
2319 | assert(ret != GEARMAN_MAX_RETURN); |
2320 | |
2321 | @@ -1467,65 +1497,65 @@ |
2322 | break; |
2323 | } |
2324 | |
2325 | - client->state= GEARMAN_CLIENT_STATE_IDLE; |
2326 | + client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
2327 | return ret; |
2328 | } |
2329 | |
2330 | - client->con->options.packet_in_use= true; |
2331 | + client->impl()->con->options.packet_in_use= true; |
2332 | |
2333 | /* We have a packet, see which task it belongs to. */ |
2334 | - for (client->task= client->task_list; client->task; |
2335 | - client->task= client->task->next) |
2336 | + for (client->impl()->task= client->impl()->task_list; client->impl()->task; |
2337 | + client->impl()->task= client->impl()->task->impl()->next) |
2338 | { |
2339 | - if (client->task->con != client->con) |
2340 | + if (client->impl()->task->impl()->con != client->impl()->con) |
2341 | { |
2342 | continue; |
2343 | } |
2344 | |
2345 | - gearman_log_debug(&client->universal, "Got %s", gearman_strcommand(client->con->_packet.command)); |
2346 | - if (client->con->_packet.command == GEARMAN_COMMAND_JOB_CREATED) |
2347 | + gearman_log_debug(&client->impl()->universal, "Got %s", gearman_strcommand(client->impl()->con->_packet.command)); |
2348 | + if (client->impl()->con->_packet.command == GEARMAN_COMMAND_JOB_CREATED) |
2349 | { |
2350 | - if (client->task->created_id != client->con->created_id) |
2351 | + if (client->impl()->task->impl()->created_id != client->impl()->con->created_id) |
2352 | { |
2353 | continue; |
2354 | } |
2355 | |
2356 | /* New job created, drop through below and notify task. */ |
2357 | - client->con->created_id++; |
2358 | + client->impl()->con->created_id++; |
2359 | } |
2360 | - else if (client->con->_packet.command == GEARMAN_COMMAND_ERROR) |
2361 | + else if (client->impl()->con->_packet.command == GEARMAN_COMMAND_ERROR) |
2362 | { |
2363 | - gearman_universal_set_error(client->universal, GEARMAN_SERVER_ERROR, GEARMAN_AT, |
2364 | + gearman_universal_set_error(client->impl()->universal, GEARMAN_SERVER_ERROR, GEARMAN_AT, |
2365 | "%s:%.*s", |
2366 | - static_cast<char *>(client->con->_packet.arg[0]), |
2367 | - int(client->con->_packet.arg_size[1]), |
2368 | - static_cast<char *>(client->con->_packet.arg[1])); |
2369 | + static_cast<char *>(client->impl()->con->_packet.arg[0]), |
2370 | + int(client->impl()->con->_packet.arg_size[1]), |
2371 | + static_cast<char *>(client->impl()->con->_packet.arg[1])); |
2372 | |
2373 | /* |
2374 | Packet cleanup copied from "Clean up the packet" below, and must |
2375 | remain in sync with its reference. |
2376 | */ |
2377 | - gearman_packet_free(&(client->con->_packet)); |
2378 | - client->con->options.packet_in_use= false; |
2379 | + gearman_packet_free(&(client->impl()->con->_packet)); |
2380 | + client->impl()->con->options.packet_in_use= false; |
2381 | |
2382 | /* This step copied from _client_run_tasks() above: */ |
2383 | /* Increment this value because new job created then failed. */ |
2384 | - client->con->created_id++; |
2385 | + client->impl()->con->created_id++; |
2386 | |
2387 | return GEARMAN_SERVER_ERROR; |
2388 | } |
2389 | - else if (client->con->_packet.command == GEARMAN_COMMAND_STATUS_RES_UNIQUE and |
2390 | - (strncmp(gearman_task_unique(client->task), |
2391 | - static_cast<char *>(client->con->_packet.arg[0]), |
2392 | - client->con->_packet.arg_size[0]) == 0)) |
2393 | + else if (client->impl()->con->_packet.command == GEARMAN_COMMAND_STATUS_RES_UNIQUE and |
2394 | + (strncmp(gearman_task_unique(client->impl()->task), |
2395 | + static_cast<char *>(client->impl()->con->_packet.arg[0]), |
2396 | + client->impl()->con->_packet.arg_size[0]) == 0)) |
2397 | { } |
2398 | - else if (strncmp(client->task->job_handle, |
2399 | - static_cast<char *>(client->con->_packet.arg[0]), |
2400 | - client->con->_packet.arg_size[0]) || |
2401 | - (client->con->_packet.command != GEARMAN_COMMAND_WORK_FAIL && |
2402 | - strlen(client->task->job_handle) != client->con->_packet.arg_size[0] - 1) || |
2403 | - (client->con->_packet.command == GEARMAN_COMMAND_WORK_FAIL && |
2404 | - strlen(client->task->job_handle) != client->con->_packet.arg_size[0])) |
2405 | + else if (strncmp(client->impl()->task->impl()->job_handle, |
2406 | + static_cast<char *>(client->impl()->con->_packet.arg[0]), |
2407 | + client->impl()->con->_packet.arg_size[0]) || |
2408 | + (client->impl()->con->_packet.command != GEARMAN_COMMAND_WORK_FAIL && |
2409 | + strlen(client->impl()->task->impl()->job_handle) != client->impl()->con->_packet.arg_size[0] - 1) || |
2410 | + (client->impl()->con->_packet.command == GEARMAN_COMMAND_WORK_FAIL && |
2411 | + strlen(client->impl()->task->impl()->job_handle) != client->impl()->con->_packet.arg_size[0])) |
2412 | { |
2413 | continue; |
2414 | } |
2415 | @@ -1535,20 +1565,20 @@ |
2416 | break; |
2417 | } |
2418 | |
2419 | - if (client->task == NULL) |
2420 | + if (client->impl()->task == NULL) |
2421 | { |
2422 | /* The client has stopped waiting for the response, ignore it. */ |
2423 | - client->con->free_private_packet(); |
2424 | + client->impl()->con->free_private_packet(); |
2425 | continue; |
2426 | } |
2427 | |
2428 | - client->task->recv= &(client->con->_packet); |
2429 | + client->impl()->task->impl()->recv= &(client->impl()->con->_packet); |
2430 | } |
2431 | |
2432 | case GEARMAN_CLIENT_STATE_PACKET: |
2433 | /* Let task process job created or result packet. */ |
2434 | - assert_msg(client == client->task->client, "Programmer error, client and task member client are not the same"); |
2435 | - gearman_return_t local_ret= _client_run_task(client->task); |
2436 | + assert_msg(client == client->impl()->task->impl()->client, "Programmer error, client and task member client are not the same"); |
2437 | + gearman_return_t local_ret= _client_run_task(client->impl()->task->impl()); |
2438 | if (local_ret == GEARMAN_IO_WAIT) |
2439 | { |
2440 | break; |
2441 | @@ -1556,46 +1586,46 @@ |
2442 | |
2443 | if (gearman_failed(local_ret)) |
2444 | { |
2445 | - client->state= GEARMAN_CLIENT_STATE_PACKET; |
2446 | + client->impl()->state= GEARMAN_CLIENT_STATE_PACKET; |
2447 | return local_ret; |
2448 | } |
2449 | |
2450 | /* Clean up the packet. */ |
2451 | - client->con->free_private_packet(); |
2452 | + client->impl()->con->free_private_packet(); |
2453 | |
2454 | /* If all tasks are done, return. */ |
2455 | - if (client->running_tasks == 0) |
2456 | + if (client->impl()->running_tasks == 0) |
2457 | { |
2458 | - client->state= GEARMAN_CLIENT_STATE_IDLE; |
2459 | + client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
2460 | return GEARMAN_SUCCESS; |
2461 | } |
2462 | } |
2463 | } |
2464 | |
2465 | /* If all tasks are done, return. */ |
2466 | - if (client->running_tasks == 0) |
2467 | + if (client->impl()->running_tasks == 0) |
2468 | { |
2469 | break; |
2470 | } |
2471 | |
2472 | - if (client->new_tasks > 0 and ! (client->options.no_new)) |
2473 | + if (client->impl()->new_tasks > 0 and ! (client->impl()->options.no_new)) |
2474 | { |
2475 | continue; |
2476 | } |
2477 | |
2478 | - if (client->options.non_blocking) |
2479 | + if (client->impl()->options.non_blocking) |
2480 | { |
2481 | /* Let the caller wait for activity. */ |
2482 | - client->state= GEARMAN_CLIENT_STATE_IDLE; |
2483 | + client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
2484 | |
2485 | - return gearman_gerror(client->universal, GEARMAN_IO_WAIT); |
2486 | + return gearman_gerror(client->impl()->universal, GEARMAN_IO_WAIT); |
2487 | } |
2488 | |
2489 | /* Wait for activity on one of the connections. */ |
2490 | - gearman_return_t local_ret= gearman_wait(client->universal); |
2491 | + gearman_return_t local_ret= gearman_wait(client->impl()->universal); |
2492 | if (gearman_failed(local_ret) and local_ret != GEARMAN_IO_WAIT) |
2493 | { |
2494 | - client->state= GEARMAN_CLIENT_STATE_IDLE; |
2495 | + client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
2496 | |
2497 | return local_ret; |
2498 | } |
2499 | @@ -1604,7 +1634,7 @@ |
2500 | break; |
2501 | } |
2502 | |
2503 | - client->state= GEARMAN_CLIENT_STATE_IDLE; |
2504 | + client->impl()->state= GEARMAN_CLIENT_STATE_IDLE; |
2505 | |
2506 | return GEARMAN_SUCCESS; |
2507 | } |
2508 | @@ -1616,7 +1646,7 @@ |
2509 | return GEARMAN_INVALID_ARGUMENT; |
2510 | } |
2511 | |
2512 | - if (client->task_list == NULL) // We are immediatly successful if all tasks are completed |
2513 | + if (client->impl()->task_list == NULL) // We are immediatly successful if all tasks are completed |
2514 | { |
2515 | return GEARMAN_SUCCESS; |
2516 | } |
2517 | @@ -1630,7 +1660,7 @@ |
2518 | |
2519 | if (rc == GEARMAN_COULD_NOT_CONNECT) |
2520 | { |
2521 | - gearman_reset(client->universal); |
2522 | + gearman_reset(client->impl()->universal); |
2523 | } |
2524 | |
2525 | return rc; |
2526 | @@ -1643,7 +1673,7 @@ |
2527 | return GEARMAN_INVALID_ARGUMENT; |
2528 | } |
2529 | |
2530 | - if (client->task_list == NULL) // We are immediatly successful if all tasks are completed |
2531 | + if (client->impl()->task_list == NULL) // We are immediatly successful if all tasks are completed |
2532 | { |
2533 | return GEARMAN_SUCCESS; |
2534 | } |
2535 | @@ -1660,12 +1690,12 @@ |
2536 | { |
2537 | if (rc == GEARMAN_COULD_NOT_CONNECT) |
2538 | { |
2539 | - gearman_reset(client->universal); |
2540 | + gearman_reset(client->impl()->universal); |
2541 | } |
2542 | |
2543 | - if (gearman_universal_error_code(client->universal) != rc and rc != GEARMAN_COULD_NOT_CONNECT) |
2544 | + if (client->impl()->universal.error_code() != rc and rc != GEARMAN_COULD_NOT_CONNECT) |
2545 | { |
2546 | - assert(gearman_universal_error_code(client->universal) == rc); |
2547 | + assert(client->impl()->universal.error_code() == rc); |
2548 | } |
2549 | } |
2550 | |
2551 | @@ -1678,22 +1708,20 @@ |
2552 | |
2553 | bool gearman_client_compare(const gearman_client_st *first, const gearman_client_st *second) |
2554 | { |
2555 | - if (first == NULL or second == NULL) |
2556 | - { |
2557 | - return false; |
2558 | - } |
2559 | - |
2560 | - if (strcmp(first->universal.con_list->host, second->universal.con_list->host)) |
2561 | - { |
2562 | - return false; |
2563 | - } |
2564 | - |
2565 | - if (first->universal.con_list->port != second->universal.con_list->port) |
2566 | - { |
2567 | - return false; |
2568 | - } |
2569 | - |
2570 | - return true; |
2571 | + if (first and second) |
2572 | + { |
2573 | + if (strcmp(first->impl()->universal.con_list->_host, second->impl()->universal.con_list->_host) == 0) |
2574 | + { |
2575 | + if (strcmp(first->impl()->universal.con_list->_service, second->impl()->universal.con_list->_service) == 0) |
2576 | + { |
2577 | + return true; |
2578 | + } |
2579 | + fprintf(stderr, "Compared %s != %s\n", first->impl()->universal.con_list->_service, second->impl()->universal.con_list->_service); |
2580 | + } |
2581 | + fprintf(stderr, "Compared %s != %s\n", first->impl()->universal.con_list->_host, second->impl()->universal.con_list->_host); |
2582 | + } |
2583 | + |
2584 | + return false; |
2585 | } |
2586 | |
2587 | bool gearman_client_set_server_option(gearman_client_st *self, const char *option_arg, size_t option_arg_size) |
2588 | @@ -1701,7 +1729,7 @@ |
2589 | if (self) |
2590 | { |
2591 | gearman_string_t option= { option_arg, option_arg_size }; |
2592 | - return gearman_request_option(self->universal, option); |
2593 | + return gearman_request_option(self->impl()->universal, option); |
2594 | } |
2595 | |
2596 | return false; |
2597 | @@ -1711,17 +1739,27 @@ |
2598 | { |
2599 | if (self) |
2600 | { |
2601 | - gearman_universal_set_namespace(self->universal, namespace_key, namespace_key_size); |
2602 | + gearman_universal_set_namespace(self->impl()->universal, namespace_key, namespace_key_size); |
2603 | } |
2604 | } |
2605 | |
2606 | gearman_return_t gearman_client_set_identifier(gearman_client_st *client, |
2607 | const char *id, size_t id_size) |
2608 | { |
2609 | - return gearman_set_identifier(client->universal, id, id_size); |
2610 | + return gearman_set_identifier(client->impl()->universal, id, id_size); |
2611 | } |
2612 | |
2613 | const char *gearman_client_namespace(gearman_client_st *self) |
2614 | { |
2615 | - return gearman_univeral_namespace(self->universal); |
2616 | + return gearman_univeral_namespace(self->impl()->universal); |
2617 | +} |
2618 | + |
2619 | +bool gearman_client_has_tasks(const gearman_client_st *client_shell) |
2620 | +{ |
2621 | + if (client_shell and client_shell->impl()) |
2622 | + { |
2623 | + return bool(client_shell->impl()->task_list); |
2624 | + } |
2625 | + |
2626 | + return false; |
2627 | } |
2628 | |
2629 | === modified file 'libgearman/common.h' |
2630 | --- libgearman/common.h 2012-08-02 05:44:19 +0000 |
2631 | +++ libgearman/common.h 2012-09-20 02:21:22 +0000 |
2632 | @@ -39,7 +39,13 @@ |
2633 | |
2634 | #pragma once |
2635 | |
2636 | +struct Client; |
2637 | +struct Task; |
2638 | +struct Worker; |
2639 | +struct gearman_client_st; |
2640 | +struct gearman_connection_st; |
2641 | struct gearman_result_st; |
2642 | +struct gearman_universal_st; |
2643 | |
2644 | #include <libgearman-1.0/gearman.h> |
2645 | |
2646 | @@ -65,7 +71,11 @@ |
2647 | #include <libgearman/command.h> |
2648 | #include <libgearman/task.hpp> |
2649 | #include <libgearman/job.h> |
2650 | +#include <libgearman/job.hpp> |
2651 | |
2652 | #include <libgearman/status.hpp> |
2653 | |
2654 | #include <libgearman/protocol/submit.h> |
2655 | +#include <libgearman/interface/client.hpp> |
2656 | +#include <libgearman/interface/task.hpp> |
2657 | +#include <libgearman/interface/worker.hpp> |
2658 | |
2659 | === modified file 'libgearman/connection.cc' |
2660 | --- libgearman/connection.cc 2012-09-16 00:30:28 +0000 |
2661 | +++ libgearman/connection.cc 2012-09-20 02:21:22 +0000 |
2662 | @@ -170,7 +170,6 @@ |
2663 | state(GEARMAN_CON_UNIVERSAL_ADDRINFO), |
2664 | send_state(GEARMAN_CON_SEND_STATE_NONE), |
2665 | recv_state(GEARMAN_CON_RECV_UNIVERSAL_NONE), |
2666 | - port(0), |
2667 | events(0), |
2668 | revents(0), |
2669 | fd(-1), |
2670 | @@ -214,7 +213,8 @@ |
2671 | |
2672 | send_buffer_ptr= send_buffer; |
2673 | recv_buffer_ptr= recv_buffer; |
2674 | - host[0]= 0; |
2675 | + _host[0]= 0; |
2676 | + _service[0]= 0; |
2677 | } |
2678 | |
2679 | gearman_connection_st *gearman_connection_create(gearman_universal_st &universal, |
2680 | @@ -231,9 +231,30 @@ |
2681 | } |
2682 | |
2683 | gearman_connection_st *gearman_connection_create_args(gearman_universal_st& universal, |
2684 | + const char *host, const char* service_) |
2685 | +{ |
2686 | + gearman_connection_st *connection= gearman_connection_create(universal); |
2687 | + if (connection == NULL) |
2688 | + { |
2689 | + return NULL; |
2690 | + } |
2691 | + |
2692 | + connection->set_host(host, service_); |
2693 | + |
2694 | + if (gearman_failed(connection->lookup())) |
2695 | + { |
2696 | + gearman_gerror(universal, GEARMAN_GETADDRINFO); |
2697 | + delete connection; |
2698 | + return NULL; |
2699 | + } |
2700 | + |
2701 | + return connection; |
2702 | +} |
2703 | + |
2704 | +gearman_connection_st *gearman_connection_create_args(gearman_universal_st& universal, |
2705 | const char *host, in_port_t port) |
2706 | { |
2707 | - gearman_connection_st *connection= gearman_connection_create(universal, NULL); |
2708 | + gearman_connection_st *connection= gearman_connection_create(universal); |
2709 | if (connection == NULL) |
2710 | { |
2711 | return NULL; |
2712 | @@ -254,7 +275,7 @@ |
2713 | gearman_connection_st *gearman_connection_copy(gearman_universal_st& universal, |
2714 | const gearman_connection_st& from) |
2715 | { |
2716 | - gearman_connection_st *connection= gearman_connection_create(universal, NULL); |
2717 | + gearman_connection_st *connection= gearman_connection_create(universal); |
2718 | |
2719 | if (connection == NULL) |
2720 | { |
2721 | @@ -265,8 +286,8 @@ |
2722 | // @todo Is this right? |
2723 | connection->options.packet_in_use= from.options.packet_in_use; |
2724 | |
2725 | - strcpy(connection->host, from.host); |
2726 | - connection->port= from.port; |
2727 | + strcpy(connection->_host, from._host); |
2728 | + strcpy(connection->_service, from._service); |
2729 | |
2730 | return connection; |
2731 | } |
2732 | @@ -355,10 +376,31 @@ |
2733 | { |
2734 | reset_addrinfo(); |
2735 | |
2736 | - strncpy(host, host_arg == NULL ? GEARMAN_DEFAULT_TCP_HOST : host_arg, GEARMAN_NI_MAXHOST); |
2737 | - host[GEARMAN_NI_MAXHOST - 1]= 0; |
2738 | - |
2739 | - port= in_port_t(port_arg == 0 ? GEARMAN_DEFAULT_TCP_PORT : port_arg); |
2740 | + strncpy(_host, host_arg == NULL ? GEARMAN_DEFAULT_TCP_HOST : host_arg, GEARMAN_NI_MAXHOST); |
2741 | + _host[GEARMAN_NI_MAXHOST - 1]= 0; |
2742 | + |
2743 | + in_port_t port= in_port_t(port_arg == 0 ? GEARMAN_DEFAULT_TCP_PORT : port_arg); |
2744 | + |
2745 | + snprintf(_service, sizeof(_service), "%hu", uint16_t(port)); |
2746 | + _service[GEARMAN_NI_MAXSERV - 1]= 0; |
2747 | +} |
2748 | + |
2749 | +void gearman_connection_st::set_host(const char *host_arg, const char* service_) |
2750 | +{ |
2751 | + reset_addrinfo(); |
2752 | + |
2753 | + strncpy(_host, host_arg == NULL ? GEARMAN_DEFAULT_TCP_HOST : host_arg, GEARMAN_NI_MAXHOST); |
2754 | + _host[GEARMAN_NI_MAXHOST - 1]= 0; |
2755 | + |
2756 | + if (service_) |
2757 | + { |
2758 | + strcpy(_service, service_); |
2759 | + } |
2760 | + else |
2761 | + { |
2762 | + strcpy(_service, GEARMAN_DEFAULT_TCP_PORT_STRING); |
2763 | + } |
2764 | + _service[GEARMAN_NI_MAXSERV - 1]= 0; |
2765 | } |
2766 | |
2767 | /* |
2768 | @@ -576,20 +618,13 @@ |
2769 | { |
2770 | reset_addrinfo(); |
2771 | |
2772 | - char port_str[GEARMAN_NI_MAXSERV]= { 0 }; |
2773 | - int port_str_length; |
2774 | - if (size_t(port_str_length= snprintf(port_str, sizeof(port_str), "%hu", uint16_t(port))) >= sizeof(port_str)) |
2775 | - { |
2776 | - return gearman_universal_set_error(universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, GEARMAN_AT, "snprintf(%d)", port_str_length); |
2777 | - } |
2778 | - |
2779 | struct addrinfo ai; |
2780 | memset(&ai, 0, sizeof(struct addrinfo)); |
2781 | ai.ai_socktype= SOCK_STREAM; |
2782 | ai.ai_protocol= IPPROTO_TCP; |
2783 | |
2784 | int ret; |
2785 | - if ((ret= getaddrinfo(host, port_str, &ai, &(_addrinfo)))) |
2786 | + if ((ret= getaddrinfo(_host, _service, &ai, &(_addrinfo)))) |
2787 | { |
2788 | reset_addrinfo(); |
2789 | return gearman_universal_set_error(universal, GEARMAN_GETADDRINFO, GEARMAN_AT, "getaddrinfo:%s", gai_strerror(ret)); |
2790 | @@ -627,7 +662,7 @@ |
2791 | if (addrinfo_next == NULL) |
2792 | { |
2793 | state= GEARMAN_CON_UNIVERSAL_ADDRINFO; |
2794 | - return gearman_universal_set_error(universal, GEARMAN_COULD_NOT_CONNECT, GEARMAN_AT, "%s:%hu", host, uint16_t(port)); |
2795 | + return gearman_universal_set_error(universal, GEARMAN_COULD_NOT_CONNECT, GEARMAN_AT, "%s:%s", _host, _service); |
2796 | } |
2797 | |
2798 | // rewrite tye if HAVE_SOCK_CLOEXEC |
2799 | @@ -686,7 +721,7 @@ |
2800 | gearman_return_t gret= connect_poll(); |
2801 | if (gearman_failed(gret)) |
2802 | { |
2803 | - assert_msg(universal.error.rc != GEARMAN_SUCCESS, "Programmer error, connect_poll() returned an error, but it was not set"); |
2804 | + assert_msg(universal.error_code() != GEARMAN_SUCCESS, "Programmer error, connect_poll() returned an error, but it was not set"); |
2805 | close_socket(); |
2806 | return gret; |
2807 | } |
2808 | @@ -729,7 +764,7 @@ |
2809 | |
2810 | set_events(POLLOUT); |
2811 | |
2812 | - if (gearman_universal_is_non_blocking(universal)) |
2813 | + if (universal.is_non_blocking()) |
2814 | { |
2815 | state= GEARMAN_CON_UNIVERSAL_CONNECTING; |
2816 | return gearman_gerror(universal, GEARMAN_IO_WAIT); |
2817 | @@ -751,7 +786,7 @@ |
2818 | while (send_buffer_size != 0) |
2819 | { |
2820 | ssize_t write_size= ::send(fd, send_buffer_ptr, send_buffer_size, |
2821 | - gearman_universal_is_non_blocking(universal) ? MSG_NOSIGNAL| MSG_DONTWAIT : MSG_NOSIGNAL); |
2822 | + universal.is_non_blocking() ? MSG_NOSIGNAL| MSG_DONTWAIT : MSG_NOSIGNAL); |
2823 | |
2824 | if (write_size == 0) // Zero value on send() |
2825 | { } |
2826 | @@ -761,7 +796,7 @@ |
2827 | { |
2828 | set_events(POLLOUT); |
2829 | |
2830 | - if (gearman_universal_is_non_blocking(universal)) |
2831 | + if (universal.is_non_blocking()) |
2832 | { |
2833 | return gearman_gerror(universal, GEARMAN_IO_WAIT); |
2834 | } |
2835 | @@ -1003,7 +1038,7 @@ |
2836 | { |
2837 | set_events(POLLIN); |
2838 | |
2839 | - if (gearman_universal_is_non_blocking(universal)) |
2840 | + if (universal.is_non_blocking()) |
2841 | { |
2842 | ret= gearman_gerror(universal, GEARMAN_IO_WAIT); |
2843 | return 0; |
2844 | |
2845 | === modified file 'libgearman/connection.hpp' |
2846 | --- libgearman/connection.hpp 2012-09-10 11:34:03 +0000 |
2847 | +++ libgearman/connection.hpp 2012-09-20 02:21:22 +0000 |
2848 | @@ -39,6 +39,8 @@ |
2849 | #pragma once |
2850 | |
2851 | #include <libgearman-1.0/connection.h> |
2852 | +#include "libgearman/interface/packet.hpp" |
2853 | +#include "libgearman/interface/universal.hpp" |
2854 | |
2855 | struct gearman_connection_st |
2856 | { |
2857 | @@ -49,7 +51,6 @@ |
2858 | enum gearman_con_universal_t state; |
2859 | enum gearman_con_send_t send_state; |
2860 | enum gearman_con_recv_t recv_state; |
2861 | - in_port_t port; |
2862 | short events; |
2863 | short revents; |
2864 | int fd; |
2865 | @@ -73,7 +74,8 @@ |
2866 | const char *send_buffer_ptr; |
2867 | char *recv_buffer_ptr; |
2868 | gearman_packet_st _packet; |
2869 | - char host[GEARMAN_NI_MAXHOST]; |
2870 | + char _host[GEARMAN_NI_MAXHOST]; |
2871 | + char _service[GEARMAN_NI_MAXSERV]; |
2872 | char send_buffer[GEARMAN_SEND_BUFFER_SIZE]; |
2873 | char recv_buffer[GEARMAN_RECV_BUFFER_SIZE]; |
2874 | |
2875 | @@ -85,6 +87,7 @@ |
2876 | ~gearman_connection_st(); |
2877 | |
2878 | void set_host( const char *host, const in_port_t port); |
2879 | + void set_host( const char *host, const char* service); |
2880 | |
2881 | gearman_return_t send_packet(const gearman_packet_st&, const bool flush_buffer); |
2882 | size_t send_and_flush(const void *data, size_t data_size, gearman_return_t *ret_ptr); |
2883 | @@ -133,11 +136,9 @@ |
2884 | * failed. |
2885 | */ |
2886 | |
2887 | -GEARMAN_LOCAL |
2888 | gearman_connection_st *gearman_connection_create(gearman_universal_st &universal, |
2889 | - gearman_connection_options_t *options); |
2890 | + gearman_connection_options_t *options= NULL); |
2891 | |
2892 | -GEARMAN_LOCAL |
2893 | gearman_connection_st *gearman_connection_copy(gearman_universal_st& universal, |
2894 | const gearman_connection_st& from); |
2895 | |
2896 | @@ -152,6 +153,8 @@ |
2897 | * @return On success, a pointer to the (possibly allocated) structure. On |
2898 | * failure this will be NULL. |
2899 | */ |
2900 | -GEARMAN_LOCAL |
2901 | gearman_connection_st *gearman_connection_create_args(gearman_universal_st &universal, |
2902 | const char *host, in_port_t port); |
2903 | + |
2904 | +gearman_connection_st *gearman_connection_create_args(gearman_universal_st &universal, |
2905 | + const char* host, const char* service); |
2906 | |
2907 | === modified file 'libgearman/do.cc' |
2908 | --- libgearman/do.cc 2012-08-02 05:44:19 +0000 |
2909 | +++ libgearman/do.cc 2012-09-20 02:21:22 +0000 |
2910 | @@ -77,16 +77,20 @@ |
2911 | return NULL; |
2912 | } |
2913 | |
2914 | - gearman_task_st *do_task_ptr= add_task(*client, &do_task, NULL, command, |
2915 | - function, |
2916 | - local_unique, |
2917 | - workload, |
2918 | - time_t(0), |
2919 | - gearman_actions_do_default()); |
2920 | - if (do_task_ptr == NULL) |
2921 | { |
2922 | - *ret_ptr= gearman_universal_error_code(client->universal); |
2923 | - return NULL; |
2924 | + gearman_task_st *do_task_ptr= add_task(*client, &do_task, NULL, command, |
2925 | + function, |
2926 | + local_unique, |
2927 | + workload, |
2928 | + time_t(0), |
2929 | + gearman_actions_do_default()); |
2930 | + if (do_task_ptr == NULL) |
2931 | + { |
2932 | + *ret_ptr= client->impl()->universal.error_code(); |
2933 | + return NULL; |
2934 | + } |
2935 | + assert(do_task_ptr); |
2936 | + assert(&do_task == do_task_ptr); |
2937 | } |
2938 | |
2939 | gearman_return_t ret= gearman_client_run_block_tasks(client); |
2940 | @@ -96,7 +100,7 @@ |
2941 | // gearman_client_run_block_tasks failed |
2942 | if (gearman_failed(ret)) |
2943 | { |
2944 | - gearman_error(client->universal, ret, "occured during gearman_client_run_tasks()"); |
2945 | + gearman_error(client->impl()->universal, ret, "occured during gearman_client_run_tasks()"); |
2946 | |
2947 | *ret_ptr= ret; |
2948 | *result_size= 0; |
2949 | @@ -104,12 +108,12 @@ |
2950 | else // Now we check the task itself |
2951 | { |
2952 | assert(ret == GEARMAN_SUCCESS); // Programmer mistake |
2953 | - if (gearman_success(do_task_ptr->result_rc)) |
2954 | + if (gearman_success(do_task.impl()->result_rc)) |
2955 | { |
2956 | - *ret_ptr= do_task_ptr->result_rc; |
2957 | - if (gearman_task_result(do_task_ptr)) |
2958 | + *ret_ptr= do_task.impl()->result_rc; |
2959 | + if (gearman_task_result(&do_task)) |
2960 | { |
2961 | - gearman_string_t result= gearman_result_take_string(do_task_ptr->result_ptr); |
2962 | + gearman_string_t result= gearman_result_take_string(do_task.impl()->result_ptr); |
2963 | *result_size= gearman_size(result); |
2964 | returnable= gearman_c_str(result); |
2965 | } |
2966 | @@ -118,17 +122,17 @@ |
2967 | } |
2968 | else // gearman_client_run_block_tasks() was successful, but the task was not |
2969 | { |
2970 | - gearman_error(client->universal, do_task_ptr->result_rc, "occured during gearman_client_run_tasks()"); |
2971 | + gearman_error(client->impl()->universal, do_task.impl()->result_rc, "occured during gearman_client_run_tasks()"); |
2972 | |
2973 | - *ret_ptr= do_task_ptr->result_rc; |
2974 | + *ret_ptr= do_task.impl()->result_rc; |
2975 | *result_size= 0; |
2976 | } |
2977 | } |
2978 | |
2979 | - assert(client->task_list); |
2980 | + assert(client->impl()->task_list); |
2981 | gearman_task_free(&do_task); |
2982 | - client->new_tasks= 0; |
2983 | - client->running_tasks= 0; |
2984 | + client->impl()->new_tasks= 0; |
2985 | + client->impl()->running_tasks= 0; |
2986 | |
2987 | return const_cast<void *>(returnable); |
2988 | } |
2989 | @@ -146,20 +150,23 @@ |
2990 | } |
2991 | |
2992 | gearman_task_st do_task; |
2993 | - gearman_task_st *do_task_ptr= add_task(*client, &do_task, |
2994 | - client, |
2995 | - command, |
2996 | - function, |
2997 | - unique, |
2998 | - workload, |
2999 | - time_t(0), |
3000 | - gearman_actions_do_default()); |
3001 | - if (do_task_ptr == NULL) |
3002 | { |
3003 | - return gearman_universal_error_code(client->universal); |
3004 | + gearman_task_st *do_task_ptr= add_task(*client, &do_task, |
3005 | + client, |
3006 | + command, |
3007 | + function, |
3008 | + unique, |
3009 | + workload, |
3010 | + time_t(0), |
3011 | + gearman_actions_do_default()); |
3012 | + if (do_task_ptr == NULL) |
3013 | + { |
3014 | + return client->impl()->universal.error_code(); |
3015 | + } |
3016 | + assert(&do_task == do_task_ptr); |
3017 | } |
3018 | |
3019 | - gearman_task_clear_fn(do_task_ptr); |
3020 | + gearman_task_clear_fn(&do_task); |
3021 | |
3022 | gearman_return_t ret= gearman_client_run_block_tasks(client); |
3023 | assert(ret != GEARMAN_IO_WAIT); |
3024 | @@ -167,10 +174,10 @@ |
3025 | { |
3026 | if (job_handle) |
3027 | { |
3028 | - strncpy(job_handle, do_task.job_handle, GEARMAN_JOB_HANDLE_SIZE); |
3029 | + strncpy(job_handle, do_task.impl()->job_handle, GEARMAN_JOB_HANDLE_SIZE); |
3030 | } |
3031 | - client->new_tasks= 0; |
3032 | - client->running_tasks= 0; |
3033 | + client->impl()->new_tasks= 0; |
3034 | + client->impl()->running_tasks= 0; |
3035 | } |
3036 | gearman_task_free(&do_task); |
3037 | |
3038 | |
3039 | === modified file 'libgearman/error.cc' |
3040 | --- libgearman/error.cc 2012-08-24 23:45:09 +0000 |
3041 | +++ libgearman/error.cc 2012-09-20 02:21:22 +0000 |
3042 | @@ -48,29 +48,29 @@ |
3043 | |
3044 | static void correct_from_errno(gearman_universal_st& universal) |
3045 | { |
3046 | - if (universal.error.rc == GEARMAN_ERRNO) |
3047 | + if (universal.error_code() == GEARMAN_ERRNO) |
3048 | { |
3049 | - switch (universal.error.last_errno) |
3050 | + switch (universal.last_errno()) |
3051 | { |
3052 | case EFAULT: |
3053 | case ENOMEM: |
3054 | - universal.error.rc= GEARMAN_MEMORY_ALLOCATION_FAILURE; |
3055 | + universal.error_code(GEARMAN_MEMORY_ALLOCATION_FAILURE); |
3056 | break; |
3057 | |
3058 | case EINVAL: |
3059 | - universal.error.rc= GEARMAN_INVALID_ARGUMENT; |
3060 | + universal.error_code(GEARMAN_INVALID_ARGUMENT); |
3061 | break; |
3062 | |
3063 | case ECONNRESET: |
3064 | case EHOSTDOWN: |
3065 | case EPIPE: |
3066 | - universal.error.rc= GEARMAN_LOST_CONNECTION; |
3067 | + universal.error_code(GEARMAN_LOST_CONNECTION); |
3068 | break; |
3069 | |
3070 | case ECONNREFUSED: |
3071 | case ENETUNREACH: |
3072 | case ETIMEDOUT: |
3073 | - universal.error.rc= GEARMAN_COULD_NOT_CONNECT; |
3074 | + universal.error_code(GEARMAN_COULD_NOT_CONNECT); |
3075 | break; |
3076 | |
3077 | default: |
3078 | @@ -79,17 +79,10 @@ |
3079 | } |
3080 | else |
3081 | { |
3082 | - universal.error.last_errno= 0; |
3083 | + universal.last_errno(0); |
3084 | } |
3085 | } |
3086 | |
3087 | -void universal_reset_error(gearman_universal_st& universal) |
3088 | -{ |
3089 | - universal.error.rc= GEARMAN_SUCCESS; |
3090 | - universal.error.last_errno= 0; |
3091 | - universal.error.last_error[0]= 0; |
3092 | -} |
3093 | - |
3094 | #pragma GCC diagnostic ignored "-Wformat-nonliteral" |
3095 | gearman_return_t gearman_universal_set_error(gearman_universal_st& universal, |
3096 | gearman_return_t rc, |
3097 | @@ -104,7 +97,7 @@ |
3098 | |
3099 | va_list args; |
3100 | |
3101 | - universal.error.rc= rc; |
3102 | + universal._error.rc= rc; |
3103 | correct_from_errno(universal); |
3104 | |
3105 | char last_error[GEARMAN_MAX_ERROR_SIZE]; |
3106 | @@ -116,24 +109,24 @@ |
3107 | { |
3108 | assert(length > int(GEARMAN_MAX_ERROR_SIZE)); |
3109 | assert(length < 0); |
3110 | - universal.error.last_error[GEARMAN_MAX_ERROR_SIZE -1]= 0; |
3111 | + universal._error.last_error[GEARMAN_MAX_ERROR_SIZE -1]= 0; |
3112 | } |
3113 | |
3114 | - length= snprintf(universal.error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) %s -> %s", function, gearman_strerror(universal.error.rc), last_error, position); |
3115 | + length= snprintf(universal._error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) %s -> %s", function, gearman_strerror(universal._error.rc), last_error, position); |
3116 | if (length > int(GEARMAN_MAX_ERROR_SIZE) or length < 0) |
3117 | { |
3118 | assert(length > int(GEARMAN_MAX_ERROR_SIZE)); |
3119 | assert(length < 0); |
3120 | - universal.error.last_error[GEARMAN_MAX_ERROR_SIZE -1]= 0; |
3121 | + universal._error.last_error[GEARMAN_MAX_ERROR_SIZE -1]= 0; |
3122 | } |
3123 | |
3124 | if (universal.log_fn) |
3125 | { |
3126 | - universal.log_fn(universal.error.last_error, GEARMAN_VERBOSE_FATAL, |
3127 | + universal.log_fn(universal._error.last_error, GEARMAN_VERBOSE_FATAL, |
3128 | static_cast<void *>(universal.log_context)); |
3129 | } |
3130 | |
3131 | - return universal.error.rc; |
3132 | + return universal._error.rc; |
3133 | } |
3134 | |
3135 | gearman_return_t gearman_universal_set_gerror(gearman_universal_st& universal, |
3136 | @@ -146,21 +139,21 @@ |
3137 | return rc; |
3138 | } |
3139 | |
3140 | - universal.error.rc= rc; |
3141 | + universal._error.rc= rc; |
3142 | correct_from_errno(universal); |
3143 | |
3144 | - int length= snprintf(universal.error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) -> %s", func, gearman_strerror(rc), position); |
3145 | + int length= snprintf(universal._error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) -> %s", func, gearman_strerror(rc), position); |
3146 | if (length > int(GEARMAN_MAX_ERROR_SIZE) or length < 0) |
3147 | { |
3148 | assert(length > int(GEARMAN_MAX_ERROR_SIZE)); |
3149 | assert(length < 0); |
3150 | - universal.error.last_error[GEARMAN_MAX_ERROR_SIZE -1]= 0; |
3151 | + universal._error.last_error[GEARMAN_MAX_ERROR_SIZE -1]= 0; |
3152 | return GEARMAN_ARGUMENT_TOO_LARGE; |
3153 | } |
3154 | |
3155 | if (universal.log_fn) |
3156 | { |
3157 | - universal.log_fn(universal.error.last_error, GEARMAN_VERBOSE_FATAL, |
3158 | + universal.log_fn(universal._error.last_error, GEARMAN_VERBOSE_FATAL, |
3159 | static_cast<void *>(universal.log_context)); |
3160 | } |
3161 | |
3162 | @@ -179,14 +172,14 @@ |
3163 | switch (errno) |
3164 | { |
3165 | case ENOMEM: |
3166 | - universal.error.rc= GEARMAN_MEMORY_ALLOCATION_FAILURE; |
3167 | + universal._error.rc= GEARMAN_MEMORY_ALLOCATION_FAILURE; |
3168 | break; |
3169 | |
3170 | default: |
3171 | - universal.error.rc= GEARMAN_ERRNO; |
3172 | + universal._error.rc= GEARMAN_ERRNO; |
3173 | break; |
3174 | } |
3175 | - universal.error.last_errno= errno; |
3176 | + universal._error.last_errno= errno; |
3177 | |
3178 | correct_from_errno(universal); |
3179 | |
3180 | @@ -195,34 +188,34 @@ |
3181 | errmsg[0]= 0; |
3182 | |
3183 | #ifdef STRERROR_R_CHAR_P |
3184 | - errmsg_ptr= strerror_r(universal.error.last_errno, errmsg, sizeof(errmsg)); |
3185 | + errmsg_ptr= strerror_r(universal._error.last_errno, errmsg, sizeof(errmsg)); |
3186 | #else |
3187 | - strerror_r(universal.error.last_errno, errmsg, sizeof(errmsg)); |
3188 | + strerror_r(universal._error.last_errno, errmsg, sizeof(errmsg)); |
3189 | errmsg_ptr= errmsg; |
3190 | #endif |
3191 | |
3192 | int length; |
3193 | if (message) |
3194 | { |
3195 | - length= snprintf(universal.error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) %s -> %s", function, errmsg_ptr, message, position); |
3196 | + length= snprintf(universal._error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) %s -> %s", function, errmsg_ptr, message, position); |
3197 | } |
3198 | else |
3199 | { |
3200 | - length= snprintf(universal.error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) -> %s", function, errmsg_ptr, position); |
3201 | + length= snprintf(universal._error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) -> %s", function, errmsg_ptr, position); |
3202 | } |
3203 | |
3204 | if (length > int(GEARMAN_MAX_ERROR_SIZE) or length < 0) |
3205 | { |
3206 | assert(length > int(GEARMAN_MAX_ERROR_SIZE)); |
3207 | assert(length < 0); |
3208 | - universal.error.last_error[GEARMAN_MAX_ERROR_SIZE -1]= 0; |
3209 | + universal._error.last_error[GEARMAN_MAX_ERROR_SIZE -1]= 0; |
3210 | } |
3211 | |
3212 | if (universal.log_fn) |
3213 | { |
3214 | - universal.log_fn(universal.error.last_error, GEARMAN_VERBOSE_FATAL, |
3215 | + universal.log_fn(universal._error.last_error, GEARMAN_VERBOSE_FATAL, |
3216 | static_cast<void *>(universal.log_context)); |
3217 | } |
3218 | |
3219 | - return universal.error.rc; |
3220 | + return universal._error.rc; |
3221 | } |
3222 | |
3223 | === modified file 'libgearman/error.hpp' |
3224 | --- libgearman/error.hpp 2012-09-16 00:30:28 +0000 |
3225 | +++ libgearman/error.hpp 2012-09-20 02:21:22 +0000 |
3226 | @@ -62,7 +62,10 @@ |
3227 | gearman_return_t rc, |
3228 | const char *func, |
3229 | const char *position); |
3230 | +<<<<<<< TREE |
3231 | |
3232 | void universal_reset_error(gearman_universal_st& universal); |
3233 | |
3234 | void gearman_worker_reset_error(gearman_worker_st *worker); |
3235 | +======= |
3236 | +>>>>>>> MERGE-SOURCE |
3237 | |
3238 | === modified file 'libgearman/execute.cc' |
3239 | --- libgearman/execute.cc 2012-08-02 05:44:19 +0000 |
3240 | +++ libgearman/execute.cc 2012-09-20 02:21:22 +0000 |
3241 | @@ -86,7 +86,7 @@ |
3242 | |
3243 | if (function_name == NULL or function_length == 0) |
3244 | { |
3245 | - gearman_error(client->universal, GEARMAN_INVALID_ARGUMENT, "function_name was NULL"); |
3246 | + gearman_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, "function_name was NULL"); |
3247 | return NULL; |
3248 | } |
3249 | gearman_string_t function= { function_name, function_length }; |
3250 | @@ -145,12 +145,12 @@ |
3251 | |
3252 | if (task == NULL) |
3253 | { |
3254 | - gearman_universal_error_code(client->universal); |
3255 | + gearman_universal_error_code(client->impl()->universal); |
3256 | |
3257 | return NULL; |
3258 | } |
3259 | |
3260 | - task->type= GEARMAN_TASK_KIND_EXECUTE; |
3261 | + task->impl()->type= GEARMAN_TASK_KIND_EXECUTE; |
3262 | gearman_client_run_tasks(client); |
3263 | |
3264 | return task; |
3265 | @@ -172,17 +172,17 @@ |
3266 | |
3267 | if ((partition_function == NULL) or (partition_function_length == 0)) |
3268 | { |
3269 | - gearman_error(client->universal, GEARMAN_INVALID_ARGUMENT, "function_name was NULL"); |
3270 | + gearman_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, "function_name was NULL"); |
3271 | return NULL; |
3272 | } |
3273 | |
3274 | if ((function_name == NULL) or (function_name_length == 0)) |
3275 | { |
3276 | - gearman_error(client->universal, GEARMAN_INVALID_ARGUMENT, "function_name was NULL"); |
3277 | + gearman_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, "function_name was NULL"); |
3278 | return NULL; |
3279 | } |
3280 | |
3281 | - universal_reset_error(client->universal); |
3282 | + universal_reset_error(client->impl()->universal); |
3283 | |
3284 | gearman_task_st *task= NULL; |
3285 | gearman_string_t partition= { partition_function, partition_function_length }; |
3286 | @@ -207,7 +207,7 @@ |
3287 | break; |
3288 | |
3289 | case GEARMAN_TASK_ATTR_EPOCH: |
3290 | - gearman_error(client->universal, GEARMAN_INVALID_ARGUMENT, "EPOCH is not currently supported for gearman_client_execute_reduce()"); |
3291 | + gearman_error(client->impl()->universal, GEARMAN_INVALID_ARGUMENT, "EPOCH is not currently supported for gearman_client_execute_reduce()"); |
3292 | return NULL; |
3293 | #if 0 |
3294 | task= add_task(client, |
3295 | @@ -260,7 +260,7 @@ |
3296 | gearman_return_t rc; |
3297 | if (gearman_failed(rc= gearman_client_run_tasks(client))) |
3298 | { |
3299 | - gearman_gerror(client->universal, rc); |
3300 | + gearman_gerror(client->impl()->universal, rc); |
3301 | gearman_task_free(task); |
3302 | return NULL; |
3303 | } |
3304 | |
3305 | === modified file 'libgearman/function/function_v1.hpp' |
3306 | --- libgearman/function/function_v1.hpp 2012-04-17 05:48:26 +0000 |
3307 | +++ libgearman/function/function_v1.hpp 2012-09-20 02:21:22 +0000 |
3308 | @@ -63,7 +63,7 @@ |
3309 | } |
3310 | |
3311 | job->error_code= GEARMAN_SUCCESS; |
3312 | - job->worker->work_result= _worker_fn(job, context_arg, &(job->worker->work_result_size), &job->error_code); |
3313 | + job->worker->impl()->work_result= _worker_fn(job, context_arg, &(job->worker->impl()->work_result_size), &job->error_code); |
3314 | |
3315 | if (job->error_code == GEARMAN_LOST_CONNECTION) |
3316 | { |
3317 | |
3318 | === modified file 'libgearman/include.am' |
3319 | --- libgearman/include.am 2012-08-16 10:51:22 +0000 |
3320 | +++ libgearman/include.am 2012-09-20 02:21:22 +0000 |
3321 | @@ -12,7 +12,14 @@ |
3322 | |
3323 | nobase_include_HEADERS+= libgearman/gearman.h |
3324 | |
3325 | +noinst_HEADERS+= libgearman/interface/packet.hpp |
3326 | +noinst_HEADERS+= libgearman/interface/universal.hpp |
3327 | +noinst_HEADERS+= libgearman/interface/client.hpp |
3328 | +noinst_HEADERS+= libgearman/interface/push.hpp |
3329 | +noinst_HEADERS+= libgearman/interface/task.hpp |
3330 | +noinst_HEADERS+= libgearman/interface/worker.hpp |
3331 | noinst_HEADERS+= libgearman/uuid.hpp |
3332 | +noinst_HEADERS+= libgearman/job.hpp |
3333 | noinst_HEADERS+= libgearman/job.h |
3334 | noinst_HEADERS+= libgearman/pipe.h |
3335 | noinst_HEADERS+= \ |
3336 | |
3337 | === added directory 'libgearman/interface' |
3338 | === added file 'libgearman/interface/client.hpp' |
3339 | --- libgearman/interface/client.hpp 1970-01-01 00:00:00 +0000 |
3340 | +++ libgearman/interface/client.hpp 2012-09-20 02:21:22 +0000 |
3341 | @@ -0,0 +1,118 @@ |
3342 | +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3343 | + * |
3344 | + * Gearmand client and server library. |
3345 | + * |
3346 | + * Copyright (C) 2012 Data Differential, http://datadifferential.com/ |
3347 | + * All rights reserved. |
3348 | + * |
3349 | + * Redistribution and use in source and binary forms, with or without |
3350 | + * modification, are permitted provided that the following conditions are |
3351 | + * met: |
3352 | + * |
3353 | + * * Redistributions of source code must retain the above copyright |
3354 | + * notice, this list of conditions and the following disclaimer. |
3355 | + * |
3356 | + * * Redistributions in binary form must reproduce the above |
3357 | + * copyright notice, this list of conditions and the following disclaimer |
3358 | + * in the documentation and/or other materials provided with the |
3359 | + * distribution. |
3360 | + * |
3361 | + * * The names of its contributors may not be used to endorse or |
3362 | + * promote products derived from this software without specific prior |
3363 | + * written permission. |
3364 | + * |
3365 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
3366 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
3367 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
3368 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
3369 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
3370 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
3371 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
3372 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
3373 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
3374 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
3375 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
3376 | + * |
3377 | + */ |
3378 | + |
3379 | +#pragma once |
3380 | + |
3381 | +#include "libgearman/actions.hpp" |
3382 | +#include "libgearman/interface/universal.hpp" |
3383 | +#include "libgearman/is.hpp" |
3384 | + |
3385 | +struct Client |
3386 | +{ |
3387 | + struct Options { |
3388 | + bool non_blocking; |
3389 | + bool unbuffered_result; |
3390 | + bool no_new; |
3391 | + bool free_tasks; |
3392 | + |
3393 | + Options(): |
3394 | + non_blocking(false), |
3395 | + unbuffered_result(false), |
3396 | + no_new(false), |
3397 | + free_tasks(false) |
3398 | + { |
3399 | + } |
3400 | + } options; |
3401 | + enum gearman_client_t state; |
3402 | + uint32_t new_tasks; |
3403 | + uint32_t running_tasks; |
3404 | + uint32_t task_count; |
3405 | + void *context; |
3406 | + struct gearman_connection_st *con; |
3407 | + gearman_task_st *task; |
3408 | + gearman_task_st *task_list; |
3409 | + gearman_task_context_free_fn *task_context_free_fn; |
3410 | + gearman_universal_st universal; |
3411 | + struct gearman_actions_t actions; |
3412 | + gearman_job_handle_t _do_handle; // Backwards compatible |
3413 | + |
3414 | + |
3415 | + Client(gearman_client_st* shell_) : |
3416 | + state(GEARMAN_CLIENT_STATE_IDLE), |
3417 | + new_tasks(0), |
3418 | + running_tasks(0), |
3419 | + task_count(0), |
3420 | + context(NULL), |
3421 | + con(NULL), |
3422 | + task(NULL), |
3423 | + task_list(NULL), |
3424 | + task_context_free_fn(NULL), |
3425 | + actions(gearman_actions_default()), |
3426 | + _shell(shell_) |
3427 | + { |
3428 | + _do_handle[0]= 0; |
3429 | + |
3430 | + if (shell_) |
3431 | + { |
3432 | + gearman_set_allocated(_shell, false); |
3433 | + } |
3434 | + else |
3435 | + { |
3436 | + _shell= &_owned_shell; |
3437 | + gearman_set_allocated(_shell, true); |
3438 | + } |
3439 | + |
3440 | + _shell->impl(this); |
3441 | + gearman_set_initialized(_shell, true); |
3442 | + } |
3443 | + |
3444 | + gearman_return_t add_server(const char *host, const char* service_); |
3445 | + |
3446 | + ~Client() |
3447 | + { |
3448 | + } |
3449 | + |
3450 | + gearman_client_st* shell() |
3451 | + { |
3452 | + return _shell; |
3453 | + } |
3454 | + |
3455 | +private: |
3456 | + gearman_client_st* _shell; |
3457 | + gearman_client_st _owned_shell; |
3458 | +}; |
3459 | + |
3460 | |
3461 | === renamed file 'libgearman-1.0/packet.h' => 'libgearman/interface/packet.hpp' |
3462 | --- libgearman-1.0/packet.h 2012-04-02 07:03:19 +0000 |
3463 | +++ libgearman/interface/packet.hpp 2012-09-20 02:21:22 +0000 |
3464 | @@ -2,7 +2,7 @@ |
3465 | * |
3466 | * Gearmand client and server library. |
3467 | * |
3468 | - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ |
3469 | + * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/ |
3470 | * Copyright (C) 2008 Brian Aker, Eric Day |
3471 | * All rights reserved. |
3472 | * |
3473 | @@ -45,22 +45,30 @@ |
3474 | GEARMAN_MAGIC_RESPONSE |
3475 | }; |
3476 | |
3477 | +struct gearman_universal_st; |
3478 | + |
3479 | /** |
3480 | * @ingroup gearman_packet |
3481 | */ |
3482 | struct gearman_packet_st |
3483 | { |
3484 | - struct { |
3485 | - bool allocated; |
3486 | + struct Options { |
3487 | + bool is_allocated; |
3488 | bool complete; |
3489 | bool free_data; |
3490 | + |
3491 | + Options() : |
3492 | + is_allocated(false), |
3493 | + complete(false), |
3494 | + free_data(false) |
3495 | + { } |
3496 | } options; |
3497 | enum gearman_magic_t magic; |
3498 | gearman_command_t command; |
3499 | uint8_t argc; |
3500 | size_t args_size; |
3501 | size_t data_size; |
3502 | - struct gearman_universal_st *universal; |
3503 | + gearman_universal_st *universal; |
3504 | gearman_packet_st *next; |
3505 | gearman_packet_st *prev; |
3506 | char *args; |
3507 | @@ -71,4 +79,18 @@ |
3508 | #ifdef GEARMAN_PACKET_TRACE |
3509 | uint32_t _id; |
3510 | #endif |
3511 | + |
3512 | + gearman_packet_st() : |
3513 | + magic(GEARMAN_MAGIC_TEXT), |
3514 | + command(GEARMAN_COMMAND_TEXT), |
3515 | + argc(0), |
3516 | + args_size(0), |
3517 | + data_size(0), |
3518 | + universal(0), |
3519 | + next(0), |
3520 | + prev(0), |
3521 | + args(0), |
3522 | + data(0) |
3523 | + { |
3524 | + } |
3525 | }; |
3526 | |
3527 | === added file 'libgearman/interface/push.hpp' |
3528 | --- libgearman/interface/push.hpp 1970-01-01 00:00:00 +0000 |
3529 | +++ libgearman/interface/push.hpp 2012-09-20 02:21:22 +0000 |
3530 | @@ -0,0 +1,102 @@ |
3531 | +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3532 | + * |
3533 | + * Gearmand client and server library. |
3534 | + * |
3535 | + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ |
3536 | + * Copyright (C) 2008 Brian Aker, Eric Day |
3537 | + * All rights reserved. |
3538 | + * |
3539 | + * Redistribution and use in source and binary forms, with or without |
3540 | + * modification, are permitted provided that the following conditions are |
3541 | + * met: |
3542 | + * |
3543 | + * * Redistributions of source code must retain the above copyright |
3544 | + * notice, this list of conditions and the following disclaimer. |
3545 | + * |
3546 | + * * Redistributions in binary form must reproduce the above |
3547 | + * copyright notice, this list of conditions and the following disclaimer |
3548 | + * in the documentation and/or other materials provided with the |
3549 | + * distribution. |
3550 | + * |
3551 | + * * The names of its contributors may not be used to endorse or |
3552 | + * promote products derived from this software without specific prior |
3553 | + * written permission. |
3554 | + * |
3555 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
3556 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
3557 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
3558 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
3559 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
3560 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
3561 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
3562 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
3563 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
3564 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
3565 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
3566 | + * |
3567 | + */ |
3568 | + |
3569 | +#pragma once |
3570 | + |
3571 | +#include "libgearman/interface/client.hpp" |
3572 | +#include "libgearman/interface/universal.hpp" |
3573 | + |
3574 | +/** |
3575 | + Push the state of IO |
3576 | +*/ |
3577 | +class PushBlocking { |
3578 | +public: |
3579 | + PushBlocking(gearman_universal_st& arg) : |
3580 | + _original(arg.options.non_blocking), |
3581 | + _universal(arg) |
3582 | + { |
3583 | + _universal.non_blocking(false); |
3584 | + } |
3585 | + |
3586 | + PushBlocking(gearman_client_st* client_shell) : |
3587 | + _original(client_shell->impl()->universal.is_non_blocking()), |
3588 | + _universal(client_shell->impl()->universal) |
3589 | + { |
3590 | + _universal.non_blocking(false); |
3591 | + } |
3592 | + |
3593 | + ~PushBlocking() |
3594 | + { |
3595 | + _universal.non_blocking(_original); |
3596 | + } |
3597 | + |
3598 | +private: |
3599 | + bool _original; |
3600 | + gearman_universal_st& _universal; |
3601 | +}; |
3602 | + |
3603 | +#define PUSH_BLOCKING(__univeral) PushBlocking _push_block((__univeral)); |
3604 | + |
3605 | +class PushNonBlocking { |
3606 | +public: |
3607 | + PushNonBlocking(gearman_universal_st& arg) : |
3608 | + _original(arg.options.non_blocking), |
3609 | + _universal(arg) |
3610 | + { |
3611 | + _universal.non_blocking(true); |
3612 | + } |
3613 | + |
3614 | + PushNonBlocking(gearman_client_st* client_shell) : |
3615 | + _original(client_shell->impl()->universal.options.non_blocking), |
3616 | + _universal(client_shell->impl()->universal) |
3617 | + { |
3618 | + _universal.non_blocking(true); |
3619 | + } |
3620 | + |
3621 | + ~PushNonBlocking() |
3622 | + { |
3623 | + _universal.non_blocking(_original); |
3624 | + } |
3625 | + |
3626 | +private: |
3627 | + bool _original; |
3628 | + gearman_universal_st& _universal; |
3629 | +}; |
3630 | + |
3631 | +#define PUSH_NON_BLOCKING(__univeral) PushNonBlocking _push_block((__univeral)); |
3632 | + |
3633 | |
3634 | === added file 'libgearman/interface/task.hpp' |
3635 | --- libgearman/interface/task.hpp 1970-01-01 00:00:00 +0000 |
3636 | +++ libgearman/interface/task.hpp 2012-09-20 02:21:22 +0000 |
3637 | @@ -0,0 +1,143 @@ |
3638 | +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3639 | + * |
3640 | + * Gearmand client and server library. |
3641 | + * |
3642 | + * Copyright (C) 2012 Data Differential, http://datadifferential.com/ |
3643 | + * All rights reserved. |
3644 | + * |
3645 | + * Redistribution and use in source and binary forms, with or without |
3646 | + * modification, are permitted provided that the following conditions are |
3647 | + * met: |
3648 | + * |
3649 | + * * Redistributions of source code must retain the above copyright |
3650 | + * notice, this list of conditions and the following disclaimer. |
3651 | + * |
3652 | + * * Redistributions in binary form must reproduce the above |
3653 | + * copyright notice, this list of conditions and the following disclaimer |
3654 | + * in the documentation and/or other materials provided with the |
3655 | + * distribution. |
3656 | + * |
3657 | + * * The names of its contributors may not be used to endorse or |
3658 | + * promote products derived from this software without specific prior |
3659 | + * written permission. |
3660 | + * |
3661 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
3662 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
3663 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
3664 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
3665 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
3666 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
3667 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
3668 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
3669 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
3670 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
3671 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
3672 | + * |
3673 | + */ |
3674 | + |
3675 | +#pragma once |
3676 | + |
3677 | +#include "libgearman/interface/client.hpp" |
3678 | +#include "libgearman/interface/packet.hpp" |
3679 | + |
3680 | +#define TASK_MAGIC 134 |
3681 | +#define TASK_ANTI_MAGIC 157 |
3682 | + |
3683 | +struct Task |
3684 | +{ |
3685 | + struct Options { |
3686 | + bool send_in_use; |
3687 | + bool is_known; |
3688 | + bool is_running; |
3689 | + bool was_reduced; |
3690 | + bool is_paused; |
3691 | + bool is_initialized; |
3692 | + |
3693 | + Options() : |
3694 | + send_in_use(false), |
3695 | + is_known(false), |
3696 | + is_running(false), |
3697 | + was_reduced(false), |
3698 | + is_paused(false), |
3699 | + is_initialized(true) |
3700 | + { } |
3701 | + } options; |
3702 | + enum gearman_task_kind_t type; |
3703 | + enum gearman_task_state_t state; |
3704 | + uint32_t magic_; |
3705 | + uint32_t created_id; |
3706 | + uint32_t numerator; |
3707 | + uint32_t denominator; |
3708 | + uint32_t client_count; |
3709 | + gearman_client_st *client; |
3710 | + gearman_task_st *next; |
3711 | + gearman_task_st *prev; |
3712 | + void *context; |
3713 | + gearman_connection_st *con; |
3714 | + gearman_packet_st *recv; |
3715 | + gearman_packet_st send; |
3716 | + struct gearman_actions_t func; |
3717 | + gearman_return_t result_rc; |
3718 | + struct gearman_result_st *result_ptr; |
3719 | + char job_handle[GEARMAN_JOB_HANDLE_SIZE]; |
3720 | + size_t unique_length; |
3721 | + char unique[GEARMAN_MAX_UNIQUE_SIZE]; |
3722 | + |
3723 | + gearman_task_st* shell() |
3724 | + { |
3725 | + return _shell; |
3726 | + } |
3727 | + |
3728 | + Task(gearman_client_st& client_, gearman_task_st* shell_) : |
3729 | + type(GEARMAN_TASK_KIND_ADD_TASK), |
3730 | + state(GEARMAN_TASK_STATE_NEW), |
3731 | + magic_(TASK_MAGIC), |
3732 | + created_id(0), |
3733 | + numerator(0), |
3734 | + denominator(0), |
3735 | + client_count(0), |
3736 | + client(&client_), |
3737 | + next(NULL), |
3738 | + prev(NULL), |
3739 | + context(NULL), |
3740 | + con(NULL), |
3741 | + recv(NULL), |
3742 | + func(client_.impl()->actions), |
3743 | + result_rc(GEARMAN_UNKNOWN_STATE), |
3744 | + result_ptr(NULL), |
3745 | + unique_length(0), |
3746 | + _shell(shell_) |
3747 | + { |
3748 | + job_handle[0]= 0; |
3749 | + unique[0]= 0; |
3750 | + |
3751 | + if (_shell) |
3752 | + { |
3753 | + gearman_set_allocated(_shell, false); |
3754 | + } |
3755 | + else |
3756 | + { |
3757 | + _shell= &_owned_shell; |
3758 | + gearman_set_allocated(_shell, true); |
3759 | + } |
3760 | + gearman_set_initialized(_shell, true); |
3761 | + |
3762 | + // Add the task to the client |
3763 | + { |
3764 | + if (client_.impl()->task_list) |
3765 | + { |
3766 | + client_.impl()->task_list->impl()->prev= _shell; |
3767 | + } |
3768 | + next= client_.impl()->task_list; |
3769 | + prev= NULL; |
3770 | + client_.impl()->task_list= _shell; |
3771 | + client_.impl()->task_count++; |
3772 | + } |
3773 | + |
3774 | + _shell->impl(this); |
3775 | + } |
3776 | + |
3777 | +private: |
3778 | + gearman_task_st* _shell; |
3779 | + gearman_task_st _owned_shell; |
3780 | +}; |
3781 | |
3782 | === renamed file 'libgearman-1.0/universal.h' => 'libgearman/interface/universal.hpp' |
3783 | --- libgearman-1.0/universal.h 2012-05-27 02:15:15 +0000 |
3784 | +++ libgearman/interface/universal.hpp 2012-09-20 02:21:22 +0000 |
3785 | @@ -38,7 +38,7 @@ |
3786 | |
3787 | #pragma once |
3788 | |
3789 | -#include <libgearman-1.0/allocator.h> |
3790 | +#include "libgearman/allocator.hpp" |
3791 | |
3792 | /** |
3793 | @todo this is only used by the server and should be made private. |
3794 | @@ -47,14 +47,16 @@ |
3795 | typedef gearman_return_t (gearman_event_watch_fn)(gearman_connection_st *con, |
3796 | short events, void *context); |
3797 | |
3798 | -/** |
3799 | - * @ingroup gearman_universal |
3800 | - */ |
3801 | struct gearman_universal_st |
3802 | { |
3803 | - struct { |
3804 | + struct Options { |
3805 | bool dont_track_packets; |
3806 | bool non_blocking; |
3807 | + |
3808 | + Options() : |
3809 | + dont_track_packets(false), |
3810 | + non_blocking(false) |
3811 | + { } |
3812 | } options; |
3813 | gearman_verbose_t verbose; |
3814 | uint32_t con_count; |
3815 | @@ -63,16 +65,146 @@ |
3816 | uint32_t sending; |
3817 | int timeout; // Used by poll() |
3818 | gearman_connection_st *con_list; |
3819 | - gearman_packet_st *packet_list; |
3820 | + struct gearman_packet_st *packet_list; |
3821 | struct pollfd *pfds; |
3822 | gearman_log_fn *log_fn; |
3823 | void *log_context; |
3824 | gearman_allocator_t allocator; |
3825 | struct gearman_vector_st *_namespace; |
3826 | - struct { |
3827 | + struct error_st { |
3828 | gearman_return_t rc; |
3829 | int last_errno; |
3830 | char last_error[GEARMAN_MAX_ERROR_SIZE]; |
3831 | - } error; |
3832 | + |
3833 | + error_st(): |
3834 | + rc(GEARMAN_SUCCESS), |
3835 | + last_errno(0) |
3836 | + { |
3837 | + last_error[0]= 0; |
3838 | + } |
3839 | + |
3840 | + } _error; |
3841 | int wakeup_fd[2]; |
3842 | + |
3843 | + bool is_non_blocking() const |
3844 | + { |
3845 | + return options.non_blocking; |
3846 | + } |
3847 | + |
3848 | + void non_blocking(bool arg_) |
3849 | + { |
3850 | + options.non_blocking= arg_; |
3851 | + } |
3852 | + |
3853 | + const char *error() const |
3854 | + { |
3855 | + if (_error.last_error[0] == 0) |
3856 | + { |
3857 | + return NULL; |
3858 | + } |
3859 | + |
3860 | + return static_cast<const char *>(_error.last_error); |
3861 | + } |
3862 | + |
3863 | + gearman_return_t error_code() const |
3864 | + { |
3865 | + return _error.rc; |
3866 | + } |
3867 | + |
3868 | + void error_code(gearman_return_t rc) |
3869 | + { |
3870 | + _error.rc= rc; |
3871 | + } |
3872 | + |
3873 | + int last_errno() const |
3874 | + { |
3875 | + return _error.last_errno; |
3876 | + } |
3877 | + |
3878 | + void last_errno(int last_errno_) |
3879 | + { |
3880 | + _error.last_errno= last_errno_; |
3881 | + } |
3882 | + |
3883 | + void reset_error() |
3884 | + { |
3885 | + _error.rc= GEARMAN_SUCCESS; |
3886 | + _error.last_errno= 0; |
3887 | + _error.last_error[0]= 0; |
3888 | + } |
3889 | + |
3890 | + gearman_return_t option(gearman_universal_options_t option_, bool value) |
3891 | + { |
3892 | + switch (option_) |
3893 | + { |
3894 | + case GEARMAN_NON_BLOCKING: |
3895 | + non_blocking(value); |
3896 | + break; |
3897 | + |
3898 | + case GEARMAN_DONT_TRACK_PACKETS: |
3899 | + break; |
3900 | + |
3901 | + case GEARMAN_MAX: |
3902 | + default: |
3903 | + return GEARMAN_INVALID_COMMAND; |
3904 | + } |
3905 | + |
3906 | + return GEARMAN_SUCCESS; |
3907 | + } |
3908 | + |
3909 | + gearman_universal_st(const gearman_universal_options_t *options_= NULL) : |
3910 | + verbose(GEARMAN_VERBOSE_NEVER), |
3911 | + con_count(0), |
3912 | + packet_count(0), |
3913 | + pfds_size(0), |
3914 | + sending(0), |
3915 | + timeout(-1), |
3916 | + con_list(NULL), |
3917 | + packet_list(NULL), |
3918 | + pfds(NULL), |
3919 | + log_fn(NULL), |
3920 | + log_context(NULL), |
3921 | + allocator(gearman_default_allocator()), |
3922 | + _namespace(NULL) |
3923 | + { |
3924 | + wakeup_fd[0]= INVALID_SOCKET; |
3925 | + wakeup_fd[1]= INVALID_SOCKET; |
3926 | + |
3927 | + if (options_) |
3928 | + { |
3929 | + while (*options_ != GEARMAN_MAX) |
3930 | + { |
3931 | + /** |
3932 | + @note Check for bad value, refactor gearman_add_options(). |
3933 | + */ |
3934 | + (void)option(*options_, true); |
3935 | + options_++; |
3936 | + } |
3937 | + } |
3938 | + } |
3939 | }; |
3940 | + |
3941 | +static inline bool gearman_universal_is_non_blocking(gearman_universal_st &self) |
3942 | +{ |
3943 | + return self.is_non_blocking(); |
3944 | +} |
3945 | + |
3946 | +static inline const char *gearman_universal_error(const gearman_universal_st &self) |
3947 | +{ |
3948 | + return self.error(); |
3949 | +} |
3950 | + |
3951 | +static inline gearman_return_t gearman_universal_error_code(const gearman_universal_st &self) |
3952 | +{ |
3953 | + return self.error_code(); |
3954 | +} |
3955 | + |
3956 | +static inline int gearman_universal_errno(const gearman_universal_st &self) |
3957 | +{ |
3958 | + return self.last_errno(); |
3959 | +} |
3960 | + |
3961 | +static inline void universal_reset_error(gearman_universal_st &self) |
3962 | +{ |
3963 | + self.reset_error(); |
3964 | +} |
3965 | |
3966 | === added file 'libgearman/interface/worker.hpp' |
3967 | --- libgearman/interface/worker.hpp 1970-01-01 00:00:00 +0000 |
3968 | +++ libgearman/interface/worker.hpp 2012-09-20 02:21:22 +0000 |
3969 | @@ -0,0 +1,124 @@ |
3970 | +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3971 | + * |
3972 | + * Gearmand client and server library. |
3973 | + * |
3974 | + * Copyright (C) 2012 Data Differential, http://datadifferential.com/ |
3975 | + * All rights reserved. |
3976 | + * |
3977 | + * Redistribution and use in source and binary forms, with or without |
3978 | + * modification, are permitted provided that the following conditions are |
3979 | + * met: |
3980 | + * |
3981 | + * * Redistributions of source code must retain the above copyright |
3982 | + * notice, this list of conditions and the following disclaimer. |
3983 | + * |
3984 | + * * Redistributions in binary form must reproduce the above |
3985 | + * copyright notice, this list of conditions and the following disclaimer |
3986 | + * in the documentation and/or other materials provided with the |
3987 | + * distribution. |
3988 | + * |
3989 | + * * The names of its contributors may not be used to endorse or |
3990 | + * promote products derived from this software without specific prior |
3991 | + * written permission. |
3992 | + * |
3993 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
3994 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
3995 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
3996 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
3997 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
3998 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
3999 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
4000 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
4001 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
4002 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
4003 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
4004 | + * |
4005 | + */ |
4006 | + |
4007 | +#pragma once |
4008 | + |
4009 | +#include "libgearman/interface/universal.hpp" |
4010 | +#include "libgearman/interface/packet.hpp" |
4011 | + |
4012 | +struct Worker |
4013 | +{ |
4014 | + struct Options { |
4015 | + bool non_blocking; |
4016 | + bool packet_init; |
4017 | + bool change; |
4018 | + bool grab_uniq; |
4019 | + bool grab_all; |
4020 | + bool timeout_return; |
4021 | + |
4022 | + Options() : |
4023 | + non_blocking(false), |
4024 | + packet_init(false), |
4025 | + change(false), |
4026 | + grab_uniq(true), |
4027 | + grab_all(true), |
4028 | + timeout_return(false) |
4029 | + { } |
4030 | + } options; |
4031 | + enum gearman_worker_state_t state; |
4032 | + enum gearman_worker_universal_t work_state; |
4033 | + uint32_t function_count; |
4034 | + uint32_t job_count; |
4035 | + size_t work_result_size; |
4036 | + void *context; |
4037 | + gearman_connection_st *con; |
4038 | + gearman_job_st *job; |
4039 | + gearman_job_st *job_list; |
4040 | + struct _worker_function_st *function; |
4041 | + struct _worker_function_st *function_list; |
4042 | + struct _worker_function_st *work_function; |
4043 | + void *work_result; |
4044 | + struct gearman_universal_st universal; |
4045 | + gearman_packet_st grab_job; |
4046 | + gearman_packet_st pre_sleep; |
4047 | + gearman_job_st *work_job; |
4048 | + |
4049 | + Worker(gearman_worker_st* shell_) : |
4050 | + state(GEARMAN_WORKER_STATE_START), |
4051 | + work_state(GEARMAN_WORKER_WORK_UNIVERSAL_GRAB_JOB), |
4052 | + function_count(0), |
4053 | + job_count(0), |
4054 | + work_result_size(0), |
4055 | + context(NULL), |
4056 | + con(NULL), |
4057 | + job(NULL), |
4058 | + job_list(NULL), |
4059 | + function(NULL), |
4060 | + function_list(NULL), |
4061 | + work_function(NULL), |
4062 | + work_result(NULL), |
4063 | + work_job(NULL), |
4064 | + _shell(shell_) |
4065 | + { |
4066 | + if (shell_) |
4067 | + { |
4068 | + gearman_set_allocated(_shell, false); |
4069 | + } |
4070 | + else |
4071 | + { |
4072 | + _shell= &_owned_shell; |
4073 | + gearman_set_allocated(_shell, true); |
4074 | + } |
4075 | + |
4076 | + _shell->impl(this); |
4077 | + gearman_set_initialized(_shell, true); |
4078 | + } |
4079 | + |
4080 | + ~Worker() |
4081 | + { |
4082 | + } |
4083 | + |
4084 | + gearman_worker_st* shell() |
4085 | + { |
4086 | + return _shell; |
4087 | + } |
4088 | + |
4089 | +private: |
4090 | + gearman_worker_st* _shell; |
4091 | + gearman_worker_st _owned_shell; |
4092 | +}; |
4093 | + |
4094 | |
4095 | === modified file 'libgearman/is.hpp' |
4096 | --- libgearman/is.hpp 2012-07-09 09:07:43 +0000 |
4097 | +++ libgearman/is.hpp 2012-09-20 02:21:22 +0000 |
4098 | @@ -42,6 +42,7 @@ |
4099 | #define gearman_is_initialized(__object) ((__object)->options.is_initialized) |
4100 | #define gearman_is_purging(__object) ((__object)->state.is_purging) |
4101 | #define gearman_is_processing_input(__object) ((__object)->state.is_processing_input) |
4102 | +#define gearman_is_non_blocking(__object) ((__object)->options.non_blocking) |
4103 | #define gearman_set_purging(__object, __value) ((__object)->state.is_purging= (__value)) |
4104 | #define gearman_set_processing_input(__object, __value) ((__object)->state.is_processing_input= (__value)) |
4105 | #define gearman_set_initialized(__object, __value) ((__object)->options.is_initialized= (__value)) |
4106 | |
4107 | === modified file 'libgearman/job.cc' |
4108 | --- libgearman/job.cc 2012-09-16 00:30:28 +0000 |
4109 | +++ libgearman/job.cc 2012-09-20 02:21:22 +0000 |
4110 | @@ -76,7 +76,9 @@ |
4111 | { |
4112 | client= gearman_client_create(NULL); |
4113 | if (not client) |
4114 | + { |
4115 | return false; |
4116 | + } |
4117 | |
4118 | if (universal._namespace) |
4119 | { |
4120 | @@ -87,7 +89,7 @@ |
4121 | |
4122 | for (gearman_connection_st *con= universal.con_list; con; con= con->next) |
4123 | { |
4124 | - if (gearman_failed(gearman_client_add_server(client, con->host, con->port))) |
4125 | + if (gearman_failed(client->impl()->add_server(con->_host, con->_service))) |
4126 | { |
4127 | return false; |
4128 | } |
4129 | @@ -110,7 +112,7 @@ |
4130 | gearman_actions_execute_defaults()); |
4131 | if (task == NULL) |
4132 | { |
4133 | - gearman_universal_error_code(client->universal); |
4134 | + gearman_universal_error_code(client->impl()->universal); |
4135 | |
4136 | return false; |
4137 | } |
4138 | @@ -126,22 +128,22 @@ |
4139 | return rc; |
4140 | } |
4141 | |
4142 | - gearman_task_st *check_task= client->task_list; |
4143 | + gearman_task_st *check_task= client->impl()->task_list; |
4144 | |
4145 | if (check_task) |
4146 | { |
4147 | do |
4148 | { |
4149 | - if (gearman_failed(check_task->result_rc)) |
4150 | + if (gearman_failed(check_task->impl()->result_rc)) |
4151 | { |
4152 | - return check_task->result_rc; |
4153 | + return check_task->impl()->result_rc; |
4154 | } |
4155 | } while ((check_task= gearman_next(check_task))); |
4156 | |
4157 | if (aggregator_fn) |
4158 | { |
4159 | - gearman_aggregator_st aggregator(client->context); |
4160 | - aggregator_fn(&aggregator, client->task_list, &result); |
4161 | + gearman_aggregator_st aggregator(client->impl()->context); |
4162 | + aggregator_fn(&aggregator, client->impl()->task_list, &result); |
4163 | } |
4164 | } |
4165 | |
4166 | @@ -173,9 +175,9 @@ |
4167 | else |
4168 | { |
4169 | job= new (std::nothrow) gearman_job_st; |
4170 | - if (not job) |
4171 | + if (job == NULL) |
4172 | { |
4173 | - gearman_perror(worker->universal, "new"); |
4174 | + gearman_perror(worker->impl()->universal, "new"); |
4175 | return NULL; |
4176 | } |
4177 | |
4178 | @@ -190,14 +192,14 @@ |
4179 | job->reducer= NULL; |
4180 | job->error_code= GEARMAN_UNKNOWN_STATE; |
4181 | |
4182 | - if (worker->job_list) |
4183 | + if (worker->impl()->job_list) |
4184 | { |
4185 | - worker->job_list->prev= job; |
4186 | + worker->impl()->job_list->prev= job; |
4187 | } |
4188 | - job->next= worker->job_list; |
4189 | + job->next= worker->impl()->job_list; |
4190 | job->prev= NULL; |
4191 | - worker->job_list= job; |
4192 | - worker->job_count++; |
4193 | + worker->impl()->job_list= job; |
4194 | + worker->impl()->job_count++; |
4195 | |
4196 | job->con= NULL; |
4197 | |
4198 | @@ -213,7 +215,7 @@ |
4199 | |
4200 | gearman_string_t reducer_func= gearman_job_reducer_string(job); |
4201 | |
4202 | - job->reducer= new (std::nothrow) gearman_job_reducer_st(job->worker->universal, reducer_func, aggregator_fn); |
4203 | + job->reducer= new (std::nothrow) gearman_job_reducer_st(job->worker->impl()->universal, reducer_func, aggregator_fn); |
4204 | if (not job->reducer) |
4205 | { |
4206 | gearman_job_free(job); |
4207 | @@ -256,7 +258,7 @@ |
4208 | args_size[0]= job->assigned.arg_size[0]; |
4209 | args[1]= data; |
4210 | args_size[1]= data_size; |
4211 | - gearman_return_t ret= gearman_packet_create_args(job->worker->universal, job->work, |
4212 | + gearman_return_t ret= gearman_packet_create_args(job->worker->impl()->universal, job->work, |
4213 | GEARMAN_MAGIC_REQUEST, |
4214 | GEARMAN_COMMAND_WORK_DATA, |
4215 | args, args_size, 2); |
4216 | @@ -286,7 +288,7 @@ |
4217 | args_size[1]= warning_size; |
4218 | |
4219 | gearman_return_t ret; |
4220 | - ret= gearman_packet_create_args(job->worker->universal, job->work, |
4221 | + ret= gearman_packet_create_args(job->worker->impl()->universal, job->work, |
4222 | GEARMAN_MAGIC_REQUEST, |
4223 | GEARMAN_COMMAND_WORK_WARNING, |
4224 | args, args_size, 2); |
4225 | @@ -323,7 +325,7 @@ |
4226 | args_size[2]= strlen(denominator_string); |
4227 | |
4228 | gearman_return_t ret; |
4229 | - ret= gearman_packet_create_args(job->worker->universal, job->work, |
4230 | + ret= gearman_packet_create_args(job->worker->impl()->universal, job->work, |
4231 | GEARMAN_MAGIC_REQUEST, |
4232 | GEARMAN_COMMAND_WORK_STATUS, |
4233 | args, args_size, 3); |
4234 | @@ -369,7 +371,7 @@ |
4235 | gearman_return_t rc= job->reducer->complete(); |
4236 | if (gearman_failed(rc)) |
4237 | { |
4238 | - return gearman_error(job->worker->universal, rc, "The reducer's complete() returned an error"); |
4239 | + return gearman_error(job->worker->impl()->universal, rc, "The reducer's complete() returned an error"); |
4240 | } |
4241 | |
4242 | gearman_vector_st *reduced_value= job->reducer->result.string(); |
4243 | @@ -395,7 +397,7 @@ |
4244 | |
4245 | args[1]= result; |
4246 | args_size[1]= result_size; |
4247 | - gearman_return_t ret= gearman_packet_create_args(job->worker->universal, job->work, |
4248 | + gearman_return_t ret= gearman_packet_create_args(job->worker->impl()->universal, job->work, |
4249 | GEARMAN_MAGIC_REQUEST, |
4250 | GEARMAN_COMMAND_WORK_COMPLETE, |
4251 | args, args_size, 2); |
4252 | @@ -431,7 +433,7 @@ |
4253 | args[1]= exception; |
4254 | args_size[1]= exception_size; |
4255 | |
4256 | - gearman_return_t ret= gearman_packet_create_args(job->worker->universal, job->work, |
4257 | + gearman_return_t ret= gearman_packet_create_args(job->worker->impl()->universal, job->work, |
4258 | GEARMAN_MAGIC_REQUEST, |
4259 | GEARMAN_COMMAND_WORK_EXCEPTION, |
4260 | args, args_size, 2); |
4261 | @@ -466,7 +468,7 @@ |
4262 | { |
4263 | args[0]= job->assigned.arg[0]; |
4264 | args_size[0]= job->assigned.arg_size[0] - 1; |
4265 | - gearman_return_t ret= gearman_packet_create_args(job->worker->universal, job->work, |
4266 | + gearman_return_t ret= gearman_packet_create_args(job->worker->impl()->universal, job->work, |
4267 | GEARMAN_MAGIC_REQUEST, |
4268 | GEARMAN_COMMAND_WORK_FAIL, |
4269 | args, args_size, 1); |
4270 | @@ -572,9 +574,9 @@ |
4271 | gearman_packet_free(&(job->work)); |
4272 | } |
4273 | |
4274 | - if (job->worker->job_list == job) |
4275 | + if (job->worker->impl()->job_list == job) |
4276 | { |
4277 | - job->worker->job_list= job->next; |
4278 | + job->worker->impl()->job_list= job->next; |
4279 | } |
4280 | |
4281 | if (job->prev) |
4282 | @@ -586,7 +588,7 @@ |
4283 | { |
4284 | job->next->prev= job->prev; |
4285 | } |
4286 | - job->worker->job_count--; |
4287 | + job->worker->impl()->job_count--; |
4288 | |
4289 | delete job->reducer; |
4290 | job->reducer= NULL; |
4291 | @@ -607,11 +609,15 @@ |
4292 | |
4293 | while ((ret == GEARMAN_IO_WAIT) or (ret == GEARMAN_TIMEOUT)) |
4294 | { |
4295 | +<<<<<<< TREE |
4296 | #if 0 |
4297 | assert(job->work.universal); |
4298 | ret= gearman_wait(*(job->work.universal)); |
4299 | #endif |
4300 | ret= gearman_wait(job->worker->universal); |
4301 | +======= |
4302 | + ret= gearman_wait(job->worker->impl()->universal); |
4303 | +>>>>>>> MERGE-SOURCE |
4304 | if (ret == GEARMAN_SUCCESS) |
4305 | { |
4306 | ret= job->con->send_packet(job->work, true); |
4307 | |
4308 | === added file 'libgearman/job.hpp' |
4309 | --- libgearman/job.hpp 1970-01-01 00:00:00 +0000 |
4310 | +++ libgearman/job.hpp 2012-09-20 02:21:22 +0000 |
4311 | @@ -0,0 +1,56 @@ |
4312 | +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
4313 | + * |
4314 | + * Gearmand client and server library. |
4315 | + * |
4316 | + * Copyright (C) 2012 Data Differential, http://datadifferential.com/ |
4317 | + * All rights reserved. |
4318 | + * |
4319 | + * Redistribution and use in source and binary forms, with or without |
4320 | + * modification, are permitted provided that the following conditions are |
4321 | + * met: |
4322 | + * |
4323 | + * * Redistributions of source code must retain the above copyright |
4324 | + * notice, this list of conditions and the following disclaimer. |
4325 | + * |
4326 | + * * Redistributions in binary form must reproduce the above |
4327 | + * copyright notice, this list of conditions and the following disclaimer |
4328 | + * in the documentation and/or other materials provided with the |
4329 | + * distribution. |
4330 | + * |
4331 | + * * The names of its contributors may not be used to endorse or |
4332 | + * promote products derived from this software without specific prior |
4333 | + * written permission. |
4334 | + * |
4335 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4336 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
4337 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
4338 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
4339 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
4340 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
4341 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
4342 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
4343 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
4344 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
4345 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
4346 | + * |
4347 | + */ |
4348 | + |
4349 | +#pragma once |
4350 | + |
4351 | +struct gearman_job_st |
4352 | +{ |
4353 | + struct { |
4354 | + bool allocated; |
4355 | + bool assigned_in_use; |
4356 | + bool work_in_use; |
4357 | + bool finished; |
4358 | + } options; |
4359 | + gearman_worker_st *worker; |
4360 | + gearman_job_st *next; |
4361 | + gearman_job_st *prev; |
4362 | + gearman_connection_st *con; |
4363 | + gearman_packet_st assigned; |
4364 | + gearman_packet_st work; |
4365 | + struct gearman_job_reducer_st *reducer; |
4366 | + gearman_return_t error_code; |
4367 | +}; |
4368 | |
4369 | === modified file 'libgearman/packet.cc' |
4370 | --- libgearman/packet.cc 2012-05-27 02:38:08 +0000 |
4371 | +++ libgearman/packet.cc 2012-09-20 02:21:22 +0000 |
4372 | @@ -159,7 +159,7 @@ |
4373 | { |
4374 | if (packet) |
4375 | { |
4376 | - packet->options.allocated= false; |
4377 | + gearman_set_allocated(packet, false); |
4378 | packet->options.complete= false; |
4379 | packet->options.free_data= false; |
4380 | } |
4381 | @@ -173,7 +173,7 @@ |
4382 | return NULL; |
4383 | } |
4384 | |
4385 | - packet->options.allocated= true; |
4386 | + gearman_set_allocated(packet, true); |
4387 | } |
4388 | packet->options.complete= false; |
4389 | packet->options.free_data= false; |
4390 | @@ -319,7 +319,7 @@ |
4391 | packet->universal->packet_count--; |
4392 | } |
4393 | |
4394 | - if (packet->options.allocated) |
4395 | + if (gearman_is_allocated(packet)) |
4396 | { |
4397 | delete packet; |
4398 | } |
4399 | |
4400 | === modified file 'libgearman/protocol/submit.cc' |
4401 | --- libgearman/protocol/submit.cc 2012-08-11 01:53:36 +0000 |
4402 | +++ libgearman/protocol/submit.cc 2012-09-20 02:21:22 +0000 |
4403 | @@ -43,7 +43,7 @@ |
4404 | namespace libgearman { |
4405 | namespace protocol { |
4406 | |
4407 | -static inline gearman_return_t __submit(gearman_task_st& task, |
4408 | +static inline gearman_return_t __submit(Task& task, |
4409 | const gearman_command_t command, |
4410 | const gearman_string_t &function, |
4411 | const gearman_string_t &workload) |
4412 | @@ -55,11 +55,12 @@ |
4413 | @todo fix it so that NULL is done by default by the API not by happenstance. |
4414 | */ |
4415 | char function_buffer[1024]; |
4416 | - if (task.client->universal._namespace) |
4417 | + assert(task.client); |
4418 | + if (task.client->impl()->universal._namespace) |
4419 | { |
4420 | char *ptr= function_buffer; |
4421 | - memcpy(ptr, gearman_string_value(task.client->universal._namespace), gearman_string_length(task.client->universal._namespace)); |
4422 | - ptr+= gearman_string_length(task.client->universal._namespace); |
4423 | + memcpy(ptr, gearman_string_value(task.client->impl()->universal._namespace), gearman_string_length(task.client->impl()->universal._namespace)); |
4424 | + ptr+= gearman_string_length(task.client->impl()->universal._namespace); |
4425 | |
4426 | memcpy(ptr, gearman_c_str(function), gearman_size(function) +1); |
4427 | ptr+= gearman_size(function); |
4428 | @@ -79,14 +80,14 @@ |
4429 | args[2]= gearman_c_str(workload); |
4430 | args_size[2]= gearman_size(workload); |
4431 | |
4432 | - return gearman_packet_create_args(task.client->universal, task.send, |
4433 | + return gearman_packet_create_args(task.client->impl()->universal, task.send, |
4434 | GEARMAN_MAGIC_REQUEST, |
4435 | command, |
4436 | args, args_size, |
4437 | 3); |
4438 | } |
4439 | |
4440 | -gearman_return_t submit(gearman_task_st& task, |
4441 | +gearman_return_t submit(Task& task, |
4442 | const gearman_command_t command, |
4443 | const gearman_string_t &function, |
4444 | const gearman_string_t &workload) |
4445 | @@ -94,7 +95,7 @@ |
4446 | return __submit(task, command, function, workload); |
4447 | } |
4448 | |
4449 | -gearman_return_t submit_background(gearman_task_st& task, |
4450 | +gearman_return_t submit_background(Task& task, |
4451 | const gearman_command_t command, |
4452 | const gearman_string_t &function, |
4453 | const gearman_string_t &workload) |
4454 | @@ -102,7 +103,7 @@ |
4455 | return __submit(task, command, function, workload); |
4456 | } |
4457 | |
4458 | -gearman_return_t submit_epoch(gearman_task_st& task, |
4459 | +gearman_return_t submit_epoch(Task& task, |
4460 | const gearman_string_t &function, |
4461 | const gearman_string_t &workload, |
4462 | time_t when) |
4463 | @@ -114,11 +115,11 @@ |
4464 | @todo fix it so that NULL is done by default by the API not by happenstance. |
4465 | */ |
4466 | char function_buffer[1024]; |
4467 | - if (task.client->universal._namespace) |
4468 | + if (task.client->impl()->universal._namespace) |
4469 | { |
4470 | char *ptr= function_buffer; |
4471 | - memcpy(ptr, gearman_string_value(task.client->universal._namespace), gearman_string_length(task.client->universal._namespace)); |
4472 | - ptr+= gearman_string_length(task.client->universal._namespace); |
4473 | + memcpy(ptr, gearman_string_value(task.client->impl()->universal._namespace), gearman_string_length(task.client->impl()->universal._namespace)); |
4474 | + ptr+= gearman_string_length(task.client->impl()->universal._namespace); |
4475 | |
4476 | memcpy(ptr, gearman_c_str(function), gearman_size(function) +1); |
4477 | ptr+= gearman_size(function); |
4478 | @@ -143,7 +144,7 @@ |
4479 | args[3]= gearman_c_str(workload); |
4480 | args_size[3]= gearman_size(workload); |
4481 | |
4482 | - return gearman_packet_create_args(task.client->universal, task.send, |
4483 | + return gearman_packet_create_args(task.client->impl()->universal, task.send, |
4484 | GEARMAN_MAGIC_REQUEST, |
4485 | GEARMAN_COMMAND_SUBMIT_JOB_EPOCH, |
4486 | args, args_size, |
4487 | |
4488 | === modified file 'libgearman/protocol/submit.h' |
4489 | --- libgearman/protocol/submit.h 2012-05-13 23:19:56 +0000 |
4490 | +++ libgearman/protocol/submit.h 2012-09-20 02:21:22 +0000 |
4491 | @@ -41,17 +41,17 @@ |
4492 | namespace libgearman { |
4493 | namespace protocol { |
4494 | |
4495 | -gearman_return_t submit(gearman_task_st&, |
4496 | +gearman_return_t submit(Task&, |
4497 | const gearman_command_t command, |
4498 | const gearman_string_t &function, |
4499 | const gearman_string_t &workload); |
4500 | |
4501 | -gearman_return_t submit_background(gearman_task_st&, |
4502 | +gearman_return_t submit_background(Task&, |
4503 | const gearman_command_t command, |
4504 | const gearman_string_t &function, |
4505 | const gearman_string_t &workload); |
4506 | |
4507 | -gearman_return_t submit_epoch(gearman_task_st&, |
4508 | +gearman_return_t submit_epoch(Task&, |
4509 | const gearman_string_t &function, |
4510 | const gearman_string_t &workload, |
4511 | time_t when); |
4512 | |
4513 | === modified file 'libgearman/run.cc' |
4514 | --- libgearman/run.cc 2012-08-02 05:44:19 +0000 |
4515 | +++ libgearman/run.cc 2012-09-20 02:21:22 +0000 |
4516 | @@ -45,13 +45,13 @@ |
4517 | #include <cstdlib> |
4518 | #include <cstring> |
4519 | |
4520 | -gearman_return_t _client_run_task(gearman_task_st *task) |
4521 | +gearman_return_t _client_run_task(Task *task) |
4522 | { |
4523 | // This should not be possible |
4524 | assert_msg(task->client, "Programmer error, somehow an invalid task was specified"); |
4525 | if (task->client == NULL) |
4526 | { |
4527 | - return gearman_universal_set_error(task->client->universal, GEARMAN_INVALID_ARGUMENT, GEARMAN_AT, |
4528 | + return gearman_universal_set_error(task->client->impl()->universal, GEARMAN_INVALID_ARGUMENT, GEARMAN_AT, |
4529 | "Programmer error, somehow an invalid task was specified"); |
4530 | } |
4531 | |
4532 | @@ -59,14 +59,14 @@ |
4533 | { |
4534 | case GEARMAN_TASK_STATE_NEW: |
4535 | |
4536 | - if (task->client->universal.con_list == NULL) |
4537 | + if (task->client->impl()->universal.con_list == NULL) |
4538 | { |
4539 | - task->client->new_tasks--; |
4540 | - task->client->running_tasks--; |
4541 | - return gearman_universal_set_error(task->client->universal, GEARMAN_NO_SERVERS, GEARMAN_AT, "no servers added"); |
4542 | + task->client->impl()->new_tasks--; |
4543 | + task->client->impl()->running_tasks--; |
4544 | + return gearman_universal_set_error(task->client->impl()->universal, GEARMAN_NO_SERVERS, GEARMAN_AT, "no servers added"); |
4545 | } |
4546 | |
4547 | - for (task->con= task->client->universal.con_list; task->con; |
4548 | + for (task->con= task->client->impl()->universal.con_list; task->con; |
4549 | task->con= task->con->next) |
4550 | { |
4551 | if (task->con->send_state == GEARMAN_CON_SEND_STATE_NONE) |
4552 | @@ -77,11 +77,11 @@ |
4553 | |
4554 | if (task->con == NULL) |
4555 | { |
4556 | - task->client->options.no_new= true; |
4557 | - return gearman_gerror(task->client->universal, GEARMAN_IO_WAIT); |
4558 | + task->client->impl()->options.no_new= true; |
4559 | + return gearman_gerror(task->client->impl()->universal, GEARMAN_IO_WAIT); |
4560 | } |
4561 | |
4562 | - task->client->new_tasks--; |
4563 | + task->client->impl()->new_tasks--; |
4564 | |
4565 | if (task->send.command != GEARMAN_COMMAND_GET_STATUS) |
4566 | { |
4567 | @@ -93,7 +93,7 @@ |
4568 | while (1) |
4569 | { |
4570 | assert(task->con); |
4571 | - gearman_return_t ret= task->con->send_packet(task->send, task->client->new_tasks == 0 ? true : false); |
4572 | + gearman_return_t ret= task->con->send_packet(task->send, task->client->impl()->new_tasks == 0 ? true : false); |
4573 | |
4574 | if (gearman_success(ret)) |
4575 | { |
4576 | @@ -133,12 +133,12 @@ |
4577 | if (ret == GEARMAN_COULD_NOT_CONNECT) // If no connection is found, we will let the user try again |
4578 | { |
4579 | task->state= GEARMAN_TASK_STATE_NEW; |
4580 | - task->client->new_tasks++; |
4581 | + task->client->impl()->new_tasks++; |
4582 | } |
4583 | else |
4584 | { |
4585 | task->state= GEARMAN_TASK_STATE_FAIL; |
4586 | - task->client->running_tasks--; |
4587 | + task->client->impl()->running_tasks--; |
4588 | } |
4589 | return ret; |
4590 | } |
4591 | @@ -155,13 +155,13 @@ |
4592 | { |
4593 | if (not task->func.workload_fn) |
4594 | { |
4595 | - gearman_error(task->client->universal, GEARMAN_NEED_WORKLOAD_FN, |
4596 | + gearman_error(task->client->impl()->universal, GEARMAN_NEED_WORKLOAD_FN, |
4597 | "workload size > 0, but no data pointer or workload_fn was given"); |
4598 | return GEARMAN_NEED_WORKLOAD_FN; |
4599 | } |
4600 | |
4601 | case GEARMAN_TASK_STATE_WORKLOAD: |
4602 | - gearman_return_t ret= task->func.workload_fn(task); |
4603 | + gearman_return_t ret= task->func.workload_fn(task->shell()); |
4604 | if (gearman_failed(ret)) |
4605 | { |
4606 | task->state= GEARMAN_TASK_STATE_WORKLOAD; |
4607 | @@ -169,7 +169,7 @@ |
4608 | } |
4609 | } |
4610 | |
4611 | - task->client->options.no_new= false; |
4612 | + task->client->impl()->options.no_new= false; |
4613 | task->state= GEARMAN_TASK_STATE_WORK; |
4614 | task->con->set_events(POLLIN); |
4615 | return GEARMAN_SUCCESS; |
4616 | @@ -185,7 +185,7 @@ |
4617 | case GEARMAN_TASK_STATE_CREATED: |
4618 | if (task->func.created_fn) |
4619 | { |
4620 | - gearman_return_t ret= task->func.created_fn(task); |
4621 | + gearman_return_t ret= task->func.created_fn(task->shell()); |
4622 | if (gearman_failed(ret)) |
4623 | { |
4624 | task->state= GEARMAN_TASK_STATE_CREATED; |
4625 | @@ -210,7 +210,7 @@ |
4626 | case GEARMAN_TASK_STATE_DATA: |
4627 | if (task->func.data_fn) |
4628 | { |
4629 | - gearman_return_t ret= task->func.data_fn(task); |
4630 | + gearman_return_t ret= task->func.data_fn(task->shell()); |
4631 | if (gearman_failed(ret)) |
4632 | { |
4633 | task->state= GEARMAN_TASK_STATE_DATA; |
4634 | @@ -223,7 +223,7 @@ |
4635 | case GEARMAN_TASK_STATE_WARNING: |
4636 | if (task->func.warning_fn) |
4637 | { |
4638 | - gearman_return_t ret= task->func.warning_fn(task); |
4639 | + gearman_return_t ret= task->func.warning_fn(task->shell()); |
4640 | if (gearman_failed(ret)) |
4641 | { |
4642 | task->state= GEARMAN_TASK_STATE_WARNING; |
4643 | @@ -311,7 +311,7 @@ |
4644 | case GEARMAN_TASK_STATE_STATUS: |
4645 | if (task->func.status_fn) |
4646 | { |
4647 | - gearman_return_t ret= task->func.status_fn(task); |
4648 | + gearman_return_t ret= task->func.status_fn(task->shell()); |
4649 | if (gearman_failed(ret)) |
4650 | { |
4651 | task->state= GEARMAN_TASK_STATE_STATUS; |
4652 | @@ -338,7 +338,7 @@ |
4653 | case GEARMAN_TASK_STATE_COMPLETE: |
4654 | if (task->func.complete_fn) |
4655 | { |
4656 | - gearman_return_t ret= task->func.complete_fn(task); |
4657 | + gearman_return_t ret= task->func.complete_fn(task->shell()); |
4658 | if (gearman_failed(ret)) |
4659 | { |
4660 | task->state= GEARMAN_TASK_STATE_COMPLETE; |
4661 | @@ -353,7 +353,7 @@ |
4662 | case GEARMAN_TASK_STATE_EXCEPTION: |
4663 | if (task->func.exception_fn) |
4664 | { |
4665 | - gearman_return_t ret= task->func.exception_fn(task); |
4666 | + gearman_return_t ret= task->func.exception_fn(task->shell()); |
4667 | if (gearman_failed(ret)) |
4668 | { |
4669 | task->state= GEARMAN_TASK_STATE_EXCEPTION; |
4670 | @@ -374,7 +374,7 @@ |
4671 | case GEARMAN_TASK_STATE_FAIL: |
4672 | if (task->func.fail_fn) |
4673 | { |
4674 | - gearman_return_t ret= task->func.fail_fn(task); |
4675 | + gearman_return_t ret= task->func.fail_fn(task->shell()); |
4676 | if (gearman_failed(ret)) |
4677 | { |
4678 | task->state= GEARMAN_TASK_STATE_FAIL; |
4679 | @@ -392,12 +392,12 @@ |
4680 | break; |
4681 | } |
4682 | |
4683 | - task->client->running_tasks--; |
4684 | + task->client->impl()->running_tasks--; |
4685 | task->state= GEARMAN_TASK_STATE_FINISHED; |
4686 | |
4687 | - if (task->client->options.free_tasks and task->type == GEARMAN_TASK_KIND_ADD_TASK) |
4688 | + if (task->client->impl()->options.free_tasks and task->type == GEARMAN_TASK_KIND_ADD_TASK) |
4689 | { |
4690 | - gearman_task_free(task); |
4691 | + gearman_task_free(task->shell()); |
4692 | } |
4693 | |
4694 | return GEARMAN_SUCCESS; |
4695 | |
4696 | === modified file 'libgearman/run.hpp' |
4697 | --- libgearman/run.hpp 2012-03-12 01:44:08 +0000 |
4698 | +++ libgearman/run.hpp 2012-09-20 02:21:22 +0000 |
4699 | @@ -38,4 +38,4 @@ |
4700 | |
4701 | #pragma once |
4702 | |
4703 | -gearman_return_t _client_run_task(gearman_task_st *task); |
4704 | +gearman_return_t _client_run_task(Task *task); |
4705 | |
4706 | === modified file 'libgearman/task.cc' |
4707 | --- libgearman/task.cc 2012-08-02 05:44:19 +0000 |
4708 | +++ libgearman/task.cc 2012-09-20 02:21:22 +0000 |
4709 | @@ -54,418 +54,367 @@ |
4710 | * Public Definitions |
4711 | */ |
4712 | |
4713 | -#define TASK_MAGIC 134 |
4714 | -#define TASK_ANTI_MAGIC 157 |
4715 | - |
4716 | -gearman_task_st *gearman_task_internal_create(gearman_client_st *client, gearman_task_st *task) |
4717 | +gearman_task_st *gearman_task_internal_create(gearman_client_st& client, gearman_task_st *task_shell) |
4718 | { |
4719 | - assert(client); |
4720 | + Task* task= new (std::nothrow) Task(client, task_shell); |
4721 | if (task) |
4722 | { |
4723 | - task->options.allocated= false; |
4724 | - } |
4725 | - else |
4726 | - { |
4727 | - task= new (std::nothrow) gearman_task_st; |
4728 | - if (task == NULL) |
4729 | - { |
4730 | - gearman_perror(client->universal, "gearman_task_st new"); |
4731 | - return NULL; |
4732 | - } |
4733 | - |
4734 | - task->options.allocated= true; |
4735 | - } |
4736 | - task->options.is_initialized= true; |
4737 | - |
4738 | - task->options.send_in_use= false; |
4739 | - task->options.is_known= false; |
4740 | - task->options.is_running= false; |
4741 | - task->options.was_reduced= false; |
4742 | - task->options.is_paused= false; |
4743 | - |
4744 | - task->type= GEARMAN_TASK_KIND_ADD_TASK; |
4745 | - |
4746 | - task->state= GEARMAN_TASK_STATE_NEW; |
4747 | - task->magic_= TASK_MAGIC; |
4748 | - task->created_id= 0; |
4749 | - task->numerator= 0; |
4750 | - task->denominator= 0; |
4751 | - task->client_count= 0; |
4752 | - task->client= client; |
4753 | - |
4754 | - task->func= client->actions; |
4755 | - task->result_rc= GEARMAN_UNKNOWN_STATE; |
4756 | - |
4757 | - // Add the task to the client |
4758 | - { |
4759 | - if (client->task_list) |
4760 | - { |
4761 | - client->task_list->prev= task; |
4762 | - } |
4763 | - task->next= client->task_list; |
4764 | - task->prev= NULL; |
4765 | - client->task_list= task; |
4766 | - client->task_count++; |
4767 | - } |
4768 | - |
4769 | - task->context= NULL; |
4770 | - task->con= NULL; |
4771 | - task->recv= NULL; |
4772 | - task->result_ptr= NULL; |
4773 | - task->job_handle[0]= 0; |
4774 | - task->unique_length= 0; |
4775 | - task->unique[0]= 0; |
4776 | - |
4777 | - return task; |
4778 | -} |
4779 | - |
4780 | - |
4781 | -void gearman_task_free(gearman_task_st *task) |
4782 | -{ |
4783 | - if (task == NULL) |
4784 | - { |
4785 | - return; |
4786 | - } |
4787 | - |
4788 | - if (task->options.is_initialized == false) |
4789 | - { |
4790 | - return; |
4791 | - } |
4792 | - |
4793 | - assert(task->magic_ != TASK_ANTI_MAGIC); |
4794 | - assert(task->magic_ == TASK_MAGIC); |
4795 | - task->magic_= TASK_ANTI_MAGIC; |
4796 | - |
4797 | - gearman_task_free_result(task); |
4798 | - |
4799 | - if (task->client) |
4800 | - { |
4801 | - if (task->options.send_in_use) |
4802 | - { |
4803 | - gearman_packet_free(&(task->send)); |
4804 | - } |
4805 | - |
4806 | - if (task->type != GEARMAN_TASK_KIND_DO and task->context and task->client->task_context_free_fn) |
4807 | - { |
4808 | - task->client->task_context_free_fn(task, static_cast<void *>(task->context)); |
4809 | - } |
4810 | - |
4811 | - if (task->client->task_list == task) |
4812 | - { |
4813 | - task->client->task_list= task->next; |
4814 | - } |
4815 | - |
4816 | - if (task->prev) |
4817 | - { |
4818 | - task->prev->next= task->next; |
4819 | - } |
4820 | - |
4821 | - if (task->next) |
4822 | - { |
4823 | - task->next->prev= task->prev; |
4824 | - } |
4825 | - |
4826 | - task->client->task_count--; |
4827 | - |
4828 | - // If the task we are removing is a current task, remove it from the client |
4829 | - // structures. |
4830 | - if (task->client->task == task) |
4831 | - { |
4832 | - task->client->task= NULL; |
4833 | - } |
4834 | - task->client= NULL; |
4835 | - } |
4836 | - task->job_handle[0]= 0; |
4837 | - |
4838 | - task->options.is_initialized= false; |
4839 | - if (task->options.allocated) |
4840 | - { |
4841 | - delete task; |
4842 | - } |
4843 | -} |
4844 | - |
4845 | -void gearman_task_free_result(gearman_task_st *task) |
4846 | -{ |
4847 | - assert(task); |
4848 | - delete task->result_ptr; |
4849 | - task->result_ptr= NULL; |
4850 | -} |
4851 | - |
4852 | -bool gearman_task_is_active(const gearman_task_st *self) |
4853 | -{ |
4854 | - assert(self); |
4855 | - switch (self->state) |
4856 | - { |
4857 | - case GEARMAN_TASK_STATE_NEW: |
4858 | - case GEARMAN_TASK_STATE_SUBMIT: |
4859 | - case GEARMAN_TASK_STATE_WORKLOAD: |
4860 | - case GEARMAN_TASK_STATE_WORK: |
4861 | - case GEARMAN_TASK_STATE_CREATED: |
4862 | - case GEARMAN_TASK_STATE_DATA: |
4863 | - case GEARMAN_TASK_STATE_WARNING: |
4864 | - case GEARMAN_TASK_STATE_STATUS: |
4865 | - return true; |
4866 | - |
4867 | - case GEARMAN_TASK_STATE_COMPLETE: |
4868 | - case GEARMAN_TASK_STATE_EXCEPTION: |
4869 | - case GEARMAN_TASK_STATE_FAIL: |
4870 | - case GEARMAN_TASK_STATE_FINISHED: |
4871 | - break; |
4872 | - } |
4873 | - |
4874 | - return false; |
4875 | -} |
4876 | - |
4877 | -const char *gearman_task_strstate(const gearman_task_st *self) |
4878 | -{ |
4879 | - if (self == NULL) |
4880 | - { |
4881 | - return NULL; |
4882 | - } |
4883 | - |
4884 | - switch (self->state) |
4885 | - { |
4886 | - case GEARMAN_TASK_STATE_NEW: return "GEARMAN_TASK_STATE_NEW"; |
4887 | - case GEARMAN_TASK_STATE_SUBMIT: return "GEARMAN_TASK_STATE_SUBMIT"; |
4888 | - case GEARMAN_TASK_STATE_WORKLOAD: return "GEARMAN_TASK_STATE_WORKLOAD"; |
4889 | - case GEARMAN_TASK_STATE_WORK: return "GEARMAN_TASK_STATE_WORK"; |
4890 | - case GEARMAN_TASK_STATE_CREATED: return "GEARMAN_TASK_STATE_CREATED"; |
4891 | - case GEARMAN_TASK_STATE_DATA: return "GEARMAN_TASK_STATE_DATA"; |
4892 | - case GEARMAN_TASK_STATE_WARNING: return "GEARMAN_TASK_STATE_WARNING"; |
4893 | - case GEARMAN_TASK_STATE_STATUS: return "GEARMAN_TASK_STATE_STATUS"; |
4894 | - case GEARMAN_TASK_STATE_COMPLETE: return "GEARMAN_TASK_STATE_COMPLETE"; |
4895 | - case GEARMAN_TASK_STATE_EXCEPTION: return "GEARMAN_TASK_STATE_EXCEPTION"; |
4896 | - case GEARMAN_TASK_STATE_FAIL: return "GEARMAN_TASK_STATE_FAIL"; |
4897 | - case GEARMAN_TASK_STATE_FINISHED: return "GEARMAN_TASK_STATE_FINISHED"; |
4898 | - } |
4899 | - |
4900 | - return ""; |
4901 | -} |
4902 | - |
4903 | -void gearman_task_clear_fn(gearman_task_st *task) |
4904 | -{ |
4905 | - if (task == NULL) |
4906 | - { |
4907 | - return; |
4908 | - } |
4909 | - |
4910 | - task->func= gearman_actions_default(); |
4911 | -} |
4912 | - |
4913 | -void *gearman_task_context(const gearman_task_st *task) |
4914 | -{ |
4915 | - if (task == NULL) |
4916 | - { |
4917 | - return NULL; |
4918 | - } |
4919 | - |
4920 | - return const_cast<void *>(task->context); |
4921 | -} |
4922 | - |
4923 | -void gearman_task_set_context(gearman_task_st *task, void *context) |
4924 | -{ |
4925 | - if (task == NULL) |
4926 | - { |
4927 | - return; |
4928 | - } |
4929 | - |
4930 | - task->context= context; |
4931 | -} |
4932 | - |
4933 | -const char *gearman_task_function_name(const gearman_task_st *task) |
4934 | -{ |
4935 | - if (task == NULL) |
4936 | - { |
4937 | - return 0; |
4938 | - } |
4939 | - |
4940 | - return task->send.arg[0]; |
4941 | -} |
4942 | - |
4943 | -const char *gearman_task_unique(const gearman_task_st *task) |
4944 | -{ |
4945 | - if (task == NULL) |
4946 | - { |
4947 | - return 0; |
4948 | - } |
4949 | - |
4950 | - return task->unique; |
4951 | -} |
4952 | - |
4953 | -const char *gearman_task_job_handle(const gearman_task_st *task) |
4954 | -{ |
4955 | - if (task == NULL) |
4956 | - { |
4957 | - return 0; |
4958 | - } |
4959 | - |
4960 | - return task->job_handle; |
4961 | -} |
4962 | - |
4963 | -bool gearman_task_is_known(const gearman_task_st *task) |
4964 | -{ |
4965 | - if (task == NULL) |
4966 | - { |
4967 | - return false; |
4968 | - } |
4969 | - |
4970 | - return task->options.is_known; |
4971 | -} |
4972 | - |
4973 | -bool gearman_task_is_running(const gearman_task_st *task) |
4974 | -{ |
4975 | - if (task == NULL) |
4976 | - { |
4977 | - return false; |
4978 | - } |
4979 | - |
4980 | - return task->options.is_running; |
4981 | -} |
4982 | - |
4983 | -uint32_t gearman_task_numerator(const gearman_task_st *task) |
4984 | -{ |
4985 | - if (task == NULL) |
4986 | - { |
4987 | - return 0; |
4988 | - } |
4989 | - |
4990 | - return task->numerator; |
4991 | -} |
4992 | - |
4993 | -uint32_t gearman_task_denominator(const gearman_task_st *task) |
4994 | -{ |
4995 | - if (task == NULL) |
4996 | - { |
4997 | - return 0; |
4998 | - } |
4999 | - |
5000 | - return task->denominator; |
The diff has been truncated for viewing.