Merge lp:~mordred/gearmand/visibility-changes into lp:gearmand/1.0

Proposed by Monty Taylor on 2009-12-30
Status: Merged
Merged at revision: not available
Proposed branch: lp:~mordred/gearmand/visibility-changes
Merge into: lp:gearmand/1.0
Diff against target: 11528 lines (+4425/-3077)
72 files modified
.bzrignore (+41/-33)
ChangeLog (+8/-0)
Makefile.am (+8/-7)
benchmark/benchmark.c (+1/-1)
benchmark/include.am (+3/-3)
config/pre_hook.sh (+1/-1)
configure.ac (+2/-17)
docs/man_gen.perl (+2/-1)
libgearman-server/common.h (+1/-0)
libgearman-server/connection.c (+8/-9)
libgearman-server/connection.h (+1/-1)
libgearman-server/constants.h (+1/-1)
libgearman-server/gearmand.c (+1/-1)
libgearman-server/gearmand.h (+1/-1)
libgearman-server/gearmand_con.c (+4/-4)
libgearman-server/gearmand_con.h (+2/-2)
libgearman-server/gearmand_thread.c (+1/-1)
libgearman-server/include.am (+8/-12)
libgearman-server/packet.c (+4/-4)
libgearman-server/protocol_http.c (+20/-18)
libgearman-server/server.c (+13/-10)
libgearman-server/server.h (+1/-1)
libgearman-server/structs.h (+8/-8)
libgearman-server/thread.c (+10/-12)
libgearman/client.c (+186/-196)
libgearman/client.h (+46/-20)
libgearman/command.h (+6/-199)
libgearman/common.h (+1/-2)
libgearman/connection.c (+505/-366)
libgearman/connection.h (+181/-90)
libgearman/constants.h (+34/-167)
libgearman/core.c (+73/-0)
libgearman/core.h (+49/-0)
libgearman/gearman.c (+57/-0)
libgearman/gearman.h (+112/-0)
libgearman/include.am (+46/-24)
libgearman/job.c (+72/-33)
libgearman/job.h (+44/-0)
libgearman/log.c (+101/-0)
libgearman/log.h (+16/-90)
libgearman/packet.c (+141/-26)
libgearman/packet.h (+109/-19)
libgearman/task.c (+69/-2)
libgearman/task.h (+61/-0)
libgearman/universal.c (+204/-577)
libgearman/universal.h (+161/-282)
libgearman/visibility.h (+11/-1)
libgearman/worker.c (+175/-153)
libgearman/worker.h (+69/-19)
m4/pandora_canonical.m4 (+2/-2)
m4/pandora_drizzle_build.m4 (+13/-1)
m4/pandora_optimize.m4 (+1/-1)
m4/pandora_visibility.m4 (+8/-4)
m4/pandora_warnings.m4 (+2/-2)
m4/pandora_with_memcached.m4 (+1/-0)
m4/pandora_with_python.m4 (+11/-2)
m4/pandora_with_python3.m4 (+1/-1)
tests/client_test.c (+259/-74)
tests/client_test.rec (+0/-28)
tests/include.am (+40/-46)
tests/internals.c (+487/-0)
tests/memcached_test.c (+38/-46)
tests/memcached_test.rec (+0/-14)
tests/regression.c (+212/-0)
tests/sqlite_test.c (+37/-46)
tests/sqlite_test.rec (+0/-14)
tests/test.c (+195/-97)
tests/test.h (+130/-27)
tests/test_worker.c (+2/-1)
tests/worker_drone.c (+21/-21)
tests/worker_test.c (+286/-219)
tests/worker_test.rec (+0/-17)
To merge this branch: bzr merge lp:~mordred/gearmand/visibility-changes
Reviewer Review Type Date Requested Status
Brian Aker 2009-12-30 Pending
Review via email: mp+16677@code.launchpad.net
To post a comment you must log in.
Monty Taylor (mordred) wrote :

Fixed the visibility issues on solaris.

277. By Monty Taylor on 2009-12-30

Updated memcached test to check that we actually _have_ memcached before trying
to test against it.

278. By Monty Taylor on 2009-12-30

Bumped version numbers for release.

279. By Monty Taylor on 2009-12-30

Fixed header install.

280. By Monty Taylor on 2009-12-30

Change libgearman-server to a noinst lib.

281. By Monty Taylor on 2009-12-30

Made libgearman-server a noinst lib.

282. By Monty Taylor on 2009-12-30

Don't install the libgearman-server headers.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2009-08-10 21:22:21 +0000
3+++ .bzrignore 2009-12-30 19:24:13 +0000
4@@ -1,20 +1,28 @@
5+*.deps
6+*.dirstamp
7+*.la
8+*.libs
9+*.lo
10+*.moved
11+*.o
12+*.orig
13+*.rej
14 *Makefile
15 *Makefile.in
16-*.o
17-*.lo
18-*.la
19-*.deps
20-*.libs
21+*gz
22+*rpm
23 *stamp-h1
24+INSTALL
25+TAGS
26 aclocal.m4
27 autom4te.cache
28+benchmark/blobslap_client
29+benchmark/blobslap_worker
30+bin/gearman
31+config.h
32+config.h.in
33 config.log
34 config.status
35-config.h
36-config.h.in
37-configure
38-libtool
39-INSTALL
40 config/compile
41 config/config.guess
42 config/config.sub
43@@ -22,11 +30,12 @@
44 config/install-sh
45 config/ltmain.sh
46 config/missing
47+config/plugin.ac
48+configure
49 docs/api
50 docs/dev
51 docs/man/man3/*.3
52 docs/man_list
53-gearmand/gearmand
54 examples/echo_client
55 examples/echo_worker
56 examples/reverse_client
57@@ -34,31 +43,30 @@
58 examples/reverse_client_cb
59 examples/reverse_worker
60 examples/wc_worker
61+gearmand/gearmand
62+libtool
63+m4/libtool.m4
64+m4/ltoptions.m4
65+m4/ltsugar.m4
66+m4/ltversion.m4
67+m4/lt~obsolete.m4
68+out
69+patch
70+patch*
71+scripts/gearmand
72+scripts/gearmand-init
73+scripts/gearmand.xml
74+scripts/smf_install.sh
75+support/gearmand.pc
76+support/gearmand.spec
77 tests/client_test
78 tests/client_test.res
79-tests/worker_test
80-tests/worker_test.res
81+tests/cpp_test
82+tests/internals_test
83 tests/memcached_test
84 tests/memcached_test.res
85+tests/regression_test
86 tests/sqlite_test
87 tests/sqlite_test.res
88-support/gearmand.pc
89-support/gearmand.spec
90-benchmark/blobslap_client
91-benchmark/blobslap_worker
92-bin/gearman
93-tests/cpp_test
94-scripts/gearmand-init
95-scripts/gearmand
96-scripts/gearmand.xml
97-scripts/smf_install.sh
98-m4/libtool.m4
99-m4/ltoptions.m4
100-m4/ltsugar.m4
101-m4/ltversion.m4
102-m4/lt~obsolete.m4
103-TAGS
104-*rpm
105-*gz
106-*.moved
107-config/plugin.ac
108+tests/worker_test
109+tests/worker_test.res
110
111=== modified file 'ChangeLog'
112--- ChangeLog 2009-12-18 20:37:36 +0000
113+++ ChangeLog 2009-12-30 19:24:13 +0000
114@@ -1,3 +1,11 @@
115+0.13
116+ * Fixed bug where setting an option off in mass would not trip any
117+ triggers on the option (for both worker and client).
118+ * Options that are internal can no longer be set by external
119+ callers.
120+ * Deprecated gearman_client_set_event_watch_fn() and
121+ gearman_worker_set_event_watch_fn.
122+
123 0.12 - 2010-01-??
124 * Fixed job handle comparison bug with WORK_FAIL responses.
125 * Fixed disable assert configure option.
126
127=== modified file 'Makefile.am'
128--- Makefile.am 2009-12-18 19:18:51 +0000
129+++ Makefile.am 2009-12-30 19:24:13 +0000
130@@ -13,7 +13,7 @@
131 noinst_PROGRAMS =
132 lib_LTLIBRARIES =
133 noinst_LTLIBRARIES =
134-nobase_pkginclude_HEADERS =
135+nobase_include_HEADERS =
136 noinst_HEADERS =
137 EXTRA_DIST =
138 CLEANFILES =
139@@ -35,11 +35,7 @@
140 docs/api_header.html \
141 docs/dev_header.html \
142 docs/doxygen.h \
143- scripts/gearmand-init \
144- scripts/gearmand.xml \
145- scripts/gearmand \
146- scripts/README.solaris \
147- support/gearmand.spec
148+ scripts/README.solaris
149
150 pkgconfigdir = $(libdir)/pkgconfig
151 pkgconfig_DATA = support/gearmand.pc
152@@ -50,9 +46,14 @@
153
154 test: check
155
156-
157 rpm: all dist
158 cp gearmand-$(VERSION).tar.gz ~/rpmbuild/SOURCES/
159 rpmbuild -ba support/gearmand.spec
160 cp ~/rpmbuild/RPMS/x86_64/gearmand-$(VERSION)*.rpm .
161 cp ~/rpmbuild/SRPMS/gearmand-$(VERSION)*.rpm .
162+
163+merge-clean:
164+ find ./ | $(GREP) \.orig | xargs rm -f
165+ find ./ | $(GREP) \.rej | xargs rm -f
166+ find ./ | $(GREP) \~$$ | xargs rm -f
167+ bzr unknowns
168
169=== modified file 'benchmark/benchmark.c'
170--- benchmark/benchmark.c 2009-01-19 20:39:38 +0000
171+++ benchmark/benchmark.c 2009-12-30 19:24:13 +0000
172@@ -30,7 +30,7 @@
173
174 gettimeofday(&(benchmark->end), NULL);
175 if (benchmark->end.tv_sec != benchmark->begin.tv_sec)
176- {
177+ {
178 benchmark->total_jobs+= benchmark->jobs;
179
180 printf("[Current: %6"PRIu64" jobs/s, Total: %6"PRIu64" jobs/s]\n",
181
182=== modified file 'benchmark/include.am'
183--- benchmark/include.am 2009-12-18 18:54:27 +0000
184+++ benchmark/include.am 2009-12-30 19:24:13 +0000
185@@ -12,11 +12,11 @@
186
187
188 noinst_PROGRAMS+= \
189- benchmark/blobslap_client \
190- benchmark/blobslap_worker
191+ benchmark/blobslap_client \
192+ benchmark/blobslap_worker
193
194 noinst_HEADERS+= \
195- benchmark/benchmark.h
196+ benchmark/benchmark.h
197
198 noinst_LTLIBRARIES+= benchmark/libbenchmark.la
199 benchmark_libbenchmark_la_SOURCES= benchmark/benchmark.c
200
201=== modified file 'config/pre_hook.sh'
202--- config/pre_hook.sh 2009-09-25 00:04:06 +0000
203+++ config/pre_hook.sh 2009-12-30 19:24:13 +0000
204@@ -6,5 +6,5 @@
205 fi
206 fi
207 echo "Generating docs..."
208-cat libgearman/*.h libgearman-server/*.h | $PERL docs/man_gen.perl > docs/man_list
209+cat libgearman/*.h | $PERL docs/man_gen.perl > docs/man_list
210
211
212=== modified file 'configure.ac'
213--- configure.ac 2009-12-18 19:25:00 +0000
214+++ configure.ac 2009-12-30 19:24:13 +0000
215@@ -6,7 +6,7 @@
216 # the COPYING file in this directory for full text.
217
218 AC_PREREQ(2.59)
219-AC_INIT([gearmand],[0.11],[https://launchpad.net/gearmand])
220+AC_INIT([gearmand],[0.12],[https://launchpad.net/gearmand])
221 AC_CONFIG_SRCDIR(libgearman/gearman.c)
222 AC_CONFIG_AUX_DIR(config)
223 AC_CONFIG_HEADERS([config.h])
224@@ -14,7 +14,7 @@
225
226 PANDORA_CANONICAL_TARGET(require-cxx)
227
228-GEARMAN_LIBRARY_VERSION=3:0:0
229+GEARMAN_LIBRARY_VERSION=4:0:0
230 # | | |
231 # +------+ | +---+
232 # | | |
233@@ -28,21 +28,6 @@
234 # +- increment if interfaces have been added, removed or changed
235 AC_SUBST(GEARMAN_LIBRARY_VERSION)
236
237-GEARMAN_SERVER_LIBRARY_VERSION=0:1:0
238-# | | |
239-# +------+ | +---+
240-# | | |
241-# current:revision:age
242-# | | |
243-# | | +- increment if interfaces have been
244-# | | added, set to zero if interfaces
245-# | | have been removed or changed
246-# | +- increment if source code has changed
247-# | set to zero if current is incremented
248-# +- increment if interfaces have been added, removed
249-# or changed
250-AC_SUBST(GEARMAN_SERVER_LIBRARY_VERSION)
251-
252
253 PANDORA_REQUIRE_PTHREAD
254 PANDORA_REQUIRE_LIBEVENT
255
256=== modified file 'docs/man_gen.perl'
257--- docs/man_gen.perl 2009-09-29 04:34:21 +0000
258+++ docs/man_gen.perl 2009-12-30 19:24:13 +0000
259@@ -81,7 +81,8 @@
260 }
261
262 $func= join(" ", @func_lines);
263- if ($name)
264+
265+ if ($name and ($func =~ m/GEARMAN_API/ or $func =~ m/GEARMAN_DEPRECATED_API/ ))
266 {
267 # We have a function! Output a man page.
268 print " \\\n\t$path/man$section/$name.$section";
269
270=== modified file 'libgearman-server/common.h'
271--- libgearman-server/common.h 2009-10-29 00:11:45 +0000
272+++ libgearman-server/common.h 2009-12-30 19:24:13 +0000
273@@ -16,6 +16,7 @@
274
275 #include "config.h"
276
277+#define GEARMAN_CORE
278 #include "server.h"
279
280 #ifdef HAVE_ASSERT_H
281
282=== renamed file 'libgearman-server/conn.c' => 'libgearman-server/connection.c'
283--- libgearman-server/conn.c 2009-10-29 00:11:45 +0000
284+++ libgearman-server/connection.c 2009-12-30 19:24:13 +0000
285@@ -27,7 +27,7 @@
286 if (con == NULL)
287 return NULL;
288
289- if (gearman_con_set_fd(&(con->con), fd) != GEARMAN_SUCCESS)
290+ if (gearman_connection_set_fd(&(con->con), fd) != GEARMAN_SUCCESS)
291 {
292 gearman_server_con_free(con);
293 return NULL;
294@@ -35,7 +35,7 @@
295
296 con->con.context= data;
297
298- ret= gearman_con_set_events(&(con->con), POLLIN);
299+ ret= gearman_connection_set_events(&(con->con), POLLIN);
300 if (ret != GEARMAN_SUCCESS)
301 {
302 gearman_server_con_free(con);
303@@ -66,14 +66,13 @@
304 }
305 }
306
307- if (gearman_add_con(thread->gearman, &(con->con)) == NULL)
308+ gearman_connection_options_t options[] = { GEARMAN_CON_IGNORE_LOST_CONNECTION, GEARMAN_CON_MAX };
309+ if (gearman_connection_create(thread->gearman, &(con->con), options) == NULL)
310 {
311 free(con);
312 return NULL;
313 }
314
315- gearman_con_add_options(&(con->con), GEARMAN_CON_IGNORE_LOST_CONNECTION);
316-
317 con->options= 0;
318 con->ret= 0;
319 con->io_list= false;
320@@ -122,7 +121,7 @@
321 return;
322 }
323
324- gearman_con_free(&(con->con));
325+ gearman_connection_free(&(con->con));
326
327 if (con->proc_list)
328 gearman_server_con_proc_remove(con);
329@@ -162,19 +161,19 @@
330 free(con);
331 }
332
333-gearman_con_st *gearman_server_con_con(gearman_server_con_st *con)
334+gearman_connection_st *gearman_server_con_con(gearman_server_con_st *con)
335 {
336 return &con->con;
337 }
338
339 void *gearman_server_con_data(gearman_server_con_st *con)
340 {
341- return gearman_con_context(&(con->con));
342+ return gearman_connection_context(&(con->con));
343 }
344
345 void gearman_server_con_set_data(gearman_server_con_st *con, void *data)
346 {
347- gearman_con_set_context(&(con->con), data);
348+ gearman_connection_set_context(&(con->con), data);
349 }
350
351 const char *gearman_server_con_host(gearman_server_con_st *con)
352
353=== renamed file 'libgearman-server/conn.h' => 'libgearman-server/connection.h'
354--- libgearman-server/conn.h 2009-10-29 00:11:45 +0000
355+++ libgearman-server/connection.h 2009-12-30 19:24:13 +0000
356@@ -58,7 +58,7 @@
357 * Get gearman connection pointer the server connection uses.
358 */
359 GEARMAN_API
360-gearman_con_st *gearman_server_con_con(gearman_server_con_st *con);
361+gearman_connection_st *gearman_server_con_con(gearman_server_con_st *con);
362
363 /**
364 * Get application data pointer.
365
366=== modified file 'libgearman-server/constants.h'
367--- libgearman-server/constants.h 2009-10-29 00:11:45 +0000
368+++ libgearman-server/constants.h 2009-12-30 19:24:13 +0000
369@@ -212,7 +212,7 @@
370 gearman_queue_add_fn *add_fn,
371 void *add_context);
372
373-typedef gearman_return_t (gearman_con_add_fn)(gearman_con_st *con);
374+typedef gearman_return_t (gearman_connection_add_fn)(gearman_connection_st *con);
375
376 /** @} */
377
378
379=== modified file 'libgearman-server/gearmand.c'
380--- libgearman-server/gearmand.c 2009-12-02 19:09:59 +0000
381+++ libgearman-server/gearmand.c 2009-12-30 19:24:13 +0000
382@@ -166,7 +166,7 @@
383 }
384
385 gearman_return_t gearmand_port_add(gearmand_st *gearmand, in_port_t port,
386- gearman_con_add_fn *function)
387+ gearman_connection_add_fn *function)
388 {
389 gearmand_port_st *port_list;
390
391
392=== modified file 'libgearman-server/gearmand.h'
393--- libgearman-server/gearmand.h 2009-10-29 22:01:39 +0000
394+++ libgearman-server/gearmand.h 2009-12-30 19:24:13 +0000
395@@ -106,7 +106,7 @@
396 */
397 GEARMAN_API
398 gearman_return_t gearmand_port_add(gearmand_st *gearmand, in_port_t port,
399- gearman_con_add_fn *function);
400+ gearman_connection_add_fn *function);
401
402 /**
403 * Run the server instance.
404
405=== modified file 'libgearman-server/gearmand_con.c'
406--- libgearman-server/gearmand_con.c 2009-12-02 19:09:59 +0000
407+++ libgearman-server/gearmand_con.c 2009-12-30 19:24:13 +0000
408@@ -37,7 +37,7 @@
409
410 gearman_return_t gearmand_con_create(gearmand_st *gearmand, int fd,
411 const char *host, const char *port,
412- gearman_con_add_fn *add_fn)
413+ gearman_connection_add_fn *add_fn)
414 {
415 gearmand_con_st *dcon;
416 gearmand_con_st *free_dcon_list;
417@@ -179,14 +179,14 @@
418 }
419 }
420
421-gearman_return_t gearmand_con_watch(gearman_con_st *con, short events,
422+gearman_return_t gearmand_connection_watch(gearman_connection_st *con, short events,
423 void *context __attribute__ ((unused)))
424 {
425 (void) context;
426 gearmand_con_st *dcon;
427 short set_events= 0;
428
429- dcon= (gearmand_con_st *)gearman_con_context(con);
430+ dcon= (gearmand_con_st *)gearman_connection_context(con);
431 dcon->con= con;
432
433 if (events & POLLIN)
434@@ -238,7 +238,7 @@
435 if (events & EV_WRITE)
436 revents|= POLLOUT;
437
438- ret= gearman_con_set_revents(dcon->con, revents);
439+ ret= gearman_connection_set_revents(dcon->con, revents);
440 if (ret != GEARMAN_SUCCESS)
441 {
442 gearmand_con_free(dcon);
443
444=== modified file 'libgearman-server/gearmand_con.h'
445--- libgearman-server/gearmand_con.h 2009-10-29 20:18:00 +0000
446+++ libgearman-server/gearmand_con.h 2009-12-30 19:24:13 +0000
447@@ -41,7 +41,7 @@
448 GEARMAN_API
449 gearman_return_t gearmand_con_create(gearmand_st *gearmand, int fd,
450 const char *host, const char *port,
451- gearman_con_add_fn *add_fn);
452+ gearman_connection_add_fn *add_fn);
453
454 /**
455 * Free resources used by a connection.
456@@ -60,7 +60,7 @@
457 * Callback function used for setting events in libevent.
458 */
459 GEARMAN_API
460-gearman_return_t gearmand_con_watch(gearman_con_st *con, short events,
461+gearman_return_t gearmand_connection_watch(gearman_connection_st *con, short events,
462 void *context);
463
464 /** @} */
465
466=== modified file 'libgearman-server/gearmand_thread.c'
467--- libgearman-server/gearmand_thread.c 2009-12-02 19:09:59 +0000
468+++ libgearman-server/gearmand_thread.c 2009-12-30 19:24:13 +0000
469@@ -65,7 +65,7 @@
470 gearman_server_thread_set_log_fn(&(thread->server_thread), _log, thread,
471 gearmand->verbose);
472 gearman_server_thread_set_event_watch(&(thread->server_thread),
473- gearmand_con_watch, NULL);
474+ gearmand_connection_watch, NULL);
475
476 thread->options= 0;
477 thread->count= 0;
478
479=== modified file 'libgearman-server/include.am'
480--- libgearman-server/include.am 2009-12-18 19:25:00 +0000
481+++ libgearman-server/include.am 2009-12-30 19:24:13 +0000
482@@ -30,10 +30,10 @@
483 QUEUE_LIBPQ_C= libgearman-server/queue_libpq.c
484 endif
485
486-lib_LTLIBRARIES+= libgearman-server/libgearman-server.la
487-
488-
489-nobase_pkginclude_HEADERS += \
490+noinst_LTLIBRARIES+= libgearman-server/libgearman-server.la
491+
492+
493+noinst_HEADERS += \
494 $(QUEUE_LIBDRIZZLE_H) \
495 $(QUEUE_LIBMEMCACHED_H) \
496 $(QUEUE_LIBPQ_H) \
497@@ -41,7 +41,7 @@
498 libgearman-server/client.h \
499 libgearman-server/conf.h \
500 libgearman-server/conf_module.h \
501- libgearman-server/conn.h \
502+ libgearman-server/connection.h \
503 libgearman-server/constants.h \
504 libgearman-server/function.h \
505 libgearman-server/gearmand.h \
506@@ -66,7 +66,7 @@
507 libgearman-server/client.c \
508 libgearman-server/conf.c \
509 libgearman-server/conf_module.c \
510- libgearman-server/conn.c \
511+ libgearman-server/connection.c \
512 libgearman-server/function.c \
513 libgearman-server/gearmand.c \
514 libgearman-server/gearmand_con.c \
515@@ -82,15 +82,11 @@
516 ${AM_CFLAGS} \
517 -DBUILDING_LIBGEARMAN
518
519-libgearman_server_libgearman_server_la_LDFLAGS= \
520- $(AM_LDFLAGS) \
521- -version-info \
522- $(GEARMAN_SERVER_LIBRARY_VERSION)
523-
524 libgearman_server_libgearman_server_la_LIBADD= \
525 $(LTLIBDRIZZLE) \
526 $(LTLIBEVENT) \
527 $(LTLIBMEMCACHED) \
528 $(LTLIBPQ) \
529 $(LTLIBSQLITE3) \
530- libgearman/libgearman.la
531+ libgearman/libgearman.la \
532+ libgearman/libgearmancore.la
533
534=== modified file 'libgearman-server/packet.c'
535--- libgearman-server/packet.c 2009-10-29 00:11:45 +0000
536+++ libgearman-server/packet.c 2009-12-30 19:24:13 +0000
537@@ -101,8 +101,8 @@
538 if (server_packet == NULL)
539 return GEARMAN_MEMORY_ALLOCATION_FAILURE;
540
541- if (gearman_add_packet(con->thread->gearman,
542- &(server_packet->packet)) == NULL)
543+ if (gearman_packet_create(con->thread->gearman,
544+ &(server_packet->packet)) == NULL)
545 {
546 gearman_server_packet_free(server_packet, con->thread, false);
547 return GEARMAN_MEMORY_ALLOCATION_FAILURE;
548@@ -117,7 +117,7 @@
549 {
550 arg_size = va_arg(ap, size_t);
551
552- ret= gearman_packet_add_arg(&(server_packet->packet), arg, arg_size);
553+ ret= gearman_packet_create_arg(&(server_packet->packet), arg, arg_size);
554 if (ret != GEARMAN_SUCCESS)
555 {
556 va_end(ap);
557@@ -140,7 +140,7 @@
558 }
559
560 if (take_data)
561- server_packet->packet.options|= GEARMAN_PACKET_FREE_DATA;
562+ server_packet->packet.options.free_data= true;
563
564 GEARMAN_SERVER_THREAD_LOCK(con->thread)
565 GEARMAN_FIFO_ADD(con->io_packet, server_packet,)
566
567=== modified file 'libgearman-server/protocol_http.c'
568--- libgearman-server/protocol_http.c 2009-10-29 20:18:00 +0000
569+++ libgearman-server/protocol_http.c 2009-12-30 19:24:13 +0000
570@@ -37,12 +37,12 @@
571 } gearman_protocol_http_st;
572
573 /* Protocol callback functions. */
574-static gearman_return_t _http_con_add(gearman_con_st *con);
575-static void _http_free(gearman_con_st *con, void *context);
576-static size_t _http_pack(const gearman_packet_st *packet, gearman_con_st *con,
577+static gearman_return_t _http_con_add(gearman_connection_st *con);
578+static void _http_free(gearman_connection_st *con, void *context);
579+static size_t _http_pack(const gearman_packet_st *packet, gearman_connection_st *con,
580 void *data, size_t data_size,
581 gearman_return_t *ret_ptr);
582-static size_t _http_unpack(gearman_packet_st *packet, gearman_con_st *con,
583+static size_t _http_unpack(gearman_packet_st *packet, gearman_connection_st *con,
584 const void *data, size_t data_size,
585 gearman_return_t *ret_ptr);
586
587@@ -114,7 +114,7 @@
588 * Static definitions
589 */
590
591-static gearman_return_t _http_con_add(gearman_con_st *con)
592+static gearman_return_t _http_con_add(gearman_connection_st *con)
593 {
594 gearman_protocol_http_st *http;
595
596@@ -128,28 +128,28 @@
597 http->background= false;
598 http->keep_alive= false;
599
600- gearman_con_set_protocol_context(con, http);
601- gearman_con_set_protocol_context_free_fn(con, _http_free);
602- gearman_con_set_packet_pack_fn(con, _http_pack);
603- gearman_con_set_packet_unpack_fn(con, _http_unpack);
604+ gearman_connection_set_protocol_context(con, http);
605+ gearman_connection_set_protocol_context_free_fn(con, _http_free);
606+ gearman_connection_set_packet_pack_fn(con, _http_pack);
607+ gearman_connection_set_packet_unpack_fn(con, _http_unpack);
608
609 return GEARMAN_SUCCESS;
610 }
611
612-static void _http_free(gearman_con_st *con __attribute__ ((unused)),
613+static void _http_free(gearman_connection_st *con __attribute__ ((unused)),
614 void *context)
615 {
616 free((gearman_protocol_http_st *)context);
617 }
618
619-static size_t _http_pack(const gearman_packet_st *packet, gearman_con_st *con,
620+static size_t _http_pack(const gearman_packet_st *packet, gearman_connection_st *con,
621 void *data, size_t data_size,
622 gearman_return_t *ret_ptr)
623 {
624 size_t pack_size;
625 gearman_protocol_http_st *http;
626
627- http= (gearman_protocol_http_st *)gearman_con_protocol_context(con);
628+ http= (gearman_protocol_http_st *)gearman_connection_protocol_context(con);
629
630 if (packet->command != GEARMAN_COMMAND_WORK_COMPLETE &&
631 packet->command != GEARMAN_COMMAND_WORK_FAIL &&
632@@ -178,14 +178,16 @@
633 return 0;
634 }
635
636- if (!(http->keep_alive))
637- gearman_con_add_options(con, GEARMAN_CON_CLOSE_AFTER_FLUSH);
638+ if (! (http->keep_alive))
639+ {
640+ gearman_connection_set_option(con, GEARMAN_CON_CLOSE_AFTER_FLUSH, true);
641+ }
642
643 *ret_ptr= GEARMAN_SUCCESS;
644 return pack_size;
645 }
646
647-static size_t _http_unpack(gearman_packet_st *packet, gearman_con_st *con,
648+static size_t _http_unpack(gearman_packet_st *packet, gearman_connection_st *con,
649 const void *data, size_t data_size,
650 gearman_return_t *ret_ptr)
651 {
652@@ -214,7 +216,7 @@
653 return offset;
654 }
655
656- http= (gearman_protocol_http_st *)gearman_con_protocol_context(con);
657+ http= (gearman_protocol_http_st *)gearman_connection_protocol_context(con);
658 http->background= false;
659 http->keep_alive= false;
660
661@@ -355,11 +357,11 @@
662 if (*ret_ptr != GEARMAN_SUCCESS)
663 return 0;
664
665- *ret_ptr= gearman_packet_add_arg(packet, uri, (size_t)uri_size + 1);
666+ *ret_ptr= gearman_packet_create_arg(packet, uri, (size_t)uri_size + 1);
667 if (*ret_ptr != GEARMAN_SUCCESS)
668 return 0;
669
670- *ret_ptr= gearman_packet_add_arg(packet, unique, unique_size + 1);
671+ *ret_ptr= gearman_packet_create_arg(packet, unique, unique_size + 1);
672 if (*ret_ptr != GEARMAN_SUCCESS)
673 return 0;
674
675
676=== modified file 'libgearman-server/server.c'
677--- libgearman-server/server.c 2009-10-29 22:01:39 +0000
678+++ libgearman-server/server.c 2009-12-30 19:24:13 +0000
679@@ -111,7 +111,7 @@
680 memset(server->unique_hash, 0,
681 sizeof(gearman_server_job_st *) * GEARMAN_JOB_HASH_SIZE);
682
683- server->gearman= gearman_create(&(server->gearman_static));
684+ server->gearman= gearman_universal_create(&(server->gearman_universal_static), NULL);
685 if (server->gearman == NULL)
686 {
687 gearman_server_free(server);
688@@ -180,7 +180,7 @@
689 }
690
691 if (server->gearman != NULL)
692- gearman_free(server->gearman);
693+ gearman_universal_free(server->gearman);
694
695 if (server->options & GEARMAN_SERVER_ALLOCATED)
696 free(server);
697@@ -237,7 +237,7 @@
698 if (ret != GEARMAN_SUCCESS)
699 return ret;
700
701- packet->options&= (gearman_packet_options_t)~GEARMAN_PACKET_FREE_DATA;
702+ packet->options.free_data= false;
703
704 break;
705
706@@ -284,7 +284,9 @@
707 packet->data_size, priority,
708 server_client, &ret);
709 if (ret == GEARMAN_SUCCESS)
710- packet->options&= (gearman_packet_options_t)~GEARMAN_PACKET_FREE_DATA;
711+ {
712+ packet->options.free_data= false;
713+ }
714 else if (ret == GEARMAN_JOB_QUEUE_FULL)
715 {
716 return _server_error_packet(server_con, "queue_full",
717@@ -913,8 +915,8 @@
718 return GEARMAN_MEMORY_ALLOCATION_FAILURE;
719 }
720
721- if (gearman_add_packet(server_con->thread->gearman,
722- &(server_packet->packet)) == NULL)
723+ if (gearman_packet_create(server_con->thread->gearman,
724+ &(server_packet->packet)) == NULL)
725 {
726 free(data);
727 gearman_server_packet_free(server_packet, server_con->thread, false);
728@@ -923,8 +925,9 @@
729
730 server_packet->packet.magic= GEARMAN_MAGIC_TEXT;
731 server_packet->packet.command= GEARMAN_COMMAND_TEXT;
732- server_packet->packet.options|= (GEARMAN_PACKET_COMPLETE |
733- GEARMAN_PACKET_FREE_DATA);
734+ server_packet->packet.options.complete= true;
735+ server_packet->packet.options.free_data= true;
736+
737 server_packet->packet.data= data;
738 server_packet->packet.data_size= strlen(data);
739
740@@ -956,11 +959,11 @@
741
742 if (packet->data_size > 0)
743 {
744- if (packet->options & GEARMAN_PACKET_FREE_DATA &&
745+ if (packet->options.free_data &&
746 server_client->job_next == NULL)
747 {
748 data= (uint8_t *)(packet->data);
749- packet->options&= (gearman_packet_options_t)~GEARMAN_PACKET_FREE_DATA;
750+ packet->options.free_data= false;
751 }
752 else
753 {
754
755=== modified file 'libgearman-server/server.h'
756--- libgearman-server/server.h 2009-10-29 22:01:39 +0000
757+++ libgearman-server/server.h 2009-12-30 19:24:13 +0000
758@@ -21,7 +21,7 @@
759 #include <libgearman-server/structs.h>
760 #include <libgearman-server/conf.h>
761 #include <libgearman-server/conf_module.h>
762-#include <libgearman-server/conn.h>
763+#include <libgearman-server/connection.h>
764 #include <libgearman-server/packet.h>
765 #include <libgearman-server/function.h>
766 #include <libgearman-server/client.h>
767
768=== modified file 'libgearman-server/structs.h'
769--- libgearman-server/structs.h 2009-10-29 22:01:39 +0000
770+++ libgearman-server/structs.h 2009-12-30 19:24:13 +0000
771@@ -39,7 +39,7 @@
772 uint32_t free_job_count;
773 uint32_t free_client_count;
774 uint32_t free_worker_count;
775- gearman_st *gearman;
776+ gearman_universal_st *gearman;
777 gearman_server_thread_st *thread_list;
778 gearman_server_function_st *function_list;
779 gearman_server_packet_st *free_packet_list;
780@@ -53,7 +53,7 @@
781 gearman_queue_flush_fn *queue_flush_fn;
782 gearman_queue_done_fn *queue_done_fn;
783 gearman_queue_replay_fn *queue_replay_fn;
784- gearman_st gearman_static;
785+ gearman_universal_st gearman_universal_static;
786 pthread_mutex_t proc_lock;
787 pthread_cond_t proc_cond;
788 pthread_t proc_id;
789@@ -73,7 +73,7 @@
790 uint32_t proc_count;
791 uint32_t free_con_count;
792 uint32_t free_packet_count;
793- gearman_st *gearman;
794+ gearman_universal_st *gearman;
795 gearman_server_st *server;
796 gearman_server_thread_st *next;
797 gearman_server_thread_st *prev;
798@@ -86,7 +86,7 @@
799 gearman_server_con_st *proc_list;
800 gearman_server_con_st *free_con_list;
801 gearman_server_packet_st *free_packet_list;
802- gearman_st gearman_static;
803+ gearman_universal_st gearman_universal_static;
804 pthread_mutex_t lock;
805 };
806
807@@ -95,7 +95,7 @@
808 */
809 struct gearman_server_con_st
810 {
811- gearman_con_st con; /* This must be the first struct member. */
812+ gearman_connection_st con; /* This must be the first struct member. */
813 gearman_server_con_options_t options;
814 gearman_return_t ret;
815 bool io_list;
816@@ -250,7 +250,7 @@
817 in_port_t port;
818 uint32_t listen_count;
819 gearmand_st *gearmand;
820- gearman_con_add_fn *add_fn;
821+ gearman_connection_add_fn *add_fn;
822 int *listen_fd;
823 struct event *listen_event;
824 };
825@@ -290,8 +290,8 @@
826 gearmand_con_st *next;
827 gearmand_con_st *prev;
828 gearman_server_con_st *server_con;
829- gearman_con_st *con;
830- gearman_con_add_fn *add_fn;
831+ gearman_connection_st *con;
832+ gearman_connection_add_fn *add_fn;
833 struct event event;
834 char host[NI_MAXHOST];
835 char port[NI_MAXSERV];
836
837=== modified file 'libgearman-server/thread.c'
838--- libgearman-server/thread.c 2009-10-29 20:18:00 +0000
839+++ libgearman-server/thread.c 2009-12-30 19:24:13 +0000
840@@ -107,18 +107,16 @@
841 return NULL;
842 }
843
844- GEARMAN_LIST_ADD(server->thread, thread,)
845+ GEARMAN_LIST_ADD(server->thread, thread,);
846
847- thread->gearman= gearman_create(&(thread->gearman_static));
848+ gearman_options_t options[]= { GEARMAN_NON_BLOCKING, GEARMAN_DONT_TRACK_PACKETS, GEARMAN_MAX};
849+ thread->gearman= gearman_universal_create(&(thread->gearman_universal_static), options);
850 if (thread->gearman == NULL)
851 {
852 gearman_server_thread_free(thread);
853 return NULL;
854 }
855
856- gearman_set_options(thread->gearman,
857- GEARMAN_NON_BLOCKING | GEARMAN_DONT_TRACK_PACKETS);
858-
859 return thread;
860 }
861
862@@ -147,7 +145,7 @@
863 }
864
865 if (thread->gearman != NULL)
866- gearman_free(thread->gearman);
867+ gearman_universal_free(thread->gearman);
868
869 pthread_mutex_destroy(&(thread->lock));
870
871@@ -159,12 +157,12 @@
872
873 const char *gearman_server_thread_error(gearman_server_thread_st *thread)
874 {
875- return gearman_error(thread->gearman);
876+ return gearman_universal_error(thread->gearman);
877 }
878
879 int gearman_server_thread_errno(gearman_server_thread_st *thread)
880 {
881- return gearman_errno(thread->gearman);
882+ return gearman_universal_errno(thread->gearman);
883 }
884
885 void gearman_server_thread_set_event_watch(gearman_server_thread_st *thread,
886@@ -196,7 +194,7 @@
887 gearman_server_thread_run(gearman_server_thread_st *thread,
888 gearman_return_t *ret_ptr)
889 {
890- gearman_con_st *con;
891+ gearman_connection_st *con;
892 gearman_server_con_st *server_con;
893
894 /* If we are multi-threaded, we may have packets to flush or connections that
895@@ -295,7 +293,7 @@
896 return GEARMAN_MEMORY_ALLOCATION_FAILURE;
897 }
898
899- (void)gearman_con_recv(&(con->con), &(con->packet->packet), &ret, true);
900+ (void)gearman_connection_recv(&(con->con), &(con->packet->packet), &ret, true);
901 if (ret != GEARMAN_SUCCESS)
902 {
903 if (ret == GEARMAN_IO_WAIT)
904@@ -343,7 +341,7 @@
905
906 while (con->io_packet_list != NULL)
907 {
908- ret= gearman_con_send(&(con->con), &(con->io_packet_list->packet),
909+ ret= gearman_connection_send(&(con->con), &(con->io_packet_list->packet),
910 con->io_packet_list->next == NULL ? true : false);
911 if (ret != GEARMAN_SUCCESS)
912 return ret;
913@@ -357,7 +355,7 @@
914 }
915
916 /* Clear the POLLOUT flag. */
917- return gearman_con_set_events(&(con->con), POLLIN);
918+ return gearman_connection_set_events(&(con->con), POLLIN);
919 }
920
921 static gearman_return_t _proc_thread_start(gearman_server_st *server)
922
923=== modified file 'libgearman/client.c'
924--- libgearman/client.c 2009-12-16 22:46:32 +0000
925+++ libgearman/client.c 2009-12-30 19:24:13 +0000
926@@ -22,7 +22,7 @@
927 /**
928 * Allocate a client structure.
929 */
930-static gearman_client_st *_client_allocate(gearman_client_st *client);
931+static gearman_client_st *_client_allocate(gearman_client_st *client, bool is_clone);
932
933 /**
934 * Callback function used when parsing server lists.
935@@ -83,18 +83,6 @@
936 */
937 static gearman_return_t _client_do_fail(gearman_task_st *task);
938
939-/**
940- * Initialize a task structure.
941- *
942- * @param[in] client Structure previously initialized with
943- * gearman_client_create() or gearman_client_clone().
944- * @param[in] task Caller allocated structure, or NULL to allocate one.
945- * @return On success, a pointer to the (possibly allocated) structure. On
946- * failure this will be NULL.
947- */
948-static gearman_task_st *_task_create(gearman_client_st *client,
949- gearman_task_st *task);
950-
951 /** @} */
952
953 /*
954@@ -103,35 +91,34 @@
955
956 gearman_client_st *gearman_client_create(gearman_client_st *client)
957 {
958- client= _client_allocate(client);
959- if (client == NULL)
960- return NULL;
961-
962- client->gearman= gearman_create(&(client->gearman_static));
963- if (client->gearman == NULL)
964- {
965- gearman_client_free(client);
966- return NULL;
967- }
968-
969- return client;
970+ return _client_allocate(client, false);
971 }
972
973 gearman_client_st *gearman_client_clone(gearman_client_st *client,
974 const gearman_client_st *from)
975 {
976- if (from == NULL)
977- return NULL;
978-
979- client= _client_allocate(client);
980+ gearman_universal_st *check;
981+
982+ if (! from)
983+ {
984+ return _client_allocate(client, false);
985+ }
986+
987+ client= _client_allocate(client, false);
988+
989 if (client == NULL)
990- return NULL;
991-
992- client->options|= (from->options &
993- (gearman_client_options_t)~GEARMAN_CLIENT_ALLOCATED);
994-
995- client->gearman= gearman_clone(&(client->gearman_static), from->gearman);
996- if (client->gearman == NULL)
997+ {
998+ return client;
999+ }
1000+
1001+ client->options.non_blocking= from->options.non_blocking;
1002+ client->options.task_in_use= from->options.task_in_use;
1003+ client->options.unbuffered_result= from->options.unbuffered_result;
1004+ client->options.no_new= from->options.no_new;
1005+ client->options.free_tasks= from->options.free_tasks;
1006+
1007+ check= gearman_universal_clone((&client->universal), &(from->universal));
1008+ if (! check)
1009 {
1010 gearman_client_free(client);
1011 return NULL;
1012@@ -142,68 +129,122 @@
1013
1014 void gearman_client_free(gearman_client_st *client)
1015 {
1016- if (client->options & GEARMAN_CLIENT_TASK_IN_USE)
1017+ if (client->options.task_in_use)
1018 gearman_task_free(&(client->do_task));
1019
1020 gearman_client_task_free_all(client);
1021
1022- if (client->gearman != NULL)
1023- gearman_free(client->gearman);
1024+ gearman_universal_free(&client->universal);
1025
1026- if (client->options & GEARMAN_CLIENT_ALLOCATED)
1027+ if (client->options.allocated)
1028 free(client);
1029 }
1030
1031 const char *gearman_client_error(const gearman_client_st *client)
1032 {
1033- return gearman_error(client->gearman);
1034+ return gearman_universal_error(&client->universal);
1035 }
1036
1037 int gearman_client_errno(const gearman_client_st *client)
1038 {
1039- return gearman_errno(client->gearman);
1040+ return gearman_universal_errno(&client->universal);
1041 }
1042
1043 gearman_client_options_t gearman_client_options(const gearman_client_st *client)
1044 {
1045- return client->options;
1046+ gearman_client_options_t options;
1047+ memset(&options, 0, sizeof(gearman_client_options_t));
1048+
1049+ if (client->options.allocated)
1050+ options|= GEARMAN_CLIENT_ALLOCATED;
1051+ if (client->options.non_blocking)
1052+ options|= GEARMAN_CLIENT_NON_BLOCKING;
1053+ if (client->options.task_in_use)
1054+ options|= GEARMAN_CLIENT_TASK_IN_USE;
1055+ if (client->options.unbuffered_result)
1056+ options|= GEARMAN_CLIENT_UNBUFFERED_RESULT;
1057+ if (client->options.no_new)
1058+ options|= GEARMAN_CLIENT_NO_NEW;
1059+ if (client->options.free_tasks)
1060+ options|= GEARMAN_CLIENT_FREE_TASKS;
1061+
1062+ return options;
1063 }
1064
1065 void gearman_client_set_options(gearman_client_st *client,
1066 gearman_client_options_t options)
1067 {
1068- /* Call this to catch any special triggers. */
1069- gearman_client_add_options(client, options);
1070-
1071- client->options= options;
1072+ gearman_client_options_t usable_options[]= {
1073+ GEARMAN_CLIENT_NON_BLOCKING,
1074+ GEARMAN_CLIENT_UNBUFFERED_RESULT,
1075+ GEARMAN_CLIENT_FREE_TASKS,
1076+ GEARMAN_CLIENT_MAX
1077+ };
1078+
1079+ gearman_client_options_t *ptr;
1080+
1081+
1082+ for (ptr= usable_options; *ptr != GEARMAN_CLIENT_MAX ; ptr++)
1083+ {
1084+ if (options & *ptr)
1085+ {
1086+ gearman_client_add_options(client, *ptr);
1087+ }
1088+ else
1089+ {
1090+ gearman_client_remove_options(client, *ptr);
1091+ }
1092+ }
1093 }
1094
1095 void gearman_client_add_options(gearman_client_st *client,
1096 gearman_client_options_t options)
1097 {
1098 if (options & GEARMAN_CLIENT_NON_BLOCKING)
1099- gearman_add_options(client->gearman, GEARMAN_NON_BLOCKING);
1100-
1101- client->options|= options;
1102+ {
1103+ gearman_universal_add_options(&client->universal, GEARMAN_NON_BLOCKING);
1104+ client->options.non_blocking= true;
1105+ }
1106+
1107+ if (options & GEARMAN_CLIENT_UNBUFFERED_RESULT)
1108+ {
1109+ client->options.unbuffered_result= true;
1110+ }
1111+
1112+ if (options & GEARMAN_CLIENT_FREE_TASKS)
1113+ {
1114+ client->options.free_tasks= true;
1115+ }
1116 }
1117
1118 void gearman_client_remove_options(gearman_client_st *client,
1119 gearman_client_options_t options)
1120 {
1121 if (options & GEARMAN_CLIENT_NON_BLOCKING)
1122- gearman_remove_options(client->gearman, GEARMAN_NON_BLOCKING);
1123-
1124- client->options&= ~options;
1125+ {
1126+ gearman_universal_remove_options(&client->universal, GEARMAN_NON_BLOCKING);
1127+ client->options.non_blocking= false;
1128+ }
1129+
1130+ if (options & GEARMAN_CLIENT_UNBUFFERED_RESULT)
1131+ {
1132+ client->options.unbuffered_result= false;
1133+ }
1134+
1135+ if (options & GEARMAN_CLIENT_FREE_TASKS)
1136+ {
1137+ client->options.free_tasks= false;
1138+ }
1139 }
1140
1141 int gearman_client_timeout(gearman_client_st *client)
1142 {
1143- return gearman_timeout(client->gearman);
1144+ return gearman_universal_timeout(&client->universal);
1145 }
1146
1147 void gearman_client_set_timeout(gearman_client_st *client, int timeout)
1148 {
1149- gearman_set_timeout(client->gearman, timeout);
1150+ gearman_universal_set_timeout(&client->universal, timeout);
1151 }
1152
1153 void *gearman_client_context(const gearman_client_st *client)
1154@@ -220,34 +261,27 @@
1155 gearman_log_fn *function, const void *context,
1156 gearman_verbose_t verbose)
1157 {
1158- gearman_set_log_fn(client->gearman, function, context, verbose);
1159-}
1160-
1161-void gearman_client_set_event_watch_fn(gearman_client_st *client,
1162- gearman_event_watch_fn *function,
1163- const void *context)
1164-{
1165- gearman_set_event_watch_fn(client->gearman, function, context);
1166+ gearman_set_log_fn(&client->universal, function, context, verbose);
1167 }
1168
1169 void gearman_client_set_workload_malloc_fn(gearman_client_st *client,
1170 gearman_malloc_fn *function,
1171 const void *context)
1172 {
1173- gearman_set_workload_malloc_fn(client->gearman, function, context);
1174+ gearman_set_workload_malloc_fn(&client->universal, function, context);
1175 }
1176
1177 void gearman_client_set_workload_free_fn(gearman_client_st *client,
1178 gearman_free_fn *function,
1179 const void *context)
1180 {
1181- gearman_set_workload_free_fn(client->gearman, function, context);
1182+ gearman_set_workload_free_fn(&client->universal, function, context);
1183 }
1184
1185 gearman_return_t gearman_client_add_server(gearman_client_st *client,
1186 const char *host, in_port_t port)
1187 {
1188- if (gearman_add_con_args(client->gearman, NULL, host, port) == NULL)
1189+ if (gearman_connection_create_args(&client->universal, NULL, host, port) == NULL)
1190 return GEARMAN_MEMORY_ALLOCATION_FAILURE;
1191
1192 return GEARMAN_SUCCESS;
1193@@ -261,12 +295,12 @@
1194
1195 void gearman_client_remove_servers(gearman_client_st *client)
1196 {
1197- gearman_free_all_cons(client->gearman);
1198+ gearman_free_all_cons(&client->universal);
1199 }
1200
1201 gearman_return_t gearman_client_wait(gearman_client_st *client)
1202 {
1203- return gearman_wait(client->gearman);
1204+ return gearman_wait(&client->universal);
1205 }
1206
1207 void *gearman_client_do(gearman_client_st *client, const char *function_name,
1208@@ -355,14 +389,14 @@
1209 {
1210 gearman_return_t ret;
1211
1212- if (!(client->options & GEARMAN_CLIENT_TASK_IN_USE))
1213+ if (! (client->options.task_in_use))
1214 {
1215 (void)gearman_client_add_task_status(client, &(client->do_task), client,
1216 job_handle, &ret);
1217 if (ret != GEARMAN_SUCCESS)
1218 return ret;
1219
1220- client->options|= GEARMAN_CLIENT_TASK_IN_USE;
1221+ client->options.task_in_use= true;
1222 }
1223
1224 gearman_client_clear_fn(client);
1225@@ -380,7 +414,7 @@
1226 *denominator= client->do_task.denominator;
1227
1228 gearman_task_free(&(client->do_task));
1229- client->options&= (gearman_client_options_t)~GEARMAN_CLIENT_TASK_IN_USE;
1230+ client->options.task_in_use= false;
1231 }
1232
1233 return ret;
1234@@ -390,30 +424,7 @@
1235 const void *workload,
1236 size_t workload_size)
1237 {
1238- return gearman_echo(client->gearman, workload, workload_size);
1239-}
1240-
1241-void gearman_task_free(gearman_task_st *task)
1242-{
1243- if (task->options & GEARMAN_TASK_SEND_IN_USE)
1244- gearman_packet_free(&(task->send));
1245-
1246- if (task != &(task->client->do_task) && task->context != NULL &&
1247- task->client->task_context_free_fn != NULL)
1248- {
1249- task->client->task_context_free_fn(task, (void *)task->context);
1250- }
1251-
1252- if (task->client->task_list == task)
1253- task->client->task_list= task->next;
1254- if (task->prev != NULL)
1255- task->prev->next= task->next;
1256- if (task->next != NULL)
1257- task->next->prev= task->prev;
1258- task->client->task_count--;
1259-
1260- if (task->options & GEARMAN_TASK_ALLOCATED)
1261- free(task);
1262+ return gearman_echo(&client->universal, workload, workload_size);
1263 }
1264
1265 void gearman_client_task_free_all(gearman_client_st *client)
1266@@ -523,7 +534,7 @@
1267 const void *args[1];
1268 size_t args_size[1];
1269
1270- task= _task_create(client, task);
1271+ task= gearman_task_create(client, task);
1272 if (task == NULL)
1273 {
1274 *ret_ptr= GEARMAN_MEMORY_ALLOCATION_FAILURE;
1275@@ -535,15 +546,15 @@
1276
1277 args[0]= job_handle;
1278 args_size[0]= strlen(job_handle);
1279- *ret_ptr= gearman_add_packet_args(client->gearman, &(task->send),
1280- GEARMAN_MAGIC_REQUEST,
1281- GEARMAN_COMMAND_GET_STATUS,
1282- args, args_size, 1);
1283+ *ret_ptr= gearman_packet_create_args(&client->universal, &(task->send),
1284+ GEARMAN_MAGIC_REQUEST,
1285+ GEARMAN_COMMAND_GET_STATUS,
1286+ args, args_size, 1);
1287 if (*ret_ptr == GEARMAN_SUCCESS)
1288 {
1289 client->new_tasks++;
1290 client->running_tasks++;
1291- task->options|= GEARMAN_TASK_SEND_IN_USE;
1292+ task->options.send_in_use= true;
1293 }
1294
1295 return task;
1296@@ -574,7 +585,7 @@
1297 }
1298
1299 void gearman_client_set_status_fn(gearman_client_st *client,
1300- gearman_status_fn *function)
1301+ gearman_universal_status_fn *function)
1302 {
1303 client->status_fn= function;
1304 }
1305@@ -611,11 +622,9 @@
1306
1307 gearman_return_t gearman_client_run_tasks(gearman_client_st *client)
1308 {
1309- gearman_options_t options;
1310 gearman_return_t ret;
1311
1312- options= client->gearman->options;
1313- client->gearman->options|= GEARMAN_NON_BLOCKING;
1314+ gearman_universal_push_non_blocking(&client->universal);
1315
1316 switch(client->state)
1317 {
1318@@ -623,7 +632,7 @@
1319 while (1)
1320 {
1321 /* Start any new tasks. */
1322- if (client->new_tasks > 0 && !(client->options & GEARMAN_CLIENT_NO_NEW))
1323+ if (client->new_tasks > 0 && ! (client->options.no_new))
1324 {
1325 for (client->task= client->task_list; client->task != NULL;
1326 client->task= client->task->next)
1327@@ -636,24 +645,24 @@
1328 if (ret != GEARMAN_SUCCESS && ret != GEARMAN_IO_WAIT)
1329 {
1330 client->state= GEARMAN_CLIENT_STATE_NEW;
1331- client->gearman->options= options;
1332+ gearman_universal_pop_non_blocking(&client->universal);
1333 return ret;
1334 }
1335 }
1336
1337 if (client->new_tasks == 0)
1338 {
1339- ret= gearman_flush_all(client->gearman);
1340+ ret= gearman_flush_all(&client->universal);
1341 if (ret != GEARMAN_SUCCESS)
1342 {
1343- client->gearman->options= options;
1344+ gearman_universal_pop_non_blocking(&client->universal);
1345 return ret;
1346 }
1347 }
1348 }
1349
1350 /* See if there are any connections ready for I/O. */
1351- while ((client->con= gearman_ready(client->gearman)) != NULL)
1352+ while ((client->con= gearman_ready(&client->universal)) != NULL)
1353 {
1354 if (client->con->revents & (POLLOUT | POLLERR | POLLHUP | POLLNVAL))
1355 {
1356@@ -673,7 +682,7 @@
1357 if (ret != GEARMAN_SUCCESS && ret != GEARMAN_IO_WAIT)
1358 {
1359 client->state= GEARMAN_CLIENT_STATE_SUBMIT;
1360- client->gearman->options= options;
1361+ gearman_universal_pop_non_blocking(&client->universal);
1362 return ret;
1363 }
1364 }
1365@@ -686,7 +695,7 @@
1366 while (1)
1367 {
1368 /* Read packet on connection and find which task it belongs to. */
1369- if (client->options & GEARMAN_CLIENT_UNBUFFERED_RESULT)
1370+ if (client->options.unbuffered_result)
1371 {
1372 /* If client is handling the data read, make sure it's complete. */
1373 if (client->con->recv_state == GEARMAN_CON_RECV_STATE_READ_DATA)
1374@@ -708,7 +717,7 @@
1375 {
1376 /* Read the next packet, without buffering the data part. */
1377 client->task= NULL;
1378- (void)gearman_con_recv(client->con, &(client->con->packet), &ret,
1379+ (void)gearman_connection_recv(client->con, &(client->con->packet), &ret,
1380 false);
1381 }
1382 }
1383@@ -716,24 +725,24 @@
1384 {
1385 /* Read the next packet, buffering the data part. */
1386 client->task= NULL;
1387- (void)gearman_con_recv(client->con, &(client->con->packet), &ret,
1388+ (void)gearman_connection_recv(client->con, &(client->con->packet), &ret,
1389 true);
1390 }
1391
1392 if (client->task == NULL)
1393 {
1394- /* Check the return of the gearman_con_recv() calls above. */
1395+ /* Check the return of the gearman_connection_recv() calls above. */
1396 if (ret != GEARMAN_SUCCESS)
1397 {
1398 if (ret == GEARMAN_IO_WAIT)
1399 break;
1400
1401 client->state= GEARMAN_CLIENT_STATE_IDLE;
1402- client->gearman->options= options;
1403+ gearman_universal_pop_non_blocking(&client->universal);
1404 return ret;
1405 }
1406
1407- client->con->options|= GEARMAN_CON_PACKET_IN_USE;
1408+ client->con->options.packet_in_use= true;
1409
1410 /* We have a packet, see which task it belongs to. */
1411 for (client->task= client->task_list; client->task != NULL;
1412@@ -752,7 +761,7 @@
1413 }
1414 else if (client->con->packet.command == GEARMAN_COMMAND_ERROR)
1415 {
1416- gearman_set_error(client->gearman, "gearman_client_run_tasks",
1417+ gearman_universal_set_error(&client->universal, "gearman_client_run_tasks",
1418 "%s:%.*s",
1419 (char *)(client->con->packet.arg[0]),
1420 (int)(client->con->packet.arg_size[1]),
1421@@ -788,14 +797,13 @@
1422 if (ret != GEARMAN_SUCCESS)
1423 {
1424 client->state= GEARMAN_CLIENT_STATE_PACKET;
1425- client->gearman->options= options;
1426+ gearman_universal_pop_non_blocking(&client->universal);
1427 return ret;
1428 }
1429
1430 /* Clean up the packet. */
1431 gearman_packet_free(&(client->con->packet));
1432- client->con->options&=
1433- (gearman_client_options_t)~GEARMAN_CON_PACKET_IN_USE;
1434+ client->con->options.packet_in_use= false;
1435
1436 /* If all tasks are done, return. */
1437 if (client->running_tasks == 0)
1438@@ -807,23 +815,24 @@
1439 if (client->running_tasks == 0)
1440 break;
1441
1442- if (client->new_tasks > 0 && !(client->options & GEARMAN_CLIENT_NO_NEW))
1443+ if (client->new_tasks > 0 && ! (client->options.no_new))
1444 continue;
1445
1446- if (options & GEARMAN_NON_BLOCKING)
1447+ if (gearman_universal_is_stored_non_blocking(&client->universal))
1448 {
1449 /* Let the caller wait for activity. */
1450 client->state= GEARMAN_CLIENT_STATE_IDLE;
1451- client->gearman->options= options;
1452+ gearman_universal_pop_non_blocking(&client->universal);
1453+
1454 return GEARMAN_IO_WAIT;
1455 }
1456
1457 /* Wait for activity on one of the connections. */
1458- ret= gearman_wait(client->gearman);
1459+ ret= gearman_wait(&client->universal);
1460 if (ret != GEARMAN_SUCCESS && ret != GEARMAN_IO_WAIT)
1461 {
1462 client->state= GEARMAN_CLIENT_STATE_IDLE;
1463- client->gearman->options= options;
1464+ gearman_universal_pop_non_blocking(&client->universal);
1465 return ret;
1466 }
1467 }
1468@@ -831,14 +840,16 @@
1469 break;
1470
1471 default:
1472- gearman_set_error(client->gearman, "gearman_client_run_tasks",
1473+ gearman_universal_set_error(&client->universal, "gearman_client_run_tasks",
1474 "unknown state: %u", client->state);
1475- client->gearman->options= options;
1476+ gearman_universal_pop_non_blocking(&client->universal);
1477+
1478 return GEARMAN_UNKNOWN_STATE;
1479 }
1480
1481 client->state= GEARMAN_CLIENT_STATE_IDLE;
1482- client->gearman->options= options;
1483+ gearman_universal_pop_non_blocking(&client->universal);
1484+
1485 return GEARMAN_SUCCESS;
1486 }
1487
1488@@ -846,7 +857,7 @@
1489 * Static Definitions
1490 */
1491
1492-static gearman_client_st *_client_allocate(gearman_client_st *client)
1493+static gearman_client_st *_client_allocate(gearman_client_st *client, bool is_clone)
1494 {
1495 if (client == NULL)
1496 {
1497@@ -854,10 +865,18 @@
1498 if (client == NULL)
1499 return NULL;
1500
1501- client->options= GEARMAN_CLIENT_ALLOCATED;
1502+ client->options.allocated= true;
1503 }
1504 else
1505- client->options= 0;
1506+ {
1507+ client->options.allocated= false;
1508+ }
1509+
1510+ client->options.non_blocking= false;
1511+ client->options.task_in_use= false;
1512+ client->options.unbuffered_result= false;
1513+ client->options.no_new= false;
1514+ client->options.free_tasks= false;
1515
1516 client->state= 0;
1517 client->do_ret= 0;
1518@@ -865,7 +884,6 @@
1519 client->running_tasks= 0;
1520 client->task_count= 0;
1521 client->do_data_size= 0;
1522- client->gearman= NULL;
1523 client->context= NULL;
1524 client->con= NULL;
1525 client->task= NULL;
1526@@ -881,6 +899,18 @@
1527 client->exception_fn= NULL;
1528 client->fail_fn= NULL;
1529
1530+ if (! is_clone)
1531+ {
1532+ gearman_universal_st *check;
1533+
1534+ check= gearman_universal_create(&client->universal, NULL);
1535+ if (check == NULL)
1536+ {
1537+ gearman_client_free(client);
1538+ return NULL;
1539+ }
1540+ }
1541+
1542 return client;
1543 }
1544
1545@@ -905,7 +935,7 @@
1546 const void *args[3];
1547 size_t args_size[3];
1548
1549- task= _task_create(client, task);
1550+ task= gearman_task_create(client, task);
1551 if (task == NULL)
1552 {
1553 *ret_ptr= GEARMAN_MEMORY_ALLOCATION_FAILURE;
1554@@ -928,14 +958,14 @@
1555 args[2]= workload;
1556 args_size[2]= workload_size;
1557
1558- *ret_ptr= gearman_add_packet_args(client->gearman, &(task->send),
1559- GEARMAN_MAGIC_REQUEST, command,
1560- args, args_size, 3);
1561+ *ret_ptr= gearman_packet_create_args(&client->universal, &(task->send),
1562+ GEARMAN_MAGIC_REQUEST, command,
1563+ args, args_size, 3);
1564 if (*ret_ptr == GEARMAN_SUCCESS)
1565 {
1566 client->new_tasks++;
1567 client->running_tasks++;
1568- task->options|= GEARMAN_TASK_SEND_IN_USE;
1569+ task->options.send_in_use= true;
1570 }
1571
1572 return task;
1573@@ -951,16 +981,16 @@
1574 switch(task->state)
1575 {
1576 case GEARMAN_TASK_STATE_NEW:
1577- if (task->client->gearman->con_list == NULL)
1578+ if (task->client->universal.con_list == NULL)
1579 {
1580 client->new_tasks--;
1581 client->running_tasks--;
1582- gearman_set_error(client->gearman, "_client_run_task",
1583+ gearman_universal_set_error(&client->universal, "_client_run_task",
1584 "no servers added");
1585 return GEARMAN_NO_SERVERS;
1586 }
1587
1588- for (task->con= task->client->gearman->con_list; task->con != NULL;
1589+ for (task->con= task->client->universal.con_list; task->con != NULL;
1590 task->con= task->con->next)
1591 {
1592 if (task->con->send_state == GEARMAN_CON_SEND_STATE_NONE)
1593@@ -969,7 +999,7 @@
1594
1595 if (task->con == NULL)
1596 {
1597- client->options|= GEARMAN_CLIENT_NO_NEW;
1598+ client->options.no_new= true;
1599 return GEARMAN_IO_WAIT;
1600 }
1601
1602@@ -984,7 +1014,7 @@
1603 case GEARMAN_TASK_STATE_SUBMIT:
1604 while (1)
1605 {
1606- ret= gearman_con_send(task->con, &(task->send),
1607+ ret= gearman_connection_send(task->con, &(task->send),
1608 client->new_tasks == 0 ? true : false);
1609 if (ret == GEARMAN_SUCCESS)
1610 break;
1611@@ -1028,8 +1058,8 @@
1612 {
1613 if (client->workload_fn == NULL)
1614 {
1615- gearman_set_error(client->gearman, "_client_run_task",
1616- "workload size > 0, but no data pointer or workload_fn was given");
1617+ gearman_universal_set_error(&client->universal, "_client_run_task",
1618+ "workload size > 0, but no data pointer or workload_fn was given");
1619 return GEARMAN_NEED_WORKLOAD_FN;
1620 }
1621
1622@@ -1042,9 +1072,9 @@
1623 }
1624 }
1625
1626- client->options&= (gearman_client_options_t)~GEARMAN_CLIENT_NO_NEW;
1627+ client->options.no_new= false;
1628 task->state= GEARMAN_TASK_STATE_WORK;
1629- return gearman_con_set_events(task->con, POLLIN);
1630+ return gearman_connection_set_events(task->con, POLLIN);
1631
1632 case GEARMAN_TASK_STATE_WORK:
1633 if (task->recv->command == GEARMAN_COMMAND_JOB_CREATED)
1634@@ -1188,15 +1218,15 @@
1635 break;
1636
1637 default:
1638- gearman_set_error(client->gearman, "_client_run_task", "unknown state: %u",
1639- task->state);
1640+ gearman_universal_set_error(&client->universal, "_client_run_task", "unknown state: %u",
1641+ task->state);
1642 return GEARMAN_UNKNOWN_STATE;
1643 }
1644
1645 client->running_tasks--;
1646 task->state= GEARMAN_TASK_STATE_FINISHED;
1647
1648- if (client->options & GEARMAN_CLIENT_FREE_TASKS)
1649+ if (client->options.free_tasks)
1650 gearman_task_free(task);
1651
1652 return GEARMAN_SUCCESS;
1653@@ -1207,7 +1237,7 @@
1654 const void *workload, size_t workload_size,
1655 size_t *result_size, gearman_return_t *ret_ptr)
1656 {
1657- if (!(client->options & GEARMAN_CLIENT_TASK_IN_USE))
1658+ if (! client->options.task_in_use)
1659 {
1660 (void)_client_add_task(client, &(client->do_task), client, command,
1661 function_name, unique, workload, workload_size,
1662@@ -1215,7 +1245,7 @@
1663 if (*ret_ptr != GEARMAN_SUCCESS)
1664 return NULL;
1665
1666- client->options|= GEARMAN_CLIENT_TASK_IN_USE;
1667+ client->options.task_in_use= true;
1668 }
1669
1670 client->workload_fn= NULL;
1671@@ -1232,7 +1262,7 @@
1672 client->do_ret == GEARMAN_WORK_FAIL))
1673 {
1674 gearman_task_free(&(client->do_task));
1675- client->options&= (gearman_client_options_t)~GEARMAN_CLIENT_TASK_IN_USE;
1676+ client->options.task_in_use= false;
1677 }
1678
1679 workload= NULL;
1680@@ -1259,7 +1289,7 @@
1681 {
1682 gearman_return_t ret;
1683
1684- if (!(client->options & GEARMAN_CLIENT_TASK_IN_USE))
1685+ if (! client->options.task_in_use)
1686 {
1687 (void)_client_add_task(client, &(client->do_task), client, command,
1688 function_name, unique, workload, workload_size,
1689@@ -1267,7 +1297,7 @@
1690 if (ret != GEARMAN_SUCCESS)
1691 return ret;
1692
1693- client->options|= GEARMAN_CLIENT_TASK_IN_USE;
1694+ client->options.task_in_use= true;
1695 }
1696
1697 gearman_client_clear_fn(client);
1698@@ -1279,7 +1309,7 @@
1699 strcpy(job_handle, client->do_task.job_handle);
1700
1701 gearman_task_free(&(client->do_task));
1702- client->options&= (gearman_client_options_t)~GEARMAN_CLIENT_TASK_IN_USE;
1703+ client->options.task_in_use= false;
1704 }
1705
1706 return ret;
1707@@ -1330,43 +1360,3 @@
1708 client->do_ret= GEARMAN_WORK_FAIL;
1709 return GEARMAN_SUCCESS;
1710 }
1711-
1712-static gearman_task_st *_task_create(gearman_client_st *client,
1713- gearman_task_st *task)
1714-{
1715- if (task == NULL)
1716- {
1717- task= malloc(sizeof(gearman_task_st));
1718- if (task == NULL)
1719- {
1720- gearman_set_error(client->gearman, "_task_create", "malloc");
1721- return NULL;
1722- }
1723-
1724- task->options= GEARMAN_TASK_ALLOCATED;
1725- }
1726- else
1727- task->options= 0;
1728-
1729- task->state= 0;
1730- task->is_known= false;
1731- task->is_running= false;
1732- task->created_id= 0;
1733- task->numerator= 0;
1734- task->denominator= 0;
1735- task->client= client;
1736-
1737- if (client->task_list != NULL)
1738- client->task_list->prev= task;
1739- task->next= client->task_list;
1740- task->prev= NULL;
1741- client->task_list= task;
1742- client->task_count++;
1743-
1744- task->context= NULL;
1745- task->con= NULL;
1746- task->recv= NULL;
1747- task->job_handle[0]= 0;
1748-
1749- return task;
1750-}
1751
1752=== modified file 'libgearman/client.h'
1753--- libgearman/client.h 2009-11-06 00:38:02 +0000
1754+++ libgearman/client.h 2009-12-30 19:24:13 +0000
1755@@ -28,6 +28,49 @@
1756 * @{
1757 */
1758
1759+
1760+/**
1761+ * @ingroup gearman_client
1762+ */
1763+struct gearman_client_st
1764+{
1765+ struct {
1766+ bool allocated:1;
1767+ bool non_blocking:1;
1768+ bool task_in_use:1;
1769+ bool unbuffered_result:1;
1770+ bool no_new:1;
1771+ bool free_tasks:1;
1772+ } options;
1773+ enum {
1774+ GEARMAN_CLIENT_STATE_IDLE,
1775+ GEARMAN_CLIENT_STATE_NEW,
1776+ GEARMAN_CLIENT_STATE_SUBMIT,
1777+ GEARMAN_CLIENT_STATE_PACKET
1778+ } state;
1779+ gearman_return_t do_ret;
1780+ uint32_t new_tasks;
1781+ uint32_t running_tasks;
1782+ uint32_t task_count;
1783+ size_t do_data_size;
1784+ const void *context;
1785+ gearman_connection_st *con;
1786+ gearman_task_st *task;
1787+ gearman_task_st *task_list;
1788+ gearman_task_context_free_fn *task_context_free_fn;
1789+ void *do_data;
1790+ gearman_workload_fn *workload_fn;
1791+ gearman_created_fn *created_fn;
1792+ gearman_data_fn *data_fn;
1793+ gearman_warning_fn *warning_fn;
1794+ gearman_universal_status_fn *status_fn;
1795+ gearman_complete_fn *complete_fn;
1796+ gearman_exception_fn *exception_fn;
1797+ gearman_fail_fn *fail_fn;
1798+ gearman_universal_st universal;
1799+ gearman_task_st do_task;
1800+};
1801+
1802 /**
1803 * Initialize a client structure. Always check the return value even if passing
1804 * in a pre-allocated structure. Some other initialization may have failed. It
1805@@ -116,13 +159,13 @@
1806 gearman_client_options_t options);
1807
1808 /**
1809- * See gearman_timeout() for details.
1810+ * See gearman_universal_timeout() for details.
1811 */
1812 GEARMAN_API
1813 int gearman_client_timeout(gearman_client_st *client);
1814
1815 /**
1816- * See gearman_set_timeout() for details.
1817+ * See gearman_universal_set_timeout() for details.
1818 */
1819 GEARMAN_API
1820 void gearman_client_set_timeout(gearman_client_st *client, int timeout);
1821@@ -156,14 +199,6 @@
1822 gearman_verbose_t verbose);
1823
1824 /**
1825- * See gearman_set_event_watch_fn() for details.
1826- */
1827-GEARMAN_API
1828-void gearman_client_set_event_watch_fn(gearman_client_st *client,
1829- gearman_event_watch_fn *function,
1830- const void *context);
1831-
1832-/**
1833 * See gearman_set_workload_malloc_fn() for details.
1834 */
1835 GEARMAN_API
1836@@ -403,15 +438,6 @@
1837 */
1838
1839 /**
1840- * Free a task structure.
1841- *
1842- * @param[in] task Structure previously initialized with one of the
1843- * gearman_client_add_task() functions.
1844- */
1845-GEARMAN_API
1846-void gearman_task_free(gearman_task_st *task);
1847-
1848-/**
1849 * Free all tasks for a gearman structure.
1850 *
1851 * @param[in] client Structure previously initialized with
1852@@ -601,7 +627,7 @@
1853 */
1854 GEARMAN_API
1855 void gearman_client_set_status_fn(gearman_client_st *client,
1856- gearman_status_fn *function);
1857+ gearman_universal_status_fn *function);
1858
1859 /**
1860 * Callback function when a task is complete.
1861
1862=== renamed file 'libgearman/structs.h' => 'libgearman/command.h'
1863--- libgearman/structs.h 2009-10-29 00:11:45 +0000
1864+++ libgearman/command.h 2009-12-30 19:24:13 +0000
1865@@ -8,64 +8,17 @@
1866
1867 /**
1868 * @file
1869- * @brief Struct Definitions
1870+ * @brief Definition for gearman_command_info_st
1871 */
1872
1873-#ifndef __GEARMAN_STRUCTS_H__
1874-#define __GEARMAN_STRUCTS_H__
1875+#ifndef __GEARMAN_COMMAND_H__
1876+#define __GEARMAN_COMMAND_H__
1877
1878 #ifdef __cplusplus
1879 extern "C" {
1880 #endif
1881
1882-/**
1883- * @ingroup gearman
1884- */
1885-struct gearman_st
1886-{
1887- gearman_options_t options;
1888- gearman_verbose_t verbose;
1889- uint32_t con_count;
1890- uint32_t packet_count;
1891- uint32_t pfds_size;
1892- uint32_t sending;
1893- int last_errno;
1894- int timeout;
1895- gearman_con_st *con_list;
1896- gearman_packet_st *packet_list;
1897- struct pollfd *pfds;
1898- gearman_log_fn *log_fn;
1899- const void *log_context;
1900- gearman_event_watch_fn *event_watch_fn;
1901- const void *event_watch_context;
1902- gearman_malloc_fn *workload_malloc_fn;
1903- const void *workload_malloc_context;
1904- gearman_free_fn *workload_free_fn;
1905- const void *workload_free_context;
1906- char last_error[GEARMAN_MAX_ERROR_SIZE];
1907-};
1908-
1909-/**
1910- * @ingroup gearman_packet
1911- */
1912-struct gearman_packet_st
1913-{
1914- gearman_packet_options_t options;
1915- gearman_magic_t magic;
1916- gearman_command_t command;
1917- uint8_t argc;
1918- size_t args_size;
1919- size_t data_size;
1920- gearman_st *gearman;
1921- gearman_packet_st *next;
1922- gearman_packet_st *prev;
1923- uint8_t *args;
1924- const void *data;
1925- uint8_t *arg[GEARMAN_MAX_COMMAND_ARGS];
1926- size_t arg_size[GEARMAN_MAX_COMMAND_ARGS];
1927- uint8_t args_buffer[GEARMAN_ARGS_BUFFER_SIZE];
1928-};
1929-
1930+#ifdef GEARMAN_CORE
1931 /**
1932 * @ingroup gearman_packet
1933 */
1934@@ -75,156 +28,10 @@
1935 const uint8_t argc;
1936 const bool data;
1937 };
1938-
1939-/**
1940- * @ingroup gearman_con
1941- */
1942-struct gearman_con_st
1943-{
1944- gearman_con_options_t options;
1945- gearman_con_state_t state;
1946- gearman_con_send_state_t send_state;
1947- gearman_con_recv_state_t recv_state;
1948- in_port_t port;
1949- short events;
1950- short revents;
1951- int fd;
1952- uint32_t created_id;
1953- uint32_t created_id_next;
1954- size_t send_buffer_size;
1955- size_t send_data_size;
1956- size_t send_data_offset;
1957- size_t recv_buffer_size;
1958- size_t recv_data_size;
1959- size_t recv_data_offset;
1960- gearman_st *gearman;
1961- gearman_con_st *next;
1962- gearman_con_st *prev;
1963- const void *context;
1964- struct addrinfo *addrinfo;
1965- struct addrinfo *addrinfo_next;
1966- uint8_t *send_buffer_ptr;
1967- gearman_packet_st *recv_packet;
1968- uint8_t *recv_buffer_ptr;
1969- const void *protocol_context;
1970- gearman_con_protocol_context_free_fn *protocol_context_free_fn;
1971- gearman_packet_pack_fn *packet_pack_fn;
1972- gearman_packet_unpack_fn *packet_unpack_fn;
1973- gearman_packet_st packet;
1974- char host[NI_MAXHOST];
1975- uint8_t send_buffer[GEARMAN_SEND_BUFFER_SIZE];
1976- uint8_t recv_buffer[GEARMAN_RECV_BUFFER_SIZE];
1977-};
1978-
1979-/**
1980- * @ingroup gearman_task
1981- */
1982-struct gearman_task_st
1983-{
1984- gearman_task_options_t options;
1985- gearman_task_state_t state;
1986- bool is_known;
1987- bool is_running;
1988- uint32_t created_id;
1989- uint32_t numerator;
1990- uint32_t denominator;
1991- gearman_client_st *client;
1992- gearman_task_st *next;
1993- gearman_task_st *prev;
1994- const void *context;
1995- gearman_con_st *con;
1996- gearman_packet_st *recv;
1997- gearman_packet_st send;
1998- char job_handle[GEARMAN_JOB_HANDLE_SIZE];
1999-};
2000-
2001-/**
2002- * @ingroup gearman_job
2003- */
2004-struct gearman_job_st
2005-{
2006- gearman_job_options_t options;
2007- gearman_worker_st *worker;
2008- gearman_job_st *next;
2009- gearman_job_st *prev;
2010- gearman_con_st *con;
2011- gearman_packet_st assigned;
2012- gearman_packet_st work;
2013-};
2014-
2015-/**
2016- * @ingroup gearman_client
2017- */
2018-struct gearman_client_st
2019-{
2020- gearman_client_options_t options;
2021- gearman_client_state_t state;
2022- gearman_return_t do_ret;
2023- uint32_t new_tasks;
2024- uint32_t running_tasks;
2025- uint32_t task_count;
2026- size_t do_data_size;
2027- gearman_st *gearman;
2028- const void *context;
2029- gearman_con_st *con;
2030- gearman_task_st *task;
2031- gearman_task_st *task_list;
2032- gearman_task_context_free_fn *task_context_free_fn;
2033- void *do_data;
2034- gearman_workload_fn *workload_fn;
2035- gearman_created_fn *created_fn;
2036- gearman_data_fn *data_fn;
2037- gearman_warning_fn *warning_fn;
2038- gearman_status_fn *status_fn;
2039- gearman_complete_fn *complete_fn;
2040- gearman_exception_fn *exception_fn;
2041- gearman_fail_fn *fail_fn;
2042- gearman_st gearman_static;
2043- gearman_task_st do_task;
2044-};
2045-
2046-/**
2047- * @ingroup gearman_worker
2048- */
2049-struct gearman_worker_st
2050-{
2051- gearman_worker_options_t options;
2052- gearman_worker_state_t state;
2053- gearman_worker_work_state_t work_state;
2054- uint32_t function_count;
2055- uint32_t job_count;
2056- size_t work_result_size;
2057- gearman_st *gearman;
2058- const void *context;
2059- gearman_con_st *con;
2060- gearman_job_st *job;
2061- gearman_job_st *job_list;
2062- gearman_worker_function_st *function;
2063- gearman_worker_function_st *function_list;
2064- gearman_worker_function_st *work_function;
2065- void *work_result;
2066- gearman_st gearman_static;
2067- gearman_packet_st grab_job;
2068- gearman_packet_st pre_sleep;
2069- gearman_job_st work_job;
2070-};
2071-
2072-/**
2073- * @ingroup gearman_worker
2074- */
2075-struct gearman_worker_function_st
2076-{
2077- gearman_worker_function_options_t options;
2078- gearman_worker_function_st *next;
2079- gearman_worker_function_st *prev;
2080- char *function_name;
2081- gearman_worker_fn *worker_fn;
2082- const void *context;
2083- gearman_packet_st packet;
2084-};
2085+#endif /* GEARMAN_CORE */
2086
2087 #ifdef __cplusplus
2088 }
2089 #endif
2090
2091-#endif /* __GEARMAN_STRUCTS_H__ */
2092+#endif /* __GEARMAN_COMMAND_H__ */
2093
2094=== modified file 'libgearman/common.h'
2095--- libgearman/common.h 2009-10-29 00:11:45 +0000
2096+++ libgearman/common.h 2009-12-30 19:24:13 +0000
2097@@ -16,6 +16,7 @@
2098
2099 #include "config.h"
2100
2101+#define GEARMAN_CORE
2102 #include "gearman.h"
2103
2104 #ifdef HAVE_ASSERT_H
2105@@ -75,6 +76,4 @@
2106 # endif
2107 #endif
2108
2109-#include "gearman_local.h"
2110-
2111 #endif /* __GEARMAN_COMMON_H__ */
2112
2113=== renamed file 'libgearman/conn.c' => 'libgearman/connection.c'
2114--- libgearman/conn.c 2009-10-29 20:18:00 +0000
2115+++ libgearman/connection.c 2009-12-30 19:24:13 +0000
2116@@ -13,16 +13,181 @@
2117
2118 #include "common.h"
2119
2120+static void gearman_connection_reset_addrinfo(gearman_connection_st *connection);
2121+
2122+
2123 /**
2124- * @addtogroup gearman_con_static Static Connection Declarations
2125- * @ingroup gearman_con
2126+ * @addtogroup gearman_connection_static Static Connection Declarations
2127+ * @ingroup gearman_connection
2128 * @{
2129 */
2130
2131+
2132+gearman_connection_st *gearman_connection_create(gearman_universal_st *gearman,
2133+ gearman_connection_st *connection,
2134+ gearman_connection_options_t *options)
2135+{
2136+ if (connection == NULL)
2137+ {
2138+ connection= malloc(sizeof(gearman_connection_st));
2139+ if (connection == NULL)
2140+ {
2141+ gearman_universal_set_error(gearman, "gearman_connection_create", "malloc");
2142+ return NULL;
2143+ }
2144+
2145+ connection->options.allocated= true;
2146+ }
2147+ else
2148+ {
2149+ connection->options.allocated= false;
2150+ }
2151+
2152+ connection->options.ready= false;
2153+ connection->options.packet_in_use= false;
2154+ connection->options.external_fd= false;
2155+ connection->options.ignore_lost_connection= false;
2156+ connection->options.close_after_flush= false;
2157+
2158+ if (options)
2159+ {
2160+ while (*options != GEARMAN_CON_MAX)
2161+ {
2162+ gearman_connection_set_option(connection, *options, true);
2163+ options++;
2164+ }
2165+ }
2166+
2167+
2168+ connection->state= 0;
2169+ connection->send_state= 0;
2170+ connection->recv_state= 0;
2171+ connection->port= 0;
2172+ connection->events= 0;
2173+ connection->revents= 0;
2174+ connection->fd= -1;
2175+ connection->created_id= 0;
2176+ connection->created_id_next= 0;
2177+ connection->send_buffer_size= 0;
2178+ connection->send_data_size= 0;
2179+ connection->send_data_offset= 0;
2180+ connection->recv_buffer_size= 0;
2181+ connection->recv_data_size= 0;
2182+ connection->recv_data_offset= 0;
2183+ connection->gearman= gearman;
2184+
2185+ if (gearman->con_list != NULL)
2186+ gearman->con_list->prev= connection;
2187+ connection->next= gearman->con_list;
2188+ connection->prev= NULL;
2189+ gearman->con_list= connection;
2190+ gearman->con_count++;
2191+
2192+ connection->context= NULL;
2193+ connection->addrinfo= NULL;
2194+ connection->addrinfo_next= NULL;
2195+ connection->send_buffer_ptr= connection->send_buffer;
2196+ connection->recv_packet= NULL;
2197+ connection->recv_buffer_ptr= connection->recv_buffer;
2198+ connection->protocol_context= NULL;
2199+ connection->protocol_context_free_fn= NULL;
2200+ connection->packet_pack_fn= gearman_packet_pack;
2201+ connection->packet_unpack_fn= gearman_packet_unpack;
2202+ connection->host[0]= 0;
2203+
2204+ return connection;
2205+}
2206+
2207+gearman_connection_st *gearman_connection_create_args(gearman_universal_st *gearman, gearman_connection_st *connection,
2208+ const char *host, in_port_t port)
2209+{
2210+ connection= gearman_connection_create(gearman, connection, NULL);
2211+ if (connection == NULL)
2212+ return NULL;
2213+
2214+ gearman_connection_set_host(connection, host, port);
2215+
2216+ return connection;
2217+}
2218+
2219+gearman_connection_st *gearman_connection_clone(gearman_universal_st *gearman, gearman_connection_st *connection,
2220+ const gearman_connection_st *from)
2221+{
2222+ connection= gearman_connection_create(gearman, connection, NULL);
2223+
2224+ if (from || connection == NULL)
2225+ return connection;
2226+
2227+ connection->options.ready= from->options.ready;
2228+ connection->options.packet_in_use= from->options.packet_in_use;
2229+ connection->options.external_fd= from->options.external_fd;
2230+ connection->options.ignore_lost_connection= from->options.ignore_lost_connection;
2231+ connection->options.close_after_flush= from->options.close_after_flush;
2232+
2233+ strcpy(connection->host, from->host);
2234+ connection->port= from->port;
2235+
2236+ return connection;
2237+}
2238+
2239+void gearman_connection_free(gearman_connection_st *connection)
2240+{
2241+ if (connection->fd != -1)
2242+ gearman_connection_close(connection);
2243+
2244+ gearman_connection_reset_addrinfo(connection);
2245+
2246+ if (connection->protocol_context != NULL && connection->protocol_context_free_fn != NULL)
2247+ connection->protocol_context_free_fn(connection, (void *)connection->protocol_context);
2248+
2249+ if (connection->gearman->con_list == connection)
2250+ connection->gearman->con_list= connection->next;
2251+ if (connection->prev != NULL)
2252+ connection->prev->next= connection->next;
2253+ if (connection->next != NULL)
2254+ connection->next->prev= connection->prev;
2255+ connection->gearman->con_count--;
2256+
2257+ if (connection->options.packet_in_use)
2258+ gearman_packet_free(&(connection->packet));
2259+
2260+ if (connection->options.allocated)
2261+ free(connection);
2262+}
2263+
2264+gearman_return_t gearman_connection_set_option(gearman_connection_st *connection,
2265+ gearman_connection_options_t options,
2266+ bool value)
2267+{
2268+ switch (options)
2269+ {
2270+ case GEARMAN_CON_READY:
2271+ connection->options.ready= value;
2272+ break;
2273+ case GEARMAN_CON_PACKET_IN_USE:
2274+ connection->options.packet_in_use= value;
2275+ break;
2276+ case GEARMAN_CON_EXTERNAL_FD:
2277+ connection->options.external_fd= value;
2278+ break;
2279+ case GEARMAN_CON_IGNORE_LOST_CONNECTION:
2280+ connection->options.ignore_lost_connection= value;
2281+ break;
2282+ case GEARMAN_CON_CLOSE_AFTER_FLUSH:
2283+ connection->options.close_after_flush= value;
2284+ break;
2285+ case GEARMAN_CON_MAX:
2286+ default:
2287+ return GEARMAN_INVALID_COMMAND;
2288+ }
2289+
2290+ return GEARMAN_SUCCESS;
2291+}
2292+
2293 /**
2294 * Set socket options for a connection.
2295 */
2296-static gearman_return_t _con_setsockopt(gearman_con_st *con);
2297+static gearman_return_t _con_setsockopt(gearman_connection_st *connection);
2298
2299 /** @} */
2300
2301@@ -30,129 +195,103 @@
2302 * Public Definitions
2303 */
2304
2305-void gearman_con_set_host(gearman_con_st *con, const char *host)
2306+void gearman_connection_set_host(gearman_connection_st *connection,
2307+ const char *host,
2308+ in_port_t port)
2309 {
2310- gearman_con_reset_addrinfo(con);
2311+ gearman_connection_reset_addrinfo(connection);
2312
2313- strncpy(con->host, host == NULL ? GEARMAN_DEFAULT_TCP_HOST : host,
2314+ strncpy(connection->host, host == NULL ? GEARMAN_DEFAULT_TCP_HOST : host,
2315 NI_MAXHOST);
2316- con->host[NI_MAXHOST - 1]= 0;
2317-}
2318-
2319-void gearman_con_set_port(gearman_con_st *con, in_port_t port)
2320-{
2321- gearman_con_reset_addrinfo(con);
2322-
2323- con->port= (in_port_t)(port == 0 ? GEARMAN_DEFAULT_TCP_PORT : port);
2324-}
2325-
2326-gearman_con_options_t gearman_con_options(const gearman_con_st *con)
2327-{
2328- return con->options;
2329-}
2330-
2331-void gearman_con_set_options(gearman_con_st *con,
2332- gearman_con_options_t options)
2333-{
2334- con->options= options;
2335-}
2336-
2337-void gearman_con_add_options(gearman_con_st *con,
2338- gearman_con_options_t options)
2339-{
2340- con->options|= options;
2341-}
2342-
2343-void gearman_con_remove_options(gearman_con_st *con,
2344- gearman_con_options_t options)
2345-{
2346- con->options&= ~options;
2347-}
2348-
2349-gearman_return_t gearman_con_set_fd(gearman_con_st *con, int fd)
2350+ connection->host[NI_MAXHOST - 1]= 0;
2351+
2352+ connection->port= (in_port_t)(port == 0 ? GEARMAN_DEFAULT_TCP_PORT : port);
2353+}
2354+
2355+gearman_return_t gearman_connection_set_fd(gearman_connection_st *connection, int fd)
2356 {
2357 gearman_return_t ret;
2358
2359- con->options|= GEARMAN_CON_EXTERNAL_FD;
2360- con->fd= fd;
2361- con->state= GEARMAN_CON_STATE_CONNECTED;
2362+ connection->options.external_fd= true;
2363+ connection->fd= fd;
2364+ connection->state= GEARMAN_CON_UNIVERSAL_CONNECTED;
2365
2366- ret= _con_setsockopt(con);
2367+ ret= _con_setsockopt(connection);
2368 if (ret != GEARMAN_SUCCESS)
2369 {
2370- con->gearman->last_errno= errno;
2371+ connection->gearman->last_errno= errno;
2372 return ret;
2373 }
2374
2375 return GEARMAN_SUCCESS;
2376 }
2377
2378-void *gearman_con_context(const gearman_con_st *con)
2379-{
2380- return (void *)con->context;
2381-}
2382-
2383-void gearman_con_set_context(gearman_con_st *con, const void *context)
2384-{
2385- con->context= context;
2386-}
2387-
2388-gearman_return_t gearman_con_connect(gearman_con_st *con)
2389-{
2390- return gearman_con_flush(con);
2391-}
2392-
2393-void gearman_con_close(gearman_con_st *con)
2394-{
2395- if (con->fd == -1)
2396+void *gearman_connection_context(const gearman_connection_st *connection)
2397+{
2398+ return (void *)connection->context;
2399+}
2400+
2401+void gearman_connection_set_context(gearman_connection_st *connection, const void *context)
2402+{
2403+ connection->context= context;
2404+}
2405+
2406+gearman_return_t gearman_connection_connect(gearman_connection_st *connection)
2407+{
2408+ return gearman_connection_flush(connection);
2409+}
2410+
2411+void gearman_connection_close(gearman_connection_st *connection)
2412+{
2413+ if (connection->fd == -1)
2414 return;
2415
2416- if (con->options & GEARMAN_CON_EXTERNAL_FD)
2417- con->options&= (gearman_con_options_t)~GEARMAN_CON_EXTERNAL_FD;
2418+ if (connection->options.external_fd)
2419+ connection->options.external_fd= false;
2420 else
2421- (void)close(con->fd);
2422-
2423- con->state= GEARMAN_CON_STATE_ADDRINFO;
2424- con->fd= -1;
2425- con->events= 0;
2426- con->revents= 0;
2427-
2428- con->send_state= GEARMAN_CON_SEND_STATE_NONE;
2429- con->send_buffer_ptr= con->send_buffer;
2430- con->send_buffer_size= 0;
2431- con->send_data_size= 0;
2432- con->send_data_offset= 0;
2433-
2434- con->recv_state= GEARMAN_CON_RECV_STATE_NONE;
2435- if (con->recv_packet != NULL)
2436- gearman_packet_free(con->recv_packet);
2437- con->recv_buffer_ptr= con->recv_buffer;
2438- con->recv_buffer_size= 0;
2439+ (void)close(connection->fd);
2440+
2441+ connection->state= GEARMAN_CON_UNIVERSAL_ADDRINFO;
2442+ connection->fd= -1;
2443+ connection->events= 0;
2444+ connection->revents= 0;
2445+
2446+ connection->send_state= GEARMAN_CON_SEND_STATE_NONE;
2447+ connection->send_buffer_ptr= connection->send_buffer;
2448+ connection->send_buffer_size= 0;
2449+ connection->send_data_size= 0;
2450+ connection->send_data_offset= 0;
2451+
2452+ connection->recv_state= GEARMAN_CON_RECV_UNIVERSAL_NONE;
2453+ if (connection->recv_packet != NULL)
2454+ gearman_packet_free(connection->recv_packet);
2455+ connection->recv_buffer_ptr= connection->recv_buffer;
2456+ connection->recv_buffer_size= 0;
2457 }
2458
2459-void gearman_con_reset_addrinfo(gearman_con_st *con)
2460+void gearman_connection_reset_addrinfo(gearman_connection_st *connection)
2461 {
2462- if (con->addrinfo != NULL)
2463+ if (connection->addrinfo != NULL)
2464 {
2465- freeaddrinfo(con->addrinfo);
2466- con->addrinfo= NULL;
2467+ freeaddrinfo(connection->addrinfo);
2468+ connection->addrinfo= NULL;
2469 }
2470
2471- con->addrinfo_next= NULL;
2472+ connection->addrinfo_next= NULL;
2473 }
2474
2475-gearman_return_t gearman_con_send(gearman_con_st *con,
2476- const gearman_packet_st *packet, bool flush)
2477+gearman_return_t gearman_connection_send(gearman_connection_st *connection,
2478+ const gearman_packet_st *packet, bool flush)
2479 {
2480 gearman_return_t ret;
2481 size_t send_size;
2482
2483- switch (con->send_state)
2484+ switch (connection->send_state)
2485 {
2486 case GEARMAN_CON_SEND_STATE_NONE:
2487- if (!(packet->options & GEARMAN_PACKET_COMPLETE))
2488+ if (! (packet->options.complete))
2489 {
2490- gearman_set_error(con->gearman, "gearman_con_send",
2491+ gearman_universal_set_error(connection->gearman, "gearman_connection_send",
2492 "packet not complete");
2493 return GEARMAN_INVALID_PACKET;
2494 }
2495@@ -160,13 +299,13 @@
2496 /* Pack first part of packet, which is everything but the payload. */
2497 while (1)
2498 {
2499- send_size= con->packet_pack_fn(packet, con,
2500- con->send_buffer + con->send_buffer_size,
2501+ send_size= connection->packet_pack_fn(packet, connection,
2502+ connection->send_buffer + connection->send_buffer_size,
2503 GEARMAN_SEND_BUFFER_SIZE -
2504- con->send_buffer_size, &ret);
2505+ connection->send_buffer_size, &ret);
2506 if (ret == GEARMAN_SUCCESS)
2507 {
2508- con->send_buffer_size+= send_size;
2509+ connection->send_buffer_size+= send_size;
2510 break;
2511 }
2512 else if (ret == GEARMAN_IGNORE_PACKET)
2513@@ -175,19 +314,19 @@
2514 return ret;
2515
2516 /* We were asked to flush when the buffer is already flushed! */
2517- if (con->send_buffer_size == 0)
2518+ if (connection->send_buffer_size == 0)
2519 {
2520- gearman_set_error(con->gearman, "gearman_con_send",
2521+ gearman_universal_set_error(connection->gearman, "gearman_connection_send",
2522 "send buffer too small (%u)",
2523 GEARMAN_SEND_BUFFER_SIZE);
2524 return GEARMAN_SEND_BUFFER_TOO_SMALL;
2525 }
2526
2527 /* Flush buffer now if first part of packet won't fit in. */
2528- con->send_state= GEARMAN_CON_SEND_STATE_PRE_FLUSH;
2529+ connection->send_state= GEARMAN_CON_SEND_UNIVERSAL_PRE_FLUSH;
2530
2531- case GEARMAN_CON_SEND_STATE_PRE_FLUSH:
2532- ret= gearman_con_flush(con);
2533+ case GEARMAN_CON_SEND_UNIVERSAL_PRE_FLUSH:
2534+ ret= gearman_connection_flush(connection);
2535 if (ret != GEARMAN_SUCCESS)
2536 return ret;
2537 }
2538@@ -198,112 +337,112 @@
2539
2540 /* If there is any room in the buffer, copy in data. */
2541 if (packet->data != NULL &&
2542- (GEARMAN_SEND_BUFFER_SIZE - con->send_buffer_size) > 0)
2543+ (GEARMAN_SEND_BUFFER_SIZE - connection->send_buffer_size) > 0)
2544 {
2545- con->send_data_offset= GEARMAN_SEND_BUFFER_SIZE - con->send_buffer_size;
2546- if (con->send_data_offset > packet->data_size)
2547- con->send_data_offset= packet->data_size;
2548+ connection->send_data_offset= GEARMAN_SEND_BUFFER_SIZE - connection->send_buffer_size;
2549+ if (connection->send_data_offset > packet->data_size)
2550+ connection->send_data_offset= packet->data_size;
2551
2552- memcpy(con->send_buffer + con->send_buffer_size, packet->data,
2553- con->send_data_offset);
2554- con->send_buffer_size+= con->send_data_offset;
2555+ memcpy(connection->send_buffer + connection->send_buffer_size, packet->data,
2556+ connection->send_data_offset);
2557+ connection->send_buffer_size+= connection->send_data_offset;
2558
2559 /* Return if all data fit in the send buffer. */
2560- if (con->send_data_offset == packet->data_size)
2561+ if (connection->send_data_offset == packet->data_size)
2562 {
2563- con->send_data_offset= 0;
2564+ connection->send_data_offset= 0;
2565 break;
2566 }
2567 }
2568
2569 /* Flush buffer now so we can start writing directly from data buffer. */
2570- con->send_state= GEARMAN_CON_SEND_STATE_FORCE_FLUSH;
2571+ connection->send_state= GEARMAN_CON_SEND_UNIVERSAL_FORCE_FLUSH;
2572
2573- case GEARMAN_CON_SEND_STATE_FORCE_FLUSH:
2574- ret= gearman_con_flush(con);
2575+ case GEARMAN_CON_SEND_UNIVERSAL_FORCE_FLUSH:
2576+ ret= gearman_connection_flush(connection);
2577 if (ret != GEARMAN_SUCCESS)
2578 return ret;
2579
2580- con->send_data_size= packet->data_size;
2581+ connection->send_data_size= packet->data_size;
2582
2583- /* If this is NULL, then gearman_con_send_data function will be used. */
2584+ /* If this is NULL, then gearman_connection_send_data function will be used. */
2585 if (packet->data == NULL)
2586 {
2587- con->send_state= GEARMAN_CON_SEND_STATE_FLUSH_DATA;
2588+ connection->send_state= GEARMAN_CON_SEND_UNIVERSAL_FLUSH_DATA;
2589 return GEARMAN_SUCCESS;
2590 }
2591
2592 /* Copy into the buffer if it fits, otherwise flush from packet buffer. */
2593- con->send_buffer_size= packet->data_size - con->send_data_offset;
2594- if (con->send_buffer_size < GEARMAN_SEND_BUFFER_SIZE)
2595+ connection->send_buffer_size= packet->data_size - connection->send_data_offset;
2596+ if (connection->send_buffer_size < GEARMAN_SEND_BUFFER_SIZE)
2597 {
2598- memcpy(con->send_buffer,
2599- ((uint8_t *)(packet->data)) + con->send_data_offset,
2600- con->send_buffer_size);
2601- con->send_data_size= 0;
2602- con->send_data_offset= 0;
2603+ memcpy(connection->send_buffer,
2604+ ((uint8_t *)(packet->data)) + connection->send_data_offset,
2605+ connection->send_buffer_size);
2606+ connection->send_data_size= 0;
2607+ connection->send_data_offset= 0;
2608 break;
2609 }
2610
2611- con->send_buffer_ptr= ((uint8_t *)(packet->data)) + con->send_data_offset;
2612- con->send_state= GEARMAN_CON_SEND_STATE_FLUSH_DATA;
2613+ connection->send_buffer_ptr= ((uint8_t *)(packet->data)) + connection->send_data_offset;
2614+ connection->send_state= GEARMAN_CON_SEND_UNIVERSAL_FLUSH_DATA;
2615
2616- case GEARMAN_CON_SEND_STATE_FLUSH:
2617- case GEARMAN_CON_SEND_STATE_FLUSH_DATA:
2618- ret= gearman_con_flush(con);
2619- if (ret == GEARMAN_SUCCESS && con->options & GEARMAN_CON_CLOSE_AFTER_FLUSH)
2620+ case GEARMAN_CON_SEND_UNIVERSAL_FLUSH:
2621+ case GEARMAN_CON_SEND_UNIVERSAL_FLUSH_DATA:
2622+ ret= gearman_connection_flush(connection);
2623+ if (ret == GEARMAN_SUCCESS && connection->options.close_after_flush)
2624 {
2625- gearman_con_close(con);
2626+ gearman_connection_close(connection);
2627 ret= GEARMAN_LOST_CONNECTION;
2628 }
2629 return ret;
2630
2631 default:
2632- gearman_set_error(con->gearman, "gearman_con_send", "unknown state: %u",
2633- con->send_state);
2634+ gearman_universal_set_error(connection->gearman, "gearman_connection_send", "unknown state: %u",
2635+ connection->send_state);
2636 return GEARMAN_UNKNOWN_STATE;
2637 }
2638
2639 if (flush)
2640 {
2641- con->send_state= GEARMAN_CON_SEND_STATE_FLUSH;
2642- ret= gearman_con_flush(con);
2643- if (ret == GEARMAN_SUCCESS && con->options & GEARMAN_CON_CLOSE_AFTER_FLUSH)
2644+ connection->send_state= GEARMAN_CON_SEND_UNIVERSAL_FLUSH;
2645+ ret= gearman_connection_flush(connection);
2646+ if (ret == GEARMAN_SUCCESS && connection->options.close_after_flush)
2647 {
2648- gearman_con_close(con);
2649+ gearman_connection_close(connection);
2650 ret= GEARMAN_LOST_CONNECTION;
2651 }
2652 return ret;
2653 }
2654
2655- con->send_state= GEARMAN_CON_SEND_STATE_NONE;
2656+ connection->send_state= GEARMAN_CON_SEND_STATE_NONE;
2657 return GEARMAN_SUCCESS;
2658 }
2659
2660-size_t gearman_con_send_data(gearman_con_st *con, const void *data,
2661- size_t data_size, gearman_return_t *ret_ptr)
2662+size_t gearman_connection_send_data(gearman_connection_st *connection, const void *data,
2663+ size_t data_size, gearman_return_t *ret_ptr)
2664 {
2665- if (con->send_state != GEARMAN_CON_SEND_STATE_FLUSH_DATA)
2666+ if (connection->send_state != GEARMAN_CON_SEND_UNIVERSAL_FLUSH_DATA)
2667 {
2668- gearman_set_error(con->gearman, "gearman_con_send_data", "not flushing");
2669+ gearman_universal_set_error(connection->gearman, "gearman_connection_send_data", "not flushing");
2670 return GEARMAN_NOT_FLUSHING;
2671 }
2672
2673- if (data_size > (con->send_data_size - con->send_data_offset))
2674+ if (data_size > (connection->send_data_size - connection->send_data_offset))
2675 {
2676- gearman_set_error(con->gearman, "gearman_con_send_data", "data too large");
2677+ gearman_universal_set_error(connection->gearman, "gearman_connection_send_data", "data too large");
2678 return GEARMAN_DATA_TOO_LARGE;
2679 }
2680
2681- con->send_buffer_ptr= (uint8_t *)data;
2682- con->send_buffer_size= data_size;
2683-
2684- *ret_ptr= gearman_con_flush(con);
2685-
2686- return data_size - con->send_buffer_size;
2687+ connection->send_buffer_ptr= (uint8_t *)data;
2688+ connection->send_buffer_size= data_size;
2689+
2690+ *ret_ptr= gearman_connection_flush(connection);
2691+
2692+ return data_size - connection->send_buffer_size;
2693 }
2694
2695-gearman_return_t gearman_con_flush(gearman_con_st *con)
2696+gearman_return_t gearman_connection_flush(gearman_connection_st *connection)
2697 {
2698 char port_str[NI_MAXSERV];
2699 struct addrinfo ai;
2700@@ -313,71 +452,71 @@
2701
2702 while (1)
2703 {
2704- switch (con->state)
2705+ switch (connection->state)
2706 {
2707- case GEARMAN_CON_STATE_ADDRINFO:
2708- if (con->addrinfo != NULL)
2709+ case GEARMAN_CON_UNIVERSAL_ADDRINFO:
2710+ if (connection->addrinfo != NULL)
2711 {
2712- freeaddrinfo(con->addrinfo);
2713- con->addrinfo= NULL;
2714+ freeaddrinfo(connection->addrinfo);
2715+ connection->addrinfo= NULL;
2716 }
2717
2718- snprintf(port_str, NI_MAXSERV, "%u", con->port);
2719+ snprintf(port_str, NI_MAXSERV, "%u", connection->port);
2720
2721 memset(&ai, 0, sizeof(struct addrinfo));
2722 ai.ai_socktype= SOCK_STREAM;
2723 ai.ai_protocol= IPPROTO_TCP;
2724
2725- ret= getaddrinfo(con->host, port_str, &ai, &(con->addrinfo));
2726+ ret= getaddrinfo(connection->host, port_str, &ai, &(connection->addrinfo));
2727 if (ret != 0)
2728 {
2729- gearman_set_error(con->gearman, "gearman_con_flush", "getaddrinfo:%s",
2730+ gearman_universal_set_error(connection->gearman, "gearman_connection_flush", "getaddrinfo:%s",
2731 gai_strerror(ret));
2732 return GEARMAN_GETADDRINFO;
2733 }
2734
2735- con->addrinfo_next= con->addrinfo;
2736-
2737- case GEARMAN_CON_STATE_CONNECT:
2738- if (con->fd != -1)
2739- gearman_con_close(con);
2740-
2741- if (con->addrinfo_next == NULL)
2742+ connection->addrinfo_next= connection->addrinfo;
2743+
2744+ case GEARMAN_CON_UNIVERSAL_CONNECT:
2745+ if (connection->fd != -1)
2746+ gearman_connection_close(connection);
2747+
2748+ if (connection->addrinfo_next == NULL)
2749 {
2750- con->state= GEARMAN_CON_STATE_ADDRINFO;
2751- gearman_set_error(con->gearman, "gearman_con_flush",
2752+ connection->state= GEARMAN_CON_UNIVERSAL_ADDRINFO;
2753+ gearman_universal_set_error(connection->gearman, "gearman_connection_flush",
2754 "could not connect");
2755 return GEARMAN_COULD_NOT_CONNECT;
2756 }
2757
2758- con->fd= socket(con->addrinfo_next->ai_family,
2759- con->addrinfo_next->ai_socktype,
2760- con->addrinfo_next->ai_protocol);
2761- if (con->fd == -1)
2762+ connection->fd= socket(connection->addrinfo_next->ai_family,
2763+ connection->addrinfo_next->ai_socktype,
2764+ connection->addrinfo_next->ai_protocol);
2765+ if (connection->fd == -1)
2766 {
2767- con->state= GEARMAN_CON_STATE_ADDRINFO;
2768- gearman_set_error(con->gearman, "gearman_con_flush", "socket:%d",
2769+ connection->state= GEARMAN_CON_UNIVERSAL_ADDRINFO;
2770+ gearman_universal_set_error(connection->gearman, "gearman_connection_flush", "socket:%d",
2771 errno);
2772- con->gearman->last_errno= errno;
2773+ connection->gearman->last_errno= errno;
2774 return GEARMAN_ERRNO;
2775 }
2776
2777- gret= _con_setsockopt(con);
2778+ gret= _con_setsockopt(connection);
2779 if (gret != GEARMAN_SUCCESS)
2780 {
2781- con->gearman->last_errno= errno;
2782- gearman_con_close(con);
2783+ connection->gearman->last_errno= errno;
2784+ gearman_connection_close(connection);
2785 return gret;
2786 }
2787
2788 while (1)
2789 {
2790- ret= connect(con->fd, con->addrinfo_next->ai_addr,
2791- con->addrinfo_next->ai_addrlen);
2792+ ret= connect(connection->fd, connection->addrinfo_next->ai_addr,
2793+ connection->addrinfo_next->ai_addrlen);
2794 if (ret == 0)
2795 {
2796- con->state= GEARMAN_CON_STATE_CONNECTED;
2797- con->addrinfo_next= NULL;
2798+ connection->state= GEARMAN_CON_UNIVERSAL_CONNECTED;
2799+ connection->addrinfo_next= NULL;
2800 break;
2801 }
2802
2803@@ -386,86 +525,86 @@
2804
2805 if (errno == EINPROGRESS)
2806 {
2807- con->state= GEARMAN_CON_STATE_CONNECTING;
2808+ connection->state= GEARMAN_CON_UNIVERSAL_CONNECTING;
2809 break;
2810 }
2811
2812 if (errno == ECONNREFUSED || errno == ENETUNREACH || errno == ETIMEDOUT)
2813 {
2814- con->state= GEARMAN_CON_STATE_CONNECT;
2815- con->addrinfo_next= con->addrinfo_next->ai_next;
2816+ connection->state= GEARMAN_CON_UNIVERSAL_CONNECT;
2817+ connection->addrinfo_next= connection->addrinfo_next->ai_next;
2818 break;
2819 }
2820
2821- gearman_set_error(con->gearman, "gearman_con_flush", "connect:%d",
2822+ gearman_universal_set_error(connection->gearman, "gearman_connection_flush", "connect:%d",
2823 errno);
2824- con->gearman->last_errno= errno;
2825- gearman_con_close(con);
2826+ connection->gearman->last_errno= errno;
2827+ gearman_connection_close(connection);
2828 return GEARMAN_ERRNO;
2829 }
2830
2831- if (con->state != GEARMAN_CON_STATE_CONNECTING)
2832+ if (connection->state != GEARMAN_CON_UNIVERSAL_CONNECTING)
2833 break;
2834
2835- case GEARMAN_CON_STATE_CONNECTING:
2836+ case GEARMAN_CON_UNIVERSAL_CONNECTING:
2837 while (1)
2838 {
2839- if (con->revents & POLLOUT)
2840+ if (connection->revents & POLLOUT)
2841 {
2842- con->state= GEARMAN_CON_STATE_CONNECTED;
2843+ connection->state= GEARMAN_CON_UNIVERSAL_CONNECTED;
2844 break;
2845 }
2846- else if (con->revents & (POLLERR | POLLHUP | POLLNVAL))
2847+ else if (connection->revents & (POLLERR | POLLHUP | POLLNVAL))
2848 {
2849- con->state= GEARMAN_CON_STATE_CONNECT;
2850- con->addrinfo_next= con->addrinfo_next->ai_next;
2851+ connection->state= GEARMAN_CON_UNIVERSAL_CONNECT;
2852+ connection->addrinfo_next= connection->addrinfo_next->ai_next;
2853 break;
2854 }
2855
2856- gret= gearman_con_set_events(con, POLLOUT);
2857+ gret= gearman_connection_set_events(connection, POLLOUT);
2858 if (gret != GEARMAN_SUCCESS)
2859 return gret;
2860
2861- if (con->gearman->options & GEARMAN_NON_BLOCKING)
2862+ if (gearman_universal_is_non_blocking(connection->gearman))
2863 {
2864- con->state= GEARMAN_CON_STATE_CONNECTING;
2865+ connection->state= GEARMAN_CON_UNIVERSAL_CONNECTING;
2866 return GEARMAN_IO_WAIT;
2867 }
2868
2869- gret= gearman_wait(con->gearman);
2870+ gret= gearman_wait(connection->gearman);
2871 if (gret != GEARMAN_SUCCESS)
2872 return gret;
2873 }
2874
2875- if (con->state != GEARMAN_CON_STATE_CONNECTED)
2876+ if (connection->state != GEARMAN_CON_UNIVERSAL_CONNECTED)
2877 break;
2878
2879- case GEARMAN_CON_STATE_CONNECTED:
2880- while (con->send_buffer_size != 0)
2881+ case GEARMAN_CON_UNIVERSAL_CONNECTED:
2882+ while (connection->send_buffer_size != 0)
2883 {
2884- write_size= write(con->fd, con->send_buffer_ptr, con->send_buffer_size);
2885+ write_size= write(connection->fd, connection->send_buffer_ptr, connection->send_buffer_size);
2886 if (write_size == 0)
2887 {
2888- if (!(con->options & GEARMAN_CON_IGNORE_LOST_CONNECTION))
2889+ if (! (connection->options.ignore_lost_connection))
2890 {
2891- gearman_set_error(con->gearman, "gearman_con_flush",
2892+ gearman_universal_set_error(connection->gearman, "gearman_connection_flush",
2893 "lost connection to server (EOF)");
2894 }
2895- gearman_con_close(con);
2896+ gearman_connection_close(connection);
2897 return GEARMAN_LOST_CONNECTION;
2898 }
2899 else if (write_size == -1)
2900 {
2901 if (errno == EAGAIN)
2902 {
2903- gret= gearman_con_set_events(con, POLLOUT);
2904+ gret= gearman_connection_set_events(connection, POLLOUT);
2905 if (gret != GEARMAN_SUCCESS)
2906 return gret;
2907
2908- if (con->gearman->options & GEARMAN_NON_BLOCKING)
2909+ if (gearman_universal_is_non_blocking(connection->gearman))
2910 return GEARMAN_IO_WAIT;
2911
2912- gret= gearman_wait(con->gearman);
2913+ gret= gearman_wait(connection->gearman);
2914 if (gret != GEARMAN_SUCCESS)
2915 return gret;
2916
2917@@ -475,124 +614,124 @@
2918 continue;
2919 else if (errno == EPIPE || errno == ECONNRESET)
2920 {
2921- if (!(con->options & GEARMAN_CON_IGNORE_LOST_CONNECTION))
2922+ if (! (connection->options.ignore_lost_connection))
2923 {
2924- gearman_set_error(con->gearman, "gearman_con_flush",
2925+ gearman_universal_set_error(connection->gearman, "gearman_connection_flush",
2926 "lost connection to server (%d)", errno);
2927 }
2928- gearman_con_close(con);
2929+ gearman_connection_close(connection);
2930 return GEARMAN_LOST_CONNECTION;
2931 }
2932
2933- gearman_set_error(con->gearman, "gearman_con_flush", "write:%d",
2934+ gearman_universal_set_error(connection->gearman, "gearman_connection_flush", "write:%d",
2935 errno);
2936- con->gearman->last_errno= errno;
2937- gearman_con_close(con);
2938+ connection->gearman->last_errno= errno;
2939+ gearman_connection_close(connection);
2940 return GEARMAN_ERRNO;
2941 }
2942
2943- con->send_buffer_size-= (size_t)write_size;
2944- if (con->send_state == GEARMAN_CON_SEND_STATE_FLUSH_DATA)
2945+ connection->send_buffer_size-= (size_t)write_size;
2946+ if (connection->send_state == GEARMAN_CON_SEND_UNIVERSAL_FLUSH_DATA)
2947 {
2948- con->send_data_offset+= (size_t)write_size;
2949- if (con->send_data_offset == con->send_data_size)
2950+ connection->send_data_offset+= (size_t)write_size;
2951+ if (connection->send_data_offset == connection->send_data_size)
2952 {
2953- con->send_data_size= 0;
2954- con->send_data_offset= 0;
2955+ connection->send_data_size= 0;
2956+ connection->send_data_offset= 0;
2957 break;
2958 }
2959
2960- if (con->send_buffer_size == 0)
2961+ if (connection->send_buffer_size == 0)
2962 return GEARMAN_SUCCESS;
2963 }
2964- else if (con->send_buffer_size == 0)
2965+ else if (connection->send_buffer_size == 0)
2966 break;
2967
2968- con->send_buffer_ptr+= write_size;
2969+ connection->send_buffer_ptr+= write_size;
2970 }
2971
2972- con->send_state= GEARMAN_CON_SEND_STATE_NONE;
2973- con->send_buffer_ptr= con->send_buffer;
2974+ connection->send_state= GEARMAN_CON_SEND_STATE_NONE;
2975+ connection->send_buffer_ptr= connection->send_buffer;
2976 return GEARMAN_SUCCESS;
2977
2978 default:
2979- gearman_set_error(con->gearman, "gearman_con_flush", "unknown state: %u",
2980- con->state);
2981+ gearman_universal_set_error(connection->gearman, "gearman_connection_flush", "unknown state: %u",
2982+ connection->state);
2983
2984 return GEARMAN_UNKNOWN_STATE;
2985 }
2986 }
2987 }
2988
2989-gearman_packet_st *gearman_con_recv(gearman_con_st *con,
2990- gearman_packet_st *packet,
2991- gearman_return_t *ret_ptr, bool recv_data)
2992+gearman_packet_st *gearman_connection_recv(gearman_connection_st *connection,
2993+ gearman_packet_st *packet,
2994+ gearman_return_t *ret_ptr, bool recv_data)
2995 {
2996 size_t recv_size;
2997
2998- switch (con->recv_state)
2999+ switch (connection->recv_state)
3000 {
3001- case GEARMAN_CON_RECV_STATE_NONE:
3002- if (con->state != GEARMAN_CON_STATE_CONNECTED)
3003+ case GEARMAN_CON_RECV_UNIVERSAL_NONE:
3004+ if (connection->state != GEARMAN_CON_UNIVERSAL_CONNECTED)
3005 {
3006- gearman_set_error(con->gearman, "gearman_con_recv", "not connected");
3007+ gearman_universal_set_error(connection->gearman, "gearman_connection_recv", "not connected");
3008 *ret_ptr= GEARMAN_NOT_CONNECTED;
3009 return NULL;
3010 }
3011
3012- con->recv_packet= gearman_add_packet(con->gearman, packet);
3013- if (con->recv_packet == NULL)
3014+ connection->recv_packet= gearman_packet_create(connection->gearman, packet);
3015+ if (connection->recv_packet == NULL)
3016 {
3017 *ret_ptr= GEARMAN_MEMORY_ALLOCATION_FAILURE;
3018 return NULL;
3019 }
3020
3021- con->recv_state= GEARMAN_CON_RECV_STATE_READ;
3022+ connection->recv_state= GEARMAN_CON_RECV_UNIVERSAL_READ;
3023
3024- case GEARMAN_CON_RECV_STATE_READ:
3025+ case GEARMAN_CON_RECV_UNIVERSAL_READ:
3026 while (1)
3027 {
3028- if (con->recv_buffer_size > 0)
3029+ if (connection->recv_buffer_size > 0)
3030 {
3031- recv_size= con->packet_unpack_fn(con->recv_packet, con,
3032- con->recv_buffer_ptr,
3033- con->recv_buffer_size, ret_ptr);
3034- con->recv_buffer_ptr+= recv_size;
3035- con->recv_buffer_size-= recv_size;
3036+ recv_size= connection->packet_unpack_fn(connection->recv_packet, connection,
3037+ connection->recv_buffer_ptr,
3038+ connection->recv_buffer_size, ret_ptr);
3039+ connection->recv_buffer_ptr+= recv_size;
3040+ connection->recv_buffer_size-= recv_size;
3041 if (*ret_ptr == GEARMAN_SUCCESS)
3042 break;
3043 else if (*ret_ptr != GEARMAN_IO_WAIT)
3044 {
3045- gearman_con_close(con);
3046+ gearman_connection_close(connection);
3047 return NULL;
3048 }
3049 }
3050
3051 /* Shift buffer contents if needed. */
3052- if (con->recv_buffer_size > 0)
3053- memmove(con->recv_buffer, con->recv_buffer_ptr, con->recv_buffer_size);
3054- con->recv_buffer_ptr= con->recv_buffer;
3055+ if (connection->recv_buffer_size > 0)
3056+ memmove(connection->recv_buffer, connection->recv_buffer_ptr, connection->recv_buffer_size);
3057+ connection->recv_buffer_ptr= connection->recv_buffer;
3058
3059- recv_size= gearman_con_read(con, con->recv_buffer + con->recv_buffer_size,
3060- GEARMAN_RECV_BUFFER_SIZE - con->recv_buffer_size,
3061- ret_ptr);
3062+ recv_size= gearman_connection_read(connection, connection->recv_buffer + connection->recv_buffer_size,
3063+ GEARMAN_RECV_BUFFER_SIZE - connection->recv_buffer_size,
3064+ ret_ptr);
3065 if (*ret_ptr != GEARMAN_SUCCESS)
3066 return NULL;
3067
3068- con->recv_buffer_size+= recv_size;
3069+ connection->recv_buffer_size+= recv_size;
3070 }
3071
3072 if (packet->data_size == 0)
3073 {
3074- con->recv_state= GEARMAN_CON_RECV_STATE_NONE;
3075+ connection->recv_state= GEARMAN_CON_RECV_UNIVERSAL_NONE;
3076 break;
3077 }
3078
3079- con->recv_data_size= packet->data_size;
3080+ connection->recv_data_size= packet->data_size;
3081
3082 if (!recv_data)
3083 {
3084- con->recv_state= GEARMAN_CON_RECV_STATE_READ_DATA;
3085+ connection->recv_state= GEARMAN_CON_RECV_STATE_READ_DATA;
3086 break;
3087 }
3088
3089@@ -601,110 +740,110 @@
3090 else
3091 {
3092 packet->data= packet->gearman->workload_malloc_fn(packet->data_size,
3093- (void *)packet->gearman->workload_malloc_context);
3094+ (void *)packet->gearman->workload_malloc_context);
3095 }
3096 if (packet->data == NULL)
3097 {
3098 *ret_ptr= GEARMAN_MEMORY_ALLOCATION_FAILURE;
3099- gearman_con_close(con);
3100+ gearman_connection_close(connection);
3101 return NULL;
3102 }
3103
3104- packet->options|= GEARMAN_PACKET_FREE_DATA;
3105- con->recv_state= GEARMAN_CON_RECV_STATE_READ_DATA;
3106+ packet->options.free_data= true;
3107+ connection->recv_state= GEARMAN_CON_RECV_STATE_READ_DATA;
3108
3109 case GEARMAN_CON_RECV_STATE_READ_DATA:
3110- while (con->recv_data_size != 0)
3111+ while (connection->recv_data_size != 0)
3112 {
3113- (void)gearman_con_recv_data(con,
3114- ((uint8_t *)(packet->data)) +
3115- con->recv_data_offset,
3116- packet->data_size -
3117- con->recv_data_offset, ret_ptr);
3118+ (void)gearman_connection_recv_data(connection,
3119+ ((uint8_t *)(packet->data)) +
3120+ connection->recv_data_offset,
3121+ packet->data_size -
3122+ connection->recv_data_offset, ret_ptr);
3123 if (*ret_ptr != GEARMAN_SUCCESS)
3124 return NULL;
3125 }
3126
3127- con->recv_state= GEARMAN_CON_RECV_STATE_NONE;
3128+ connection->recv_state= GEARMAN_CON_RECV_UNIVERSAL_NONE;
3129 break;
3130
3131 default:
3132- gearman_set_error(con->gearman, "gearman_con_recv", "unknown state: %u",
3133- con->recv_state);
3134+ gearman_universal_set_error(connection->gearman, "gearman_connection_recv", "unknown state: %u",
3135+ connection->recv_state);
3136 *ret_ptr= GEARMAN_UNKNOWN_STATE;
3137 return NULL;
3138 }
3139
3140- packet= con->recv_packet;
3141- con->recv_packet= NULL;
3142+ packet= connection->recv_packet;
3143+ connection->recv_packet= NULL;
3144
3145 return packet;
3146 }
3147
3148-size_t gearman_con_recv_data(gearman_con_st *con, void *data, size_t data_size,
3149- gearman_return_t *ret_ptr)
3150+size_t gearman_connection_recv_data(gearman_connection_st *connection, void *data, size_t data_size,
3151+ gearman_return_t *ret_ptr)
3152 {
3153 size_t recv_size= 0;
3154
3155- if (con->recv_data_size == 0)
3156+ if (connection->recv_data_size == 0)
3157 {
3158 *ret_ptr= GEARMAN_SUCCESS;
3159 return 0;
3160 }
3161
3162- if ((con->recv_data_size - con->recv_data_offset) < data_size)
3163- data_size= con->recv_data_size - con->recv_data_offset;
3164+ if ((connection->recv_data_size - connection->recv_data_offset) < data_size)
3165+ data_size= connection->recv_data_size - connection->recv_data_offset;
3166
3167- if (con->recv_buffer_size > 0)
3168+ if (connection->recv_buffer_size > 0)
3169 {
3170- if (con->recv_buffer_size < data_size)
3171- recv_size= con->recv_buffer_size;
3172+ if (connection->recv_buffer_size < data_size)
3173+ recv_size= connection->recv_buffer_size;
3174 else
3175 recv_size= data_size;
3176
3177- memcpy(data, con->recv_buffer_ptr, recv_size);
3178- con->recv_buffer_ptr+= recv_size;
3179- con->recv_buffer_size-= recv_size;
3180+ memcpy(data, connection->recv_buffer_ptr, recv_size);
3181+ connection->recv_buffer_ptr+= recv_size;
3182+ connection->recv_buffer_size-= recv_size;
3183 }
3184
3185 if (data_size != recv_size)
3186 {
3187- recv_size+= gearman_con_read(con, ((uint8_t *)data) + recv_size,
3188- data_size - recv_size, ret_ptr);
3189- con->recv_data_offset+= recv_size;
3190+ recv_size+= gearman_connection_read(connection, ((uint8_t *)data) + recv_size,
3191+ data_size - recv_size, ret_ptr);
3192+ connection->recv_data_offset+= recv_size;
3193 }
3194 else
3195 {
3196- con->recv_data_offset+= recv_size;
3197+ connection->recv_data_offset+= recv_size;
3198 *ret_ptr= GEARMAN_SUCCESS;
3199 }
3200
3201- if (con->recv_data_size == con->recv_data_offset)
3202+ if (connection->recv_data_size == connection->recv_data_offset)
3203 {
3204- con->recv_data_size= 0;
3205- con->recv_data_offset= 0;
3206- con->recv_state= GEARMAN_CON_RECV_STATE_NONE;
3207+ connection->recv_data_size= 0;
3208+ connection->recv_data_offset= 0;
3209+ connection->recv_state= GEARMAN_CON_RECV_UNIVERSAL_NONE;
3210 }
3211
3212 return recv_size;
3213 }
3214
3215-size_t gearman_con_read(gearman_con_st *con, void *data, size_t data_size,
3216- gearman_return_t *ret_ptr)
3217+size_t gearman_connection_read(gearman_connection_st *connection, void *data, size_t data_size,
3218+ gearman_return_t *ret_ptr)
3219 {
3220 ssize_t read_size;
3221
3222 while (1)
3223 {
3224- read_size= read(con->fd, data, data_size);
3225+ read_size= read(connection->fd, data, data_size);
3226 if (read_size == 0)
3227 {
3228- if (!(con->options & GEARMAN_CON_IGNORE_LOST_CONNECTION))
3229+ if (! (connection->options.ignore_lost_connection))
3230 {
3231- gearman_set_error(con->gearman, "gearman_con_read",
3232+ gearman_universal_set_error(connection->gearman, "gearman_connection_read",
3233 "lost connection to server (EOF)");
3234 }
3235- gearman_con_close(con);
3236+ gearman_connection_close(connection);
3237 *ret_ptr= GEARMAN_LOST_CONNECTION;
3238 return 0;
3239 }
3240@@ -712,17 +851,17 @@
3241 {
3242 if (errno == EAGAIN)
3243 {
3244- *ret_ptr= gearman_con_set_events(con, POLLIN);
3245+ *ret_ptr= gearman_connection_set_events(connection, POLLIN);
3246 if (*ret_ptr != GEARMAN_SUCCESS)
3247 return 0;
3248
3249- if (con->gearman->options & GEARMAN_NON_BLOCKING)
3250+ if (gearman_universal_is_non_blocking(connection->gearman))
3251 {
3252 *ret_ptr= GEARMAN_IO_WAIT;
3253 return 0;
3254 }
3255
3256- *ret_ptr= gearman_wait(con->gearman);
3257+ *ret_ptr= gearman_wait(connection->gearman);
3258 if (*ret_ptr != GEARMAN_SUCCESS)
3259 return 0;
3260
3261@@ -732,21 +871,21 @@
3262 continue;
3263 else if (errno == EPIPE || errno == ECONNRESET)
3264 {
3265- if (!(con->options & GEARMAN_CON_IGNORE_LOST_CONNECTION))
3266+ if (! (connection->options.ignore_lost_connection))
3267 {
3268- gearman_set_error(con->gearman, "gearman_con_read",
3269+ gearman_universal_set_error(connection->gearman, "gearman_connection_read",
3270 "lost connection to server (%d)", errno);
3271 }
3272 *ret_ptr= GEARMAN_LOST_CONNECTION;
3273 }
3274 else
3275 {
3276- gearman_set_error(con->gearman, "gearman_con_read", "read:%d", errno);
3277- con->gearman->last_errno= errno;
3278+ gearman_universal_set_error(connection->gearman, "gearman_connection_read", "read:%d", errno);
3279+ connection->gearman->last_errno= errno;
3280 *ret_ptr= GEARMAN_ERRNO;
3281 }
3282
3283- gearman_con_close(con);
3284+ gearman_connection_close(connection);
3285 return 0;
3286 }
3287
3288@@ -757,22 +896,22 @@
3289 return (size_t)read_size;
3290 }
3291
3292-gearman_return_t gearman_con_set_events(gearman_con_st *con, short events)
3293+gearman_return_t gearman_connection_set_events(gearman_connection_st *connection, short events)
3294 {
3295 gearman_return_t ret;
3296
3297- if ((con->events | events) == con->events)
3298+ if ((connection->events | events) == connection->events)
3299 return GEARMAN_SUCCESS;
3300
3301- con->events|= events;
3302+ connection->events|= events;
3303
3304- if (con->gearman->event_watch_fn != NULL)
3305+ if (connection->gearman->event_watch_fn != NULL)
3306 {
3307- ret= con->gearman->event_watch_fn(con, con->events,
3308- (void *)con->gearman->event_watch_context);
3309+ ret= connection->gearman->event_watch_fn(connection, connection->events,
3310+ (void *)connection->gearman->event_watch_context);
3311 if (ret != GEARMAN_SUCCESS)
3312 {
3313- gearman_con_close(con);
3314+ gearman_connection_close(connection);
3315 return ret;
3316 }
3317 }
3318@@ -780,145 +919,145 @@
3319 return GEARMAN_SUCCESS;
3320 }
3321
3322-gearman_return_t gearman_con_set_revents(gearman_con_st *con, short revents)
3323+gearman_return_t gearman_connection_set_revents(gearman_connection_st *connection, short revents)
3324 {
3325 gearman_return_t ret;
3326
3327 if (revents != 0)
3328- con->options|= GEARMAN_CON_READY;
3329+ connection->options.ready= true;
3330
3331- con->revents= revents;
3332+ connection->revents= revents;
3333
3334 /* Remove external POLLOUT watch if we didn't ask for it. Otherwise we spin
3335- forever until another POLLIN state change. This is much more efficient
3336- than removing POLLOUT on every state change since some external polling
3337- mechanisms need to use a system call to change flags (like Linux epoll). */
3338- if (revents & POLLOUT && !(con->events & POLLOUT) &&
3339- con->gearman->event_watch_fn != NULL)
3340+ forever until another POLLIN state change. This is much more efficient
3341+ than removing POLLOUT on every state change since some external polling
3342+ mechanisms need to use a system call to change flags (like Linux epoll). */
3343+ if (revents & POLLOUT && !(connection->events & POLLOUT) &&
3344+ connection->gearman->event_watch_fn != NULL)
3345 {
3346- ret= con->gearman->event_watch_fn(con, con->events,
3347- (void *)con->gearman->event_watch_context);
3348+ ret= connection->gearman->event_watch_fn(connection, connection->events,
3349+ (void *)connection->gearman->event_watch_context);
3350 if (ret != GEARMAN_SUCCESS)
3351 {
3352- gearman_con_close(con);
3353+ gearman_connection_close(connection);
3354 return ret;
3355 }
3356 }
3357
3358- con->events&= (short)~revents;
3359+ connection->events&= (short)~revents;
3360
3361 return GEARMAN_SUCCESS;
3362 }
3363
3364-void *gearman_con_protocol_context(const gearman_con_st *con)
3365-{
3366- return (void *)con->protocol_context;
3367-}
3368-
3369-void gearman_con_set_protocol_context(gearman_con_st *con, const void *context)
3370-{
3371- con->protocol_context= context;
3372-}
3373-
3374-void gearman_con_set_protocol_context_free_fn(gearman_con_st *con,
3375- gearman_con_protocol_context_free_fn *function)
3376-{
3377- con->protocol_context_free_fn= function;
3378-}
3379-
3380-void gearman_con_set_packet_pack_fn(gearman_con_st *con,
3381- gearman_packet_pack_fn *function)
3382-{
3383- con->packet_pack_fn= function;
3384-}
3385-
3386-void gearman_con_set_packet_unpack_fn(gearman_con_st *con,
3387- gearman_packet_unpack_fn *function)
3388-{
3389- con->packet_unpack_fn= function;
3390+void *gearman_connection_protocol_context(const gearman_connection_st *connection)
3391+{
3392+ return (void *)connection->protocol_context;
3393+}
3394+
3395+void gearman_connection_set_protocol_context(gearman_connection_st *connection, const void *context)
3396+{
3397+ connection->protocol_context= context;
3398+}
3399+
3400+void gearman_connection_set_protocol_context_free_fn(gearman_connection_st *connection,
3401+ gearman_connection_protocol_context_free_fn *function)
3402+{
3403+ connection->protocol_context_free_fn= function;
3404+}
3405+
3406+void gearman_connection_set_packet_pack_fn(gearman_connection_st *connection,
3407+ gearman_packet_pack_fn *function)
3408+{
3409+ connection->packet_pack_fn= function;
3410+}
3411+
3412+void gearman_connection_set_packet_unpack_fn(gearman_connection_st *connection,
3413+ gearman_packet_unpack_fn *function)
3414+{
3415+ connection->packet_unpack_fn= function;
3416 }
3417
3418 /*
3419 * Static Definitions
3420 */
3421
3422-static gearman_return_t _con_setsockopt(gearman_con_st *con)
3423+static gearman_return_t _con_setsockopt(gearman_connection_st *connection)
3424 {
3425 int ret;
3426 struct linger linger;
3427 struct timeval waittime;
3428
3429 ret= 1;
3430- ret= setsockopt(con->fd, IPPROTO_TCP, TCP_NODELAY, &ret,
3431+ ret= setsockopt(connection->fd, IPPROTO_TCP, TCP_NODELAY, &ret,
3432 (socklen_t)sizeof(int));
3433 if (ret == -1 && errno != EOPNOTSUPP)
3434 {
3435- gearman_set_error(con->gearman, "_con_setsockopt",
3436+ gearman_universal_set_error(connection->gearman, "_con_setsockopt",
3437 "setsockopt:TCP_NODELAY:%d", errno);
3438 return GEARMAN_ERRNO;
3439 }
3440
3441 linger.l_onoff= 1;
3442 linger.l_linger= GEARMAN_DEFAULT_SOCKET_TIMEOUT;
3443- ret= setsockopt(con->fd, SOL_SOCKET, SO_LINGER, &linger,
3444+ ret= setsockopt(connection->fd, SOL_SOCKET, SO_LINGER, &linger,
3445 (socklen_t)sizeof(struct linger));
3446 if (ret == -1)
3447 {
3448- gearman_set_error(con->gearman, "_con_setsockopt",
3449+ gearman_universal_set_error(connection->gearman, "_con_setsockopt",
3450 "setsockopt:SO_LINGER:%d", errno);
3451 return GEARMAN_ERRNO;
3452 }
3453
3454 waittime.tv_sec= GEARMAN_DEFAULT_SOCKET_TIMEOUT;
3455 waittime.tv_usec= 0;
3456- ret= setsockopt(con->fd, SOL_SOCKET, SO_SNDTIMEO, &waittime,
3457+ ret= setsockopt(connection->fd, SOL_SOCKET, SO_SNDTIMEO, &waittime,
3458 (socklen_t)sizeof(struct timeval));
3459 if (ret == -1 && errno != ENOPROTOOPT)
3460 {
3461- gearman_set_error(con->gearman, "_con_setsockopt",
3462+ gearman_universal_set_error(connection->gearman, "_con_setsockopt",
3463 "setsockopt:SO_SNDTIMEO:%d", errno);
3464 return GEARMAN_ERRNO;
3465 }
3466
3467- ret= setsockopt(con->fd, SOL_SOCKET, SO_RCVTIMEO, &waittime,
3468+ ret= setsockopt(connection->fd, SOL_SOCKET, SO_RCVTIMEO, &waittime,
3469 (socklen_t)sizeof(struct timeval));
3470 if (ret == -1 && errno != ENOPROTOOPT)
3471 {
3472- gearman_set_error(con->gearman, "_con_setsockopt",
3473+ gearman_universal_set_error(connection->gearman, "_con_setsockopt",
3474 "setsockopt:SO_RCVTIMEO:%d", errno);
3475 return GEARMAN_ERRNO;
3476 }
3477
3478 ret= GEARMAN_DEFAULT_SOCKET_SEND_SIZE;
3479- ret= setsockopt(con->fd, SOL_SOCKET, SO_SNDBUF, &ret, (socklen_t)sizeof(int));
3480+ ret= setsockopt(connection->fd, SOL_SOCKET, SO_SNDBUF, &ret, (socklen_t)sizeof(int));
3481 if (ret == -1)
3482 {
3483- gearman_set_error(con->gearman, "_con_setsockopt",
3484+ gearman_universal_set_error(connection->gearman, "_con_setsockopt",
3485 "setsockopt:SO_SNDBUF:%d", errno);
3486 return GEARMAN_ERRNO;
3487 }
3488
3489 ret= GEARMAN_DEFAULT_SOCKET_RECV_SIZE;
3490- ret= setsockopt(con->fd, SOL_SOCKET, SO_RCVBUF, &ret, (socklen_t)sizeof(int));
3491+ ret= setsockopt(connection->fd, SOL_SOCKET, SO_RCVBUF, &ret, (socklen_t)sizeof(int));
3492 if (ret == -1)
3493 {
3494- gearman_set_error(con->gearman, "_con_setsockopt",
3495+ gearman_universal_set_error(connection->gearman, "_con_setsockopt",
3496 "setsockopt:SO_RCVBUF:%d", errno);
3497 return GEARMAN_ERRNO;
3498 }
3499
3500- ret= fcntl(con->fd, F_GETFL, 0);
3501+ ret= fcntl(connection->fd, F_GETFL, 0);
3502 if (ret == -1)
3503 {
3504- gearman_set_error(con->gearman, "_con_setsockopt", "fcntl:F_GETFL:%d",
3505+ gearman_universal_set_error(connection->gearman, "_con_setsockopt", "fcntl:F_GETFL:%d",
3506 errno);
3507 return GEARMAN_ERRNO;
3508 }
3509
3510- ret= fcntl(con->fd, F_SETFL, ret | O_NONBLOCK);
3511+ ret= fcntl(connection->fd, F_SETFL, ret | O_NONBLOCK);
3512 if (ret == -1)
3513 {
3514- gearman_set_error(con->gearman, "_con_setsockopt", "fcntl:F_SETFL:%d",
3515+ gearman_universal_set_error(connection->gearman, "_con_setsockopt", "fcntl:F_SETFL:%d",
3516 errno);
3517 return GEARMAN_ERRNO;
3518 }
3519
3520=== renamed file 'libgearman/conn.h' => 'libgearman/connection.h'
3521--- libgearman/conn.h 2009-10-29 00:11:45 +0000
3522+++ libgearman/connection.h 2009-12-30 19:24:13 +0000
3523@@ -11,8 +11,8 @@
3524 * @brief Connection Declarations
3525 */
3526
3527-#ifndef __GEARMAN_CON_H__
3528-#define __GEARMAN_CON_H__
3529+#ifndef __GEARMAN_CONNECTION_H__
3530+#define __GEARMAN_CONNECTION_H__
3531
3532 #ifdef __cplusplus
3533 extern "C" {
3534@@ -20,7 +20,7 @@
3535
3536 /**
3537 * @addtogroup gearman_con Connection Declarations
3538- * @ingroup gearman
3539+ * @ingroup gearman_universal
3540 *
3541 * This is a low level interface for gearman connections. This is used
3542 * internally by both client and worker interfaces, so you probably want to
3543@@ -31,172 +31,263 @@
3544 */
3545
3546 /**
3547+ * @ingroup gearman_connection
3548+ */
3549+struct gearman_connection_st
3550+{
3551+ struct {
3552+ bool allocated:1;
3553+ bool ready:1;
3554+ bool packet_in_use:1;
3555+ bool external_fd:1;
3556+ bool ignore_lost_connection:1;
3557+ bool close_after_flush:1;
3558+ } options;
3559+ enum {
3560+ GEARMAN_CON_UNIVERSAL_ADDRINFO,
3561+ GEARMAN_CON_UNIVERSAL_CONNECT,
3562+ GEARMAN_CON_UNIVERSAL_CONNECTING,
3563+ GEARMAN_CON_UNIVERSAL_CONNECTED
3564+ } state;
3565+ enum {
3566+ GEARMAN_CON_SEND_STATE_NONE,
3567+ GEARMAN_CON_SEND_UNIVERSAL_PRE_FLUSH,
3568+ GEARMAN_CON_SEND_UNIVERSAL_FORCE_FLUSH,
3569+ GEARMAN_CON_SEND_UNIVERSAL_FLUSH,
3570+ GEARMAN_CON_SEND_UNIVERSAL_FLUSH_DATA
3571+ } send_state;
3572+ enum {
3573+ GEARMAN_CON_RECV_UNIVERSAL_NONE,
3574+ GEARMAN_CON_RECV_UNIVERSAL_READ,
3575+ GEARMAN_CON_RECV_STATE_READ_DATA
3576+ } recv_state;
3577+ in_port_t port;
3578+ short events;
3579+ short revents;
3580+ int fd;
3581+ uint32_t created_id;
3582+ uint32_t created_id_next;
3583+ size_t send_buffer_size;
3584+ size_t send_data_size;
3585+ size_t send_data_offset;
3586+ size_t recv_buffer_size;
3587+ size_t recv_data_size;
3588+ size_t recv_data_offset;
3589+ gearman_universal_st *gearman;
3590+ gearman_connection_st *next;
3591+ gearman_connection_st *prev;
3592+ const void *context;
3593+ struct addrinfo *addrinfo;
3594+ struct addrinfo *addrinfo_next;
3595+ uint8_t *send_buffer_ptr;
3596+ gearman_packet_st *recv_packet;
3597+ uint8_t *recv_buffer_ptr;
3598+ const void *protocol_context;
3599+ gearman_connection_protocol_context_free_fn *protocol_context_free_fn;
3600+ gearman_packet_pack_fn *packet_pack_fn;
3601+ gearman_packet_unpack_fn *packet_unpack_fn;
3602+ gearman_packet_st packet;
3603+ char host[NI_MAXHOST];
3604+ uint8_t send_buffer[GEARMAN_SEND_BUFFER_SIZE];
3605+ uint8_t recv_buffer[GEARMAN_RECV_BUFFER_SIZE];
3606+};
3607+
3608+#ifdef GEARMAN_CORE
3609+
3610+/**
3611+ * Initialize a connection structure. Always check the return value even if
3612+ * passing in a pre-allocated structure. Some other initialization may have
3613+ * failed.
3614+ *
3615+ * @param[in] gearman Structure previously initialized with gearman_create() or
3616+ * gearman_clone().
3617+ * @param[in] connection Caller allocated structure, or NULL to allocate one.
3618+ * @return On success, a pointer to the (possibly allocated) structure. On
3619+ * failure this will be NULL.
3620+ */
3621+GEARMAN_INTERNAL_API
3622+gearman_connection_st *gearman_connection_create(gearman_universal_st *gearman,
3623+ gearman_connection_st *connection,
3624+ gearman_connection_options_t *options);
3625+
3626+/**
3627+ * Create a connection structure with the given host and port.
3628+ *
3629+ * @param[in] gearman Structure previously initialized with gearman_create() or
3630+ * gearman_clone().
3631+ * @param[in] connection Caller allocated structure, or NULL to allocate one.
3632+ * @param[in] host Host or IP address to connect to.
3633+ * @param[in] port Port to connect to.
3634+ * @return On success, a pointer to the (possibly allocated) structure. On
3635+ * failure this will be NULL.
3636+ */
3637+GEARMAN_INTERNAL_API
3638+gearman_connection_st *gearman_connection_create_args(gearman_universal_st *gearman,
3639+ gearman_connection_st *connection,
3640+ const char *host, in_port_t port);
3641+
3642+/**
3643+ * Clone a connection structure.
3644+ *
3645+ * @param[in] gearman Structure previously initialized with gearman_create() or
3646+ * gearman_clone().
3647+ * @param[in] connection Caller allocated structure, or NULL to allocate one.
3648+ * @param[in] from Structure to use as a source to clone from.
3649+ * @return On success, a pointer to the (possibly allocated) structure. On
3650+ * failure this will be NULL.
3651+ */
3652+GEARMAN_INTERNAL_API
3653+gearman_connection_st *gearman_connection_clone(gearman_universal_st *gearman, gearman_connection_st *src,
3654+ const gearman_connection_st *from);
3655+
3656+/**
3657+ * Free a connection structure.
3658+ *
3659+ * @param[in] connection Structure previously initialized with gearman_connection_create(),
3660+ * gearman_connection_create_args(), or gearman_connection_clone().
3661+ */
3662+GEARMAN_INTERNAL_API
3663+void gearman_connection_free(gearman_connection_st *connection);
3664+
3665+
3666+GEARMAN_INTERNAL_API
3667+gearman_return_t gearman_connection_set_option(gearman_connection_st *connection,
3668+ gearman_connection_options_t options,
3669+ bool value);
3670+
3671+
3672+/**
3673 * Set host for a connection.
3674 */
3675-GEARMAN_API
3676-void gearman_con_set_host(gearman_con_st *con, const char *host);
3677-
3678-/**
3679- * Set port for a connection.
3680- */
3681-GEARMAN_API
3682-void gearman_con_set_port(gearman_con_st *con, in_port_t port);
3683-
3684-/**
3685- * Get options for a connection.
3686- */
3687-GEARMAN_API
3688-gearman_con_options_t gearman_con_options(const gearman_con_st *con);
3689-
3690-/**
3691- * Set options for a connection.
3692- */
3693-GEARMAN_API
3694-void gearman_con_set_options(gearman_con_st *con,
3695- gearman_con_options_t options);
3696-
3697-/**
3698- * Add options for a connection.
3699- */
3700-GEARMAN_API
3701-void gearman_con_add_options(gearman_con_st *con,
3702- gearman_con_options_t options);
3703-
3704-/**
3705- * Remove options for a connection.
3706- */
3707-GEARMAN_API
3708-void gearman_con_remove_options(gearman_con_st *con,
3709- gearman_con_options_t options);
3710+GEARMAN_INTERNAL_API
3711+void gearman_connection_set_host(gearman_connection_st *connection,
3712+ const char *host,
3713+ in_port_t port);
3714
3715 /**
3716 * Set connection to an already open file descriptor.
3717 */
3718-GEARMAN_API
3719-gearman_return_t gearman_con_set_fd(gearman_con_st *con, int fd);
3720+GEARMAN_INTERNAL_API
3721+gearman_return_t gearman_connection_set_fd(gearman_connection_st *connection, int fd);
3722
3723 /**
3724 * Get application context pointer.
3725 */
3726-GEARMAN_API
3727-void *gearman_con_context(const gearman_con_st *con);
3728+GEARMAN_INTERNAL_API
3729+void *gearman_connection_context(const gearman_connection_st *connection);
3730
3731 /**
3732 * Set application context pointer.
3733 */
3734-GEARMAN_API
3735-void gearman_con_set_context(gearman_con_st *con, const void *context);
3736+GEARMAN_INTERNAL_API
3737+void gearman_connection_set_context(gearman_connection_st *connection, const void *context);
3738
3739 /**
3740 * Connect to server.
3741 */
3742-GEARMAN_API
3743-gearman_return_t gearman_con_connect(gearman_con_st *con);
3744+GEARMAN_INTERNAL_API
3745+gearman_return_t gearman_connection_connect(gearman_connection_st *connection);
3746
3747 /**
3748 * Close a connection.
3749 */
3750-GEARMAN_API
3751-void gearman_con_close(gearman_con_st *con);
3752-
3753-/**
3754- * Clear address info, freeing structs if needed.
3755- */
3756-GEARMAN_API
3757-void gearman_con_reset_addrinfo(gearman_con_st *con);
3758+GEARMAN_INTERNAL_API
3759+void gearman_connection_close(gearman_connection_st *connection);
3760
3761 /**
3762 * Send packet to a connection.
3763 */
3764-GEARMAN_API
3765-gearman_return_t gearman_con_send(gearman_con_st *con,
3766- const gearman_packet_st *packet, bool flush);
3767+GEARMAN_INTERNAL_API
3768+gearman_return_t gearman_connection_send(gearman_connection_st *connection,
3769+ const gearman_packet_st *packet, bool flush);
3770
3771 /**
3772 * Send packet data to a connection.
3773 */
3774-GEARMAN_API
3775-size_t gearman_con_send_data(gearman_con_st *con, const void *data,
3776- size_t data_size, gearman_return_t *ret_ptr);
3777+GEARMAN_INTERNAL_API
3778+size_t gearman_connection_send_data(gearman_connection_st *connection, const void *data,
3779+ size_t data_size, gearman_return_t *ret_ptr);
3780
3781 /**
3782 * Flush the send buffer.
3783 */
3784-GEARMAN_API
3785-gearman_return_t gearman_con_flush(gearman_con_st *con);
3786+GEARMAN_INTERNAL_API
3787+gearman_return_t gearman_connection_flush(gearman_connection_st *connection);
3788
3789 /**
3790 * Receive packet from a connection.
3791 */
3792-GEARMAN_API
3793-gearman_packet_st *gearman_con_recv(gearman_con_st *con,
3794- gearman_packet_st *packet,
3795- gearman_return_t *ret_ptr, bool recv_data);
3796+GEARMAN_INTERNAL_API
3797+gearman_packet_st *gearman_connection_recv(gearman_connection_st *connection,
3798+ gearman_packet_st *packet,
3799+ gearman_return_t *ret_ptr, bool recv_data);
3800
3801 /**
3802 * Receive packet data from a connection.
3803 */
3804-GEARMAN_API
3805-size_t gearman_con_recv_data(gearman_con_st *con, void *data, size_t data_size,
3806- gearman_return_t *ret_ptr);
3807+GEARMAN_INTERNAL_API
3808+size_t gearman_connection_recv_data(gearman_connection_st *connection, void *data, size_t data_size,
3809+ gearman_return_t *ret_ptr);
3810
3811 /**
3812 * Read data from a connection.
3813 */
3814-GEARMAN_API
3815-size_t gearman_con_read(gearman_con_st *con, void *data, size_t data_size,
3816- gearman_return_t *ret_ptr);
3817+GEARMAN_INTERNAL_API
3818+size_t gearman_connection_read(gearman_connection_st *connection, void *data, size_t data_size,
3819+ gearman_return_t *ret_ptr);
3820
3821 /**
3822 * Set events to be watched for a connection.
3823 */
3824-GEARMAN_API
3825-gearman_return_t gearman_con_set_events(gearman_con_st *con, short events);
3826+GEARMAN_INTERNAL_API
3827+gearman_return_t gearman_connection_set_events(gearman_connection_st *connection, short events);
3828
3829 /**
3830 * Set events that are ready for a connection. This is used with the external
3831 * event callbacks.
3832 */
3833-GEARMAN_API
3834-gearman_return_t gearman_con_set_revents(gearman_con_st *con, short revents);
3835+GEARMAN_INTERNAL_API
3836+gearman_return_t gearman_connection_set_revents(gearman_connection_st *connection, short revents);
3837
3838 /**
3839 * Get protocol context pointer.
3840 */
3841-GEARMAN_API
3842-void *gearman_con_protocol_context(const gearman_con_st *con);
3843+GEARMAN_INTERNAL_API
3844+void *gearman_connection_protocol_context(const gearman_connection_st *connection);
3845
3846 /**
3847 * Set protocol context pointer.
3848 */
3849-GEARMAN_API
3850-void gearman_con_set_protocol_context(gearman_con_st *con, const void *context);
3851+GEARMAN_INTERNAL_API
3852+void gearman_connection_set_protocol_context(gearman_connection_st *connection, const void *context);
3853
3854 /**
3855 * Set function to call when protocol_data should be freed.
3856 */
3857-GEARMAN_API
3858-void gearman_con_set_protocol_context_free_fn(gearman_con_st *con,
3859- gearman_con_protocol_context_free_fn *function);
3860+GEARMAN_INTERNAL_API
3861+void gearman_connection_set_protocol_context_free_fn(gearman_connection_st *connection,
3862+ gearman_connection_protocol_context_free_fn *function);
3863
3864 /**
3865 * Set custom packet_pack function
3866 */
3867-GEARMAN_API
3868-void gearman_con_set_packet_pack_fn(gearman_con_st *con,
3869- gearman_packet_pack_fn *function);
3870+GEARMAN_INTERNAL_API
3871+void gearman_connection_set_packet_pack_fn(gearman_connection_st *connection,
3872+ gearman_packet_pack_fn *function);
3873
3874 /**
3875 * Set custom packet_unpack function
3876 */
3877-GEARMAN_API
3878-void gearman_con_set_packet_unpack_fn(gearman_con_st *con,
3879- gearman_packet_unpack_fn *function);
3880+GEARMAN_INTERNAL_API
3881+void gearman_connection_set_packet_unpack_fn(gearman_connection_st *connection,
3882+ gearman_packet_unpack_fn *function);
3883
3884 /** @} */
3885
3886+#endif /* GEARMAN_CORE */
3887+
3888 #ifdef __cplusplus
3889 }
3890 #endif
3891
3892-#endif /* __GEARMAN_CON_H__ */
3893+#endif /* __GEARMAN_CONNECTION_H__ */
3894
3895=== modified file 'libgearman/constants.h'
3896--- libgearman/constants.h 2009-10-29 20:18:00 +0000
3897+++ libgearman/constants.h 2009-12-30 19:24:13 +0000
3898@@ -20,7 +20,7 @@
3899
3900 /**
3901 * @addtogroup gearman_constants Constants
3902- * @ingroup gearman
3903+ * @ingroup gearman_universal
3904 * @ingroup gearman_client
3905 * @ingroup gearman_worker
3906 * @{
3907@@ -115,81 +115,34 @@
3908 /** @} */
3909
3910 /**
3911- * @ingroup gearman
3912- * Options for gearman_st.
3913+ * @ingroup gearman_universal
3914+ * Options for gearman_universal_st.
3915 */
3916 typedef enum
3917 {
3918- GEARMAN_ALLOCATED= (1 << 0),
3919- GEARMAN_NON_BLOCKING= (1 << 1),
3920- GEARMAN_DONT_TRACK_PACKETS= (1 << 2)
3921+ GEARMAN_NON_BLOCKING,
3922+ GEARMAN_DONT_TRACK_PACKETS,
3923+ GEARMAN_MAX
3924 } gearman_options_t;
3925
3926 /**
3927 * @ingroup gearman_con
3928- * Options for gearman_con_st.
3929- */
3930-typedef enum
3931-{
3932- GEARMAN_CON_ALLOCATED= (1 << 0),
3933- GEARMAN_CON_READY= (1 << 1),
3934- GEARMAN_CON_PACKET_IN_USE= (1 << 2),
3935- GEARMAN_CON_EXTERNAL_FD= (1 << 3),
3936- GEARMAN_CON_IGNORE_LOST_CONNECTION= (1 << 4),
3937- GEARMAN_CON_CLOSE_AFTER_FLUSH= (1 << 5)
3938-} gearman_con_options_t;
3939-
3940-/**
3941- * @ingroup gearman_con
3942- * States for gearman_con_st.
3943- */
3944-typedef enum
3945-{
3946- GEARMAN_CON_STATE_ADDRINFO,
3947- GEARMAN_CON_STATE_CONNECT,
3948- GEARMAN_CON_STATE_CONNECTING,
3949- GEARMAN_CON_STATE_CONNECTED
3950-} gearman_con_state_t;
3951-
3952-/**
3953- * @ingroup gearman_con
3954- * Send states for gearman_con_st.
3955- */
3956-typedef enum
3957-{
3958- GEARMAN_CON_SEND_STATE_NONE,
3959- GEARMAN_CON_SEND_STATE_PRE_FLUSH,
3960- GEARMAN_CON_SEND_STATE_FORCE_FLUSH,
3961- GEARMAN_CON_SEND_STATE_FLUSH,
3962- GEARMAN_CON_SEND_STATE_FLUSH_DATA
3963-} gearman_con_send_state_t;
3964-
3965-/**
3966- * @ingroup gearman_con
3967- * Recv states for gearman_con_st.
3968- */
3969-typedef enum
3970-{
3971- GEARMAN_CON_RECV_STATE_NONE,
3972- GEARMAN_CON_RECV_STATE_READ,
3973- GEARMAN_CON_RECV_STATE_READ_DATA
3974-} gearman_con_recv_state_t;
3975-
3976-/**
3977- * @ingroup gearman_packet
3978- * Options for gearman_packet_st.
3979- */
3980-typedef enum
3981-{
3982- GEARMAN_PACKET_ALLOCATED= (1 << 0),
3983- GEARMAN_PACKET_COMPLETE= (1 << 1),
3984- GEARMAN_PACKET_FREE_DATA= (1 << 2)
3985-} gearman_packet_options_t;
3986+ * Options for gearman_connection_st.
3987+ */
3988+typedef enum
3989+{
3990+ GEARMAN_CON_READY,
3991+ GEARMAN_CON_PACKET_IN_USE,
3992+ GEARMAN_CON_EXTERNAL_FD,
3993+ GEARMAN_CON_IGNORE_LOST_CONNECTION,
3994+ GEARMAN_CON_CLOSE_AFTER_FLUSH,
3995+ GEARMAN_CON_MAX
3996+} gearman_connection_options_t;
3997
3998 /**
3999 * @ingroup gearman_packet
4000 * Magic types.
4001- */
4002+*/
4003 typedef enum
4004 {
4005 GEARMAN_MAGIC_TEXT,
4006@@ -245,48 +198,6 @@
4007 } gearman_command_t;
4008
4009 /**
4010- * @ingroup gearman_task
4011- * Options for gearman_task_st.
4012- */
4013-typedef enum
4014-{
4015- GEARMAN_TASK_ALLOCATED= (1 << 0),
4016- GEARMAN_TASK_SEND_IN_USE= (1 << 1)
4017-} gearman_task_options_t;
4018-
4019-/**
4020- * @ingroup gearman_task
4021- * States for gearman_task_st.
4022- */
4023-typedef enum
4024-{
4025- GEARMAN_TASK_STATE_NEW,
4026- GEARMAN_TASK_STATE_SUBMIT,
4027- GEARMAN_TASK_STATE_WORKLOAD,
4028- GEARMAN_TASK_STATE_WORK,
4029- GEARMAN_TASK_STATE_CREATED,
4030- GEARMAN_TASK_STATE_DATA,
4031- GEARMAN_TASK_STATE_WARNING,
4032- GEARMAN_TASK_STATE_STATUS,
4033- GEARMAN_TASK_STATE_COMPLETE,
4034- GEARMAN_TASK_STATE_EXCEPTION,
4035- GEARMAN_TASK_STATE_FAIL,
4036- GEARMAN_TASK_STATE_FINISHED
4037-} gearman_task_state_t;
4038-
4039-/**
4040- * @ingroup gearman_job
4041- * Options for gearman_job_st.
4042- */
4043-typedef enum
4044-{
4045- GEARMAN_JOB_ALLOCATED= (1 << 0),
4046- GEARMAN_JOB_ASSIGNED_IN_USE= (1 << 1),
4047- GEARMAN_JOB_WORK_IN_USE= (1 << 2),
4048- GEARMAN_JOB_FINISHED= (1 << 3)
4049-} gearman_job_options_t;
4050-
4051-/**
4052 * @ingroup gearman_job
4053 * Priority levels for a job.
4054 */
4055@@ -309,22 +220,11 @@
4056 GEARMAN_CLIENT_TASK_IN_USE= (1 << 2),
4057 GEARMAN_CLIENT_UNBUFFERED_RESULT= (1 << 3),
4058 GEARMAN_CLIENT_NO_NEW= (1 << 4),
4059- GEARMAN_CLIENT_FREE_TASKS= (1 << 5)
4060+ GEARMAN_CLIENT_FREE_TASKS= (1 << 5),
4061+ GEARMAN_CLIENT_MAX= (1 << 6)
4062 } gearman_client_options_t;
4063
4064 /**
4065- * @ingroup gearman_client
4066- * States for gearman_client_st.
4067- */
4068-typedef enum
4069-{
4070- GEARMAN_CLIENT_STATE_IDLE,
4071- GEARMAN_CLIENT_STATE_NEW,
4072- GEARMAN_CLIENT_STATE_SUBMIT,
4073- GEARMAN_CLIENT_STATE_PACKET
4074-} gearman_client_state_t;
4075-
4076-/**
4077 * @ingroup gearman_worker
4078 * Options for gearman_worker_st.
4079 */
4080@@ -338,57 +238,21 @@
4081 GEARMAN_WORKER_WORK_JOB_IN_USE= (1 << 5),
4082 GEARMAN_WORKER_CHANGE= (1 << 6),
4083 GEARMAN_WORKER_GRAB_UNIQ= (1 << 7),
4084- GEARMAN_WORKER_TIMEOUT_RETURN= (1 << 8)
4085+ GEARMAN_WORKER_TIMEOUT_RETURN= (1 << 8),
4086+ GEARMAN_WORKER_MAX= (1 << 9)
4087 } gearman_worker_options_t;
4088
4089 /**
4090- * @ingroup gearman_worker
4091- * States for gearman_worker_st.
4092- */
4093-typedef enum
4094-{
4095- GEARMAN_WORKER_STATE_START,
4096- GEARMAN_WORKER_STATE_FUNCTION_SEND,
4097- GEARMAN_WORKER_STATE_CONNECT,
4098- GEARMAN_WORKER_STATE_GRAB_JOB_SEND,
4099- GEARMAN_WORKER_STATE_GRAB_JOB_RECV,
4100- GEARMAN_WORKER_STATE_PRE_SLEEP
4101-} gearman_worker_state_t;
4102-
4103-/**
4104- * @ingroup gearman_worker
4105- * Options for gearman_worker_function_st.
4106- */
4107-typedef enum
4108-{
4109- GEARMAN_WORKER_FUNCTION_PACKET_IN_USE= (1 << 0),
4110- GEARMAN_WORKER_FUNCTION_CHANGE= (1 << 1),
4111- GEARMAN_WORKER_FUNCTION_REMOVE= (1 << 2)
4112-} gearman_worker_function_options_t;
4113-
4114-/**
4115- * @ingroup gearman_worker
4116- * Work states for gearman_worker_st.
4117- */
4118-typedef enum
4119-{
4120- GEARMAN_WORKER_WORK_STATE_GRAB_JOB,
4121- GEARMAN_WORKER_WORK_STATE_FUNCTION,
4122- GEARMAN_WORKER_WORK_STATE_COMPLETE,
4123- GEARMAN_WORKER_WORK_STATE_FAIL
4124-} gearman_worker_work_state_t;
4125-
4126-/**
4127 * @addtogroup gearman_types Types
4128- * @ingroup gearman
4129+ * @ingroup gearman_universal
4130 * @ingroup gearman_client
4131 * @ingroup gearman_worker
4132 * @{
4133 */
4134
4135 /* Types. */
4136-typedef struct gearman_st gearman_st;
4137-typedef struct gearman_con_st gearman_con_st;
4138+typedef struct gearman_universal_st gearman_universal_st;
4139+typedef struct gearman_connection_st gearman_connection_st;
4140 typedef struct gearman_packet_st gearman_packet_st;
4141 typedef struct gearman_command_info_st gearman_command_info_st;
4142 typedef struct gearman_task_st gearman_task_st;
4143@@ -402,7 +266,7 @@
4144 typedef gearman_return_t (gearman_created_fn)(gearman_task_st *task);
4145 typedef gearman_return_t (gearman_data_fn)(gearman_task_st *task);
4146 typedef gearman_return_t (gearman_warning_fn)(gearman_task_st *task);
4147-typedef gearman_return_t (gearman_status_fn)(gearman_task_st *task);
4148+typedef gearman_return_t (gearman_universal_status_fn)(gearman_task_st *task);
4149 typedef gearman_return_t (gearman_complete_fn)(gearman_task_st *task);
4150 typedef gearman_return_t (gearman_exception_fn)(gearman_task_st *task);
4151 typedef gearman_return_t (gearman_fail_fn)(gearman_task_st *task);
4152@@ -415,7 +279,10 @@
4153 size_t *result_size,
4154 gearman_return_t *ret_ptr);
4155
4156-typedef gearman_return_t (gearman_event_watch_fn)(gearman_con_st *con,
4157+/**
4158+ @todo this is only used by the server and should be made private.
4159+ */
4160+typedef gearman_return_t (gearman_event_watch_fn)(gearman_connection_st *con,
4161 short events, void *context);
4162
4163 typedef void* (gearman_malloc_fn)(size_t size, void *context);
4164@@ -427,15 +294,15 @@
4165 typedef void (gearman_log_fn)(const char *line, gearman_verbose_t verbose,
4166 void *context);
4167
4168-typedef void (gearman_con_protocol_context_free_fn)(gearman_con_st *con,
4169- void *context);
4170+typedef void (gearman_connection_protocol_context_free_fn)(gearman_connection_st *con,
4171+ void *context);
4172
4173 typedef size_t (gearman_packet_pack_fn)(const gearman_packet_st *packet,
4174- gearman_con_st *con,
4175+ gearman_connection_st *con,
4176 void *data, size_t data_size,
4177 gearman_return_t *ret_ptr);
4178 typedef size_t (gearman_packet_unpack_fn)(gearman_packet_st *packet,
4179- gearman_con_st *con, const void *data,
4180+ gearman_connection_st *con, const void *data,
4181 size_t data_size,
4182 gearman_return_t *ret_ptr);
4183
4184
4185=== added file 'libgearman/core.c'
4186--- libgearman/core.c 1970-01-01 00:00:00 +0000
4187+++ libgearman/core.c 2009-12-30 19:24:13 +0000
4188@@ -0,0 +1,73 @@
4189+/* Gearman server and library
4190+ * Copyright (C) 2008 Brian Aker, Eric Day
4191+ * All rights reserved.
4192+ *
4193+ * Use and distribution licensed under the BSD license. See
4194+ * the COPYING file in the parent directory for full text.
4195+ */
4196+
4197+/**
4198+ * @file
4199+ * @brief Gearman State Definitions
4200+ */
4201+
4202+#include "common.h"
4203+
4204+
4205+gearman_return_t gearman_parse_servers(const char *servers,
4206+ gearman_parse_server_fn *function,
4207+ const void *context)
4208+{
4209+ const char *ptr= servers;
4210+ size_t x;
4211+ char host[NI_MAXHOST];
4212+ char port[NI_MAXSERV];
4213+ gearman_return_t ret;
4214+
4215+ if (ptr == NULL)
4216+ return (*function)(NULL, 0, (void *)context);
4217+
4218+ while (1)
4219+ {
4220+ x= 0;
4221+
4222+ while (*ptr != 0 && *ptr != ',' && *ptr != ':')
4223+ {
4224+ if (x < (NI_MAXHOST - 1))
4225+ host[x++]= *ptr;
4226+
4227+ ptr++;
4228+ }
4229+
4230+ host[x]= 0;
4231+
4232+ if (*ptr == ':')
4233+ {
4234+ ptr++;
4235+ x= 0;
4236+
4237+ while (*ptr != 0 && *ptr != ',')
4238+ {
4239+ if (x < (NI_MAXSERV - 1))
4240+ port[x++]= *ptr;
4241+
4242+ ptr++;
4243+ }
4244+
4245+ port[x]= 0;
4246+ }
4247+ else
4248+ port[0]= 0;
4249+
4250+ ret= (*function)(host, (in_port_t)atoi(port), (void *)context);
4251+ if (ret != GEARMAN_SUCCESS)
4252+ return ret;
4253+
4254+ if (*ptr == 0)
4255+ break;
4256+
4257+ ptr++;
4258+ }
4259+
4260+ return GEARMAN_SUCCESS;
4261+}
4262
4263=== added file 'libgearman/core.h'
4264--- libgearman/core.h 1970-01-01 00:00:00 +0000
4265+++ libgearman/core.h 2009-12-30 19:24:13 +0000
4266@@ -0,0 +1,49 @@
4267+/* Gearman server and library
4268+ * Copyright (C) 2008 Brian Aker, Eric Day
4269+ * All rights reserved.
4270+ *
4271+ * Use and distribution licensed under the BSD license. See
4272+ * the COPYING file in the parent directory for full text.
4273+ */
4274+
4275+/**
4276+ * @file
4277+ * @brief Gearman Declarations
4278+ */
4279+
4280+#ifndef __GEARMAN_CORE_H__
4281+#define __GEARMAN_CORE_H__
4282+
4283+#include <libgearman/universal.h>
4284+#include <libgearman/command.h>
4285+#include <libgearman/packet.h>
4286+#include <libgearman/connection.h>
4287+#include <libgearman/log.h>
4288+
4289+#ifdef __cplusplus
4290+extern "C" {
4291+#endif
4292+
4293+/**
4294+ * @ingroup gearman_universal
4295+ */
4296+/**
4297+ * Utility function used for parsing server lists.
4298+ *
4299+ * @param[in] servers String containing a list of servers to parse.
4300+ * @param[in] callback Function to call for each server that is found.
4301+ * @param[in] context Argument to pass along with callback function.
4302+ * @return Standard Gearman return value.
4303+ */
4304+GEARMAN_API
4305+gearman_return_t gearman_parse_servers(const char *servers,
4306+ gearman_parse_server_fn *callback,
4307+ const void *context);
4308+
4309+/** @} */
4310+
4311+#ifdef __cplusplus
4312+}
4313+#endif
4314+
4315+#endif /* __GEARMAN_CORE_H__ */
4316
4317=== added file 'libgearman/gearman.c'
4318--- libgearman/gearman.c 1970-01-01 00:00:00 +0000
4319+++ libgearman/gearman.c 2009-12-30 19:24:13 +0000
4320@@ -0,0 +1,57 @@
4321+/* Gearman server and library
4322+ * Copyright (C) 2008 Brian Aker, Eric Day
4323+ * All rights reserved.
4324+ *
4325+ * Use and distribution licensed under the BSD license. See
4326+ * the COPYING file in the parent directory for full text.
4327+ */
4328+
4329+/**
4330+ * @file
4331+ * @brief Gearman State Definitions
4332+ */
4333+
4334+#include "common.h"
4335+
4336+/**
4337+ * @addtogroup gearman_universal_static Static Gearman Declarations
4338+ * @ingroup gearman_universal
4339+ * @{
4340+ */
4341+
4342+/**
4343+ * Names of the verbose levels provided.
4344+ */
4345+static const char *_verbose_name[GEARMAN_VERBOSE_MAX]=
4346+{
4347+ "NEVER",
4348+ "FATAL",
4349+ "ERROR",
4350+ "INFO",
4351+ "DEBUG",
4352+ "CRAZY"
4353+};
4354+
4355+/** @} */
4356+
4357+/*
4358+ * Public Definitions
4359+ */
4360+
4361+const char *gearman_version(void)
4362+{
4363+ return PACKAGE_VERSION;
4364+}
4365+
4366+const char *gearman_bugreport(void)
4367+{
4368+ return PACKAGE_BUGREPORT;
4369+}
4370+
4371+const char *gearman_verbose_name(gearman_verbose_t verbose)
4372+{
4373+ if (verbose >= GEARMAN_VERBOSE_MAX)
4374+ return "UNKNOWN";
4375+
4376+ return _verbose_name[verbose];
4377+}
4378
4379=== added file 'libgearman/gearman.h'
4380--- libgearman/gearman.h 1970-01-01 00:00:00 +0000
4381+++ libgearman/gearman.h 2009-12-30 19:24:13 +0000
4382@@ -0,0 +1,112 @@
4383+/* Gearman server and library
4384+ * Copyright (C) 2008 Brian Aker, Eric Day
4385+ * All rights reserved.
4386+ *
4387+ * Use and distribution licensed under the BSD license. See
4388+ * the COPYING file in the parent directory for full text.
4389+ */
4390+
4391+/**
4392+ * @file
4393+ * @brief Gearman Declarations
4394+ */
4395+
4396+#ifndef __GEARMAN_H__
4397+#define __GEARMAN_H__
4398+
4399+#include <inttypes.h>
4400+#ifndef __cplusplus
4401+# include <stdbool.h>
4402+#endif
4403+#include <sys/types.h>
4404+#include <netinet/in.h>
4405+#include <sys/socket.h>
4406+#include <netdb.h>
4407+#include <arpa/inet.h>
4408+#include <poll.h>
4409+#include <sys/uio.h>
4410+#include <stdarg.h>
4411+#include <stdlib.h>
4412+
4413+#include <libgearman/visibility.h>
4414+#include <libgearman/constants.h>
4415+
4416+// Everything above this line must be in the order specified.
4417+#include <libgearman/core.h>
4418+#include <libgearman/task.h>
4419+#include <libgearman/job.h>
4420+
4421+#include <libgearman/worker.h>
4422+#include <libgearman/client.h>
4423+
4424+#ifdef __cplusplus
4425+extern "C" {
4426+#endif
4427+
4428+/**
4429+ * @addtogroup gearman Gearman Declarations
4430+ *
4431+ * This is a low level interface for gearman library instances. This is used
4432+ * internally by both client and worker interfaces, so you probably want to
4433+ * look there first. This is usually used to write lower level clients, workers,
4434+ * proxies, or your own server.
4435+ *
4436+ * There is no locking within a single gearman_universal_st structure, so for threaded
4437+ * applications you must either ensure isolation in the application or use
4438+ * multiple gearman_universal_st structures (for example, one for each thread).
4439+ *
4440+ * @{
4441+ */
4442+
4443+/**
4444+ * Get Gearman library version.
4445+ *
4446+ * @return Version string of library.
4447+ */
4448+GEARMAN_API
4449+const char *gearman_version(void);
4450+
4451+/**
4452+ * Get bug report URL.
4453+ *
4454+ * @return Bug report URL string.
4455+ */
4456+GEARMAN_API
4457+const char *gearman_bugreport(void);
4458+
4459+/**
4460+ * Get string with the name of the given verbose level.
4461+ *
4462+ * @param[in] verbose Verbose logging level.
4463+ * @return String form of verbose level.
4464+ */
4465+GEARMAN_API
4466+const char *gearman_verbose_name(gearman_verbose_t verbose);
4467+
4468+/**
4469+ * Get current socket I/O activity timeout value.
4470+ *
4471+ * @param[in] gearman_client_st or gearman_worker_st Structure previously initialized.
4472+ * @return Timeout in milliseconds to wait for I/O activity. A negative value
4473+ * means an infinite timeout.
4474+ * @note This is a utility macro.
4475+ */
4476+#define gearman_timeout(__object) ((__object)->gearman.timeout)
4477+
4478+/**
4479+ * Set socket I/O activity timeout for connections in a Gearman structure.
4480+ *
4481+ * @param[in] gearman_client_st or gearman_worker_st Structure previously initialized.
4482+ * @param[in] timeout Milliseconds to wait for I/O activity. A negative value
4483+ * means an infinite timeout.
4484+ * @note This is a utility macro.
4485+ */
4486+#define gearman_set_timeout(__object, __value) ((__object)->gearman.timeout)=(__value);
4487+
4488+/** @} */
4489+
4490+#ifdef __cplusplus
4491+}
4492+#endif
4493+
4494+#endif /* __GEARMAN_H__ */
4495
4496=== modified file 'libgearman/include.am'
4497--- libgearman/include.am 2009-12-18 19:25:00 +0000
4498+++ libgearman/include.am 2009-12-30 19:24:13 +0000
4499@@ -10,32 +10,53 @@
4500 # Included from Top Level Makefile.am
4501 # All paths should be given relative to the root
4502
4503+nobase_include_HEADERS += \
4504+ libgearman/client.h \
4505+ libgearman/command.h \
4506+ libgearman/connection.h \
4507+ libgearman/constants.h \
4508+ libgearman/core.h \
4509+ libgearman/gearman.h \
4510+ libgearman/job.h \
4511+ libgearman/packet.h \
4512+ libgearman/task.h \
4513+ libgearman/universal.h \
4514+ libgearman/visibility.h \
4515+ libgearman/worker.h
4516+
4517+noinst_HEADERS+= \
4518+ libgearman/common.h \
4519+ libgearman/log.h
4520+
4521+noinst_LTLIBRARIES+= libgearman/libgearmancore.la
4522+libgearman_libgearmancore_la_SOURCES= \
4523+ libgearman/connection.c \
4524+ libgearman/core.c \
4525+ libgearman/log.c \
4526+ libgearman/packet.c \
4527+ libgearman/universal.c
4528+
4529+libgearman_libgearmancore_la_CFLAGS= \
4530+ ${AM_CFLAGS} \
4531+ -DBUILDING_LIBGEARMAN
4532+
4533+#libgearman_libgearmancore_la_LDFLAGS= \
4534+# $(AM_LDFLAGS) \
4535+# -version-info \
4536+# $(GEARMAN_LIBRARY_VERSION)
4537+#
4538+#libgearman_libgearmancore_la_LIBADD= \
4539+# $(LTLIBUUID)
4540+
4541 lib_LTLIBRARIES+= libgearman/libgearman.la
4542-
4543-nobase_pkginclude_HEADERS += \
4544- libgearman/client.h \
4545- libgearman/conn.h \
4546- libgearman/constants.h \
4547- libgearman/gearman.h \
4548- libgearman/job.h \
4549- libgearman/packet.h \
4550- libgearman/structs.h \
4551- libgearman/task.h \
4552- libgearman/visibility.h \
4553- libgearman/worker.h
4554-
4555-noinst_HEADERS+= \
4556- libgearman/common.h \
4557- libgearman/gearman_local.h
4558-
4559 libgearman_libgearman_la_SOURCES= \
4560- libgearman/client.c \
4561- libgearman/conn.c \
4562- libgearman/gearman.c \
4563- libgearman/job.c \
4564- libgearman/packet.c \
4565- libgearman/task.c \
4566- libgearman/worker.c
4567+ libgearman/client.c \
4568+ libgearman/gearman.c \
4569+ libgearman/job.c \
4570+ libgearman/task.c \
4571+ libgearman/worker.c
4572+
4573+libgearman_libgearman_la_DEPENDENCIES= libgearman/libgearmancore.la
4574
4575 libgearman_libgearman_la_CFLAGS= \
4576 ${AM_CFLAGS} \
4577@@ -47,5 +68,6 @@
4578 $(GEARMAN_LIBRARY_VERSION)
4579
4580 libgearman_libgearman_la_LIBADD= \
4581+ libgearman/libgearmancore.la \
4582 $(LTLIBUUID)
4583
4584
4585=== modified file 'libgearman/job.c'
4586--- libgearman/job.c 2009-11-09 10:05:31 +0000
4587+++ libgearman/job.c 2009-12-30 19:24:13 +0000
4588@@ -30,6 +30,44 @@
4589 * Public Definitions
4590 */
4591
4592+gearman_job_st *gearman_job_create(gearman_worker_st *worker,
4593+ gearman_job_st *job)
4594+{
4595+ if (job == NULL)
4596+ {
4597+ job= malloc(sizeof(gearman_job_st));
4598+ if (job == NULL)
4599+ {
4600+ gearman_universal_set_error(worker->gearman, "_job_create", "malloc");
4601+ return NULL;
4602+ }
4603+
4604+ job->options.allocated= true;
4605+ }
4606+ else
4607+ {
4608+ job->options.allocated= false;
4609+ }
4610+
4611+ job->options.assigned_in_use= false;
4612+ job->options.work_in_use= false;
4613+ job->options.finished= false;
4614+
4615+ job->worker= worker;
4616+
4617+ if (worker->job_list != NULL)
4618+ worker->job_list->prev= job;
4619+ job->next= worker->job_list;
4620+ job->prev= NULL;
4621+ worker->job_list= job;
4622+ worker->job_count++;
4623+
4624+ job->con= NULL;
4625+
4626+ return job;
4627+}
4628+
4629+
4630 gearman_return_t gearman_job_send_data(gearman_job_st *job, const void *data,
4631 size_t data_size)
4632 {
4633@@ -37,20 +75,20 @@
4634 const void *args[2];
4635 size_t args_size[2];
4636
4637- if (!(job->options & GEARMAN_JOB_WORK_IN_USE))
4638+ if (! (job->options.work_in_use))
4639 {
4640 args[0]= job->assigned.arg[0];
4641 args_size[0]= job->assigned.arg_size[0];
4642 args[1]= data;
4643 args_size[1]= data_size;
4644- ret= gearman_add_packet_args(job->worker->gearman, &(job->work),
4645- GEARMAN_MAGIC_REQUEST,
4646- GEARMAN_COMMAND_WORK_DATA,
4647- args, args_size, 2);
4648+ ret= gearman_packet_create_args(job->worker->gearman, &(job->work),
4649+ GEARMAN_MAGIC_REQUEST,
4650+ GEARMAN_COMMAND_WORK_DATA,
4651+ args, args_size, 2);
4652 if (ret != GEARMAN_SUCCESS)
4653 return ret;
4654
4655- job->options|= GEARMAN_JOB_WORK_IN_USE;
4656+ job->options.work_in_use= true;
4657 }
4658
4659 return _job_send(job);
4660@@ -64,20 +102,20 @@
4661 const void *args[2];
4662 size_t args_size[2];
4663
4664- if (!(job->options & GEARMAN_JOB_WORK_IN_USE))
4665+ if (! (job->options.work_in_use))
4666 {
4667 args[0]= job->assigned.arg[0];
4668 args_size[0]= job->assigned.arg_size[0];
4669 args[1]= warning;
4670 args_size[1]= warning_size;
4671- ret= gearman_add_packet_args(job->worker->gearman, &(job->work),
4672- GEARMAN_MAGIC_REQUEST,
4673- GEARMAN_COMMAND_WORK_WARNING,
4674- args, args_size, 2);
4675+ ret= gearman_packet_create_args(job->worker->gearman, &(job->work),
4676+ GEARMAN_MAGIC_REQUEST,
4677+ GEARMAN_COMMAND_WORK_WARNING,
4678+ args, args_size, 2);
4679 if (ret != GEARMAN_SUCCESS)
4680 return ret;
4681
4682- job->options|= GEARMAN_JOB_WORK_IN_USE;
4683+ job->options.work_in_use= true;
4684 }
4685
4686 return _job_send(job);
4687@@ -93,7 +131,7 @@
4688 const void *args[3];
4689 size_t args_size[3];
4690
4691- if (!(job->options & GEARMAN_JOB_WORK_IN_USE))
4692+ if (! (job->options.work_in_use))
4693 {
4694 snprintf(numerator_string, 12, "%u", numerator);
4695 snprintf(denominator_string, 12, "%u", denominator);
4696@@ -104,14 +142,14 @@
4697 args_size[1]= strlen(numerator_string) + 1;
4698 args[2]= denominator_string;
4699 args_size[2]= strlen(denominator_string);
4700- ret= gearman_add_packet_args(job->worker->gearman, &(job->work),
4701+ ret= gearman_packet_create_args(job->worker->gearman, &(job->work),
4702 GEARMAN_MAGIC_REQUEST,
4703 GEARMAN_COMMAND_WORK_STATUS,
4704 args, args_size, 3);
4705 if (ret != GEARMAN_SUCCESS)
4706 return ret;
4707
4708- job->options|= GEARMAN_JOB_WORK_IN_USE;
4709+ job->options.work_in_use= true;
4710 }
4711
4712 return _job_send(job);
4713@@ -125,30 +163,31 @@
4714 const void *args[2];
4715 size_t args_size[2];
4716
4717- if (job->options & GEARMAN_JOB_FINISHED)
4718+ if (job->options.finished)
4719 return GEARMAN_SUCCESS;
4720
4721- if (!(job->options & GEARMAN_JOB_WORK_IN_USE))
4722+ if (! (job->options.work_in_use))
4723 {
4724 args[0]= job->assigned.arg[0];
4725 args_size[0]= job->assigned.arg_size[0];
4726 args[1]= result;
4727 args_size[1]= result_size;
4728- ret= gearman_add_packet_args(job->worker->gearman, &(job->work),
4729+ ret= gearman_packet_create_args(job->worker->gearman, &(job->work),
4730 GEARMAN_MAGIC_REQUEST,
4731 GEARMAN_COMMAND_WORK_COMPLETE,
4732 args, args_size, 2);
4733 if (ret != GEARMAN_SUCCESS)
4734 return ret;
4735
4736- job->options|= GEARMAN_JOB_WORK_IN_USE;
4737+ job->options.work_in_use= true;
4738 }
4739
4740 ret= _job_send(job);
4741 if (ret != GEARMAN_SUCCESS)
4742 return ret;
4743
4744- job->options|= GEARMAN_JOB_FINISHED;
4745+ job->options.finished= true;
4746+
4747 return GEARMAN_SUCCESS;
4748 }
4749
4750@@ -160,20 +199,20 @@
4751 const void *args[2];
4752 size_t args_size[2];
4753
4754- if (!(job->options & GEARMAN_JOB_WORK_IN_USE))
4755+ if (! (job->options.work_in_use))
4756 {
4757 args[0]= job->assigned.arg[0];
4758 args_size[0]= job->assigned.arg_size[0];
4759 args[1]= exception;
4760 args_size[1]= exception_size;
4761- ret= gearman_add_packet_args(job->worker->gearman, &(job->work),
4762+ ret= gearman_packet_create_args(job->worker->gearman, &(job->work),
4763 GEARMAN_MAGIC_REQUEST,
4764 GEARMAN_COMMAND_WORK_EXCEPTION,
4765 args, args_size, 2);
4766 if (ret != GEARMAN_SUCCESS)
4767 return ret;
4768
4769- job->options|= GEARMAN_JOB_WORK_IN_USE;
4770+ job->options.work_in_use= true;
4771 }
4772
4773 return _job_send(job);
4774@@ -185,28 +224,28 @@
4775 const void *args[1];
4776 size_t args_size[1];
4777
4778- if (job->options & GEARMAN_JOB_FINISHED)
4779+ if (job->options.finished)
4780 return GEARMAN_SUCCESS;
4781
4782- if (!(job->options & GEARMAN_JOB_WORK_IN_USE))
4783+ if (! (job->options.work_in_use))
4784 {
4785 args[0]= job->assigned.arg[0];
4786 args_size[0]= job->assigned.arg_size[0] - 1;
4787- ret= gearman_add_packet_args(job->worker->gearman, &(job->work),
4788- GEARMAN_MAGIC_REQUEST,
4789- GEARMAN_COMMAND_WORK_FAIL,
4790- args, args_size, 1);
4791+ ret= gearman_packet_create_args(job->worker->gearman, &(job->work),
4792+ GEARMAN_MAGIC_REQUEST,
4793+ GEARMAN_COMMAND_WORK_FAIL,
4794+ args, args_size, 1);
4795 if (ret != GEARMAN_SUCCESS)
4796 return ret;
4797
4798- job->options|= GEARMAN_JOB_WORK_IN_USE;
4799+ job->options.work_in_use= true;
4800 }
4801
4802 ret= _job_send(job);
4803 if (ret != GEARMAN_SUCCESS)
4804 return ret;
4805
4806- job->options|= GEARMAN_JOB_FINISHED;
4807+ job->options.finished= true;
4808 return GEARMAN_SUCCESS;
4809 }
4810
4811@@ -250,12 +289,12 @@
4812 {
4813 gearman_return_t ret;
4814
4815- ret= gearman_con_send(job->con, &(job->work), true);
4816+ ret= gearman_connection_send(job->con, &(job->work), true);
4817 if (ret != GEARMAN_SUCCESS)
4818 return ret;
4819
4820 gearman_packet_free(&(job->work));
4821- job->options&= (gearman_job_options_t)~GEARMAN_JOB_WORK_IN_USE;
4822+ job->options.work_in_use= false;
4823
4824 return GEARMAN_SUCCESS;
4825 }
4826
4827=== modified file 'libgearman/job.h'
4828--- libgearman/job.h 2009-10-29 00:11:45 +0000
4829+++ libgearman/job.h 2009-12-30 19:24:13 +0000
4830@@ -28,6 +28,50 @@
4831 * @{
4832 */
4833
4834+
4835+/**
4836+ * @ingroup gearman_job
4837+ */
4838+struct gearman_job_st
4839+{
4840+ struct {
4841+ bool allocated:1;
4842+ bool assigned_in_use:1;
4843+ bool work_in_use:1;
4844+ bool finished:1;
4845+ } options;
4846+ gearman_worker_st *worker;
4847+ gearman_job_st *next;
4848+ gearman_job_st *prev;
4849+ gearman_connection_st *con;
4850+ gearman_packet_st assigned;
4851+ gearman_packet_st work;
4852+};
4853+
4854+/**
4855+ * Initialize a job structure. Always check the return value even if passing
4856+ * in a pre-allocated structure. Some other initialization may have failed. It
4857+ * is not required to memset() a structure before providing it.
4858+ *
4859+ * @param[in] A valid gearman_worker_st.
4860+ * @param[in] gearman_job_st allocated structure, or NULL to allocate one.
4861+ * @return On success, a pointer to the (possibly allocated) structure. On
4862+ * failure this will be NULL.
4863+ */
4864+GEARMAN_LOCAL
4865+gearman_job_st *gearman_job_create(gearman_worker_st *worker,
4866+ gearman_job_st *job);
4867+
4868+/**
4869+ * Free a job structure.
4870+ *
4871+ * @param[in] job Structure previously initialized with
4872+ * gearman_worker_grab_job().
4873+ */
4874+GEARMAN_API
4875+void gearman_job_free(gearman_job_st *job);
4876+
4877+
4878 /**
4879 * Send data for a running job.
4880 */
4881
4882=== added file 'libgearman/log.c'
4883--- libgearman/log.c 1970-01-01 00:00:00 +0000
4884+++ libgearman/log.c 2009-12-30 19:24:13 +0000
4885@@ -0,0 +1,101 @@
4886+/* Gearman server and library
4887+ * Copyright (C) 2008-2009 Brian Aker, Eric Day
4888+ * All rights reserved.
4889+ *
4890+ * Use and distribution licensed under the BSD license. See
4891+ * the COPYING file in the parent directory for full text.
4892+ */
4893+
4894+/**
4895+ * @file
4896+ * @brief Gearman State Definitions
4897+ */
4898+
4899+#include "common.h"
4900+
4901+
4902+void gearman_log(gearman_universal_st *state, gearman_verbose_t verbose,
4903+ const char *format, va_list args)
4904+{
4905+ char log_buffer[GEARMAN_MAX_ERROR_SIZE];
4906+
4907+ if (state->log_fn == NULL)
4908+ {
4909+ printf("%5s: ", gearman_verbose_name(verbose));
4910+ vprintf(format, args);
4911+ printf("\n");
4912+ }
4913+ else
4914+ {
4915+ vsnprintf(log_buffer, GEARMAN_MAX_ERROR_SIZE, format, args);
4916+ state->log_fn(log_buffer, verbose, (void *)state->log_context);
4917+ }
4918+}
4919+
4920+
4921+void gearman_log_fatal(gearman_universal_st *gearman, const char *format,
4922+ ...)
4923+{
4924+ va_list args;
4925+
4926+ if (gearman->verbose >= GEARMAN_VERBOSE_FATAL)
4927+ {
4928+ va_start(args, format);
4929+ gearman_log(gearman, GEARMAN_VERBOSE_FATAL, format, args);
4930+ va_end(args);
4931+ }
4932+}
4933+
4934+void gearman_log_error(gearman_universal_st *gearman, const char *format,
4935+ ...)
4936+{
4937+ va_list args;
4938+
4939+ if (gearman->verbose >= GEARMAN_VERBOSE_ERROR)
4940+ {
4941+ va_start(args, format);
4942+ gearman_log(gearman, GEARMAN_VERBOSE_ERROR, format, args);
4943+ va_end(args);
4944+ }
4945+}
4946+
4947+void gearman_log_info(gearman_universal_st *gearman, const char *format,
4948+ ...)
4949+{
4950+ va_list args;
4951+
4952+ if (gearman->verbose >= GEARMAN_VERBOSE_INFO)
4953+ {
4954+ va_start(args, format);
4955+ gearman_log(gearman, GEARMAN_VERBOSE_INFO, format, args);
4956+ va_end(args);
4957+ }
4958+}
4959+
4960+void gearman_log_debug(gearman_universal_st *gearman, const char *format,
4961+ ...)
4962+{
4963+ va_list args;
4964+
4965+ if (gearman->verbose >= GEARMAN_VERBOSE_DEBUG)
4966+ {
4967+ va_start(args, format);
4968+ gearman_log(gearman, GEARMAN_VERBOSE_DEBUG, format, args);
4969+ va_end(args);
4970+ }
4971+}
4972+
4973+void gearman_log_crazy(gearman_universal_st *gearman, const char *format,
4974+ ...)
4975+{
4976+ va_list args;
4977+
4978+ if (gearman->verbose >= GEARMAN_VERBOSE_CRAZY)
4979+ {
4980+ va_start(args, format);
4981+ gearman_log(gearman, GEARMAN_VERBOSE_CRAZY, format, args);
4982+ va_end(args);
4983+ }
4984+}
4985+
4986+
4987
4988=== renamed file 'libgearman/gearman_local.h' => 'libgearman/log.h'
4989--- libgearman/gearman_local.h 2009-10-29 00:11:45 +0000
4990+++ libgearman/log.h 2009-12-30 19:24:13 +0000
4991@@ -11,8 +11,8 @@
4992 * @brief Local Gearman Declarations
4993 */
4994
4995-#ifndef __GEARMAN_LOCAL_H__
4996-#define __GEARMAN_LOCAL_H__
4997+#ifndef __GEARMAN_LOG_H__
4998+#define __GEARMAN_LOG_H__
4999
5000 #ifdef __cplusplus
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches