Merge lp:~mordred/gearmand/fix-1.0-build into lp:gearmand/1.0
- fix-1.0-build
- Merge into 1.0
Proposed by
Monty Taylor
Status: | Merged |
---|---|
Merge reported by: | Monty Taylor |
Merged at revision: | not available |
Proposed branch: | lp:~mordred/gearmand/fix-1.0-build |
Merge into: | lp:gearmand/1.0 |
Diff against target: |
18576 lines (+9419/-5025) (has conflicts) 110 files modified
.quickly (+5/-0) ChangeLog (+14/-0) HACKING (+13/-0) Makefile.am (+7/-6) bin/gearman.c (+4/-0) config/autorun.sh (+1/-1) config/pandora-plugin (+667/-0) config/uncrustify.cfg (+1112/-0) configure.ac (+8/-1) gearmand/gearmand.cc (+239/-387) gearmand/include.am (+4/-3) libgearman-server/client.cc (+14/-1) libgearman-server/client.h (+4/-44) libgearman-server/common.h (+21/-28) libgearman-server/conf.h (+0/-103) libgearman-server/conf_module.h (+0/-80) libgearman-server/connection.cc (+523/-186) libgearman-server/connection.h (+145/-152) libgearman-server/constants.h (+2/-31) libgearman-server/function.cc (+45/-24) libgearman-server/function.h (+7/-20) libgearman-server/gearmand.cc (+225/-139) libgearman-server/gearmand.h (+123/-138) libgearman-server/gearmand_con.cc (+79/-148) libgearman-server/gearmand_con.h (+17/-19) libgearman-server/gearmand_thread.cc (+191/-247) libgearman-server/gearmand_thread.h (+47/-54) libgearman-server/gqueue.h (+87/-0) libgearman-server/include.am (+45/-28) libgearman-server/job.cc (+100/-116) libgearman-server/job.h (+80/-70) libgearman-server/log.cc (+111/-97) libgearman-server/log.h (+78/-75) libgearman-server/logger.cc (+13/-0) libgearman-server/logger.h (+64/-0) libgearman-server/logger/standard.cc (+106/-0) libgearman-server/logger/standard.h (+52/-0) libgearman-server/logger/stats.cc (+75/-0) libgearman-server/logger/stats.h (+49/-0) libgearman-server/logger/syslog.cc (+71/-0) libgearman-server/logger/syslog.h (+43/-0) libgearman-server/packet.cc (+28/-1) libgearman-server/packet.h (+9/-55) libgearman-server/port.cc (+228/-0) libgearman-server/port.h (+63/-0) libgearman-server/protocol.h (+33/-0) libgearman-server/protocol/http.cc (+92/-101) libgearman-server/protocol/http.h (+49/-21) libgearman-server/queue/libdrizzle.cc (+195/-254) libgearman-server/queue/libdrizzle.h (+51/-48) libgearman-server/queue/libmemcached.cc (+108/-227) libgearman-server/queue/libmemcached.h (+35/-49) libgearman-server/queue/libpq.cc (+141/-193) libgearman-server/queue/libpq.h (+46/-47) libgearman-server/queue/libsqlite3.cc (+271/-357) libgearman-server/queue/libsqlite3.h (+47/-53) libgearman-server/queue/libtokyocabinet.cc (+88/-214) libgearman-server/queue/libtokyocabinet.h (+36/-52) libgearman-server/server.cc (+622/-380) libgearman-server/server.h (+83/-144) libgearman-server/service.cc (+8/-0) libgearman-server/service.h (+34/-0) libgearman-server/service/echo.cc (+86/-0) libgearman-server/service/echo.h (+39/-0) libgearman-server/services.cc (+26/-0) libgearman-server/services.h (+60/-0) libgearman-server/thread.cc (+180/-197) libgearman-server/thread.h (+75/-111) libgearman-server/wake.cc (+116/-0) libgearman-server/wake.h (+57/-0) libgearman-server/worker.cc (+44/-22) libgearman-server/worker.h (+27/-47) libgearman/constants.h (+1/-0) libgearman/universal.c (+0/-7) libgearman/universal.h (+64/-5) libgearman/worker.c (+15/-4) libgearman/worker.h (+1/-0) m4/ac_cxx_header_stdcxx_98.m4 (+22/-6) m4/acx_pthread.m4 (+68/-73) m4/gettext.m4 (+379/-0) m4/iconv.m4 (+180/-0) m4/pandora_canonical.m4 (+8/-7) m4/pandora_drizzle_build.m4 (+2/-1) m4/pandora_enable_dtrace.m4 (+32/-17) m4/pandora_ensure_gcc_version.m4 (+39/-16) m4/pandora_have_boost.m4 (+4/-5) m4/pandora_have_innodb.m4 (+0/-41) m4/pandora_have_libboost_options.m4 (+47/-0) m4/pandora_have_libboost_thread.m4 (+45/-0) m4/pandora_have_libhashkit.m4 (+42/-0) m4/pandora_have_libldap.m4 (+73/-0) m4/pandora_have_libpqxx.m4 (+44/-0) m4/pandora_have_libvbucket.m4 (+40/-0) m4/pandora_have_sasl.m4 (+133/-0) m4/pandora_platform.m4 (+10/-1) m4/pandora_plugins.m4 (+6/-2) m4/pandora_stack_direction.m4 (+0/-39) m4/pandora_vc_build.m4 (+6/-4) m4/pandora_warnings.m4 (+7/-1) m4/po.m4 (+449/-0) m4/progtest.m4 (+92/-0) tests/client_test.c (+71/-0) tests/include.am (+1/-2) tests/internals.c (+0/-18) tests/memcached_test.c (+1/-1) tests/round_robin.c (+1/-1) tests/test_gearmand.c (+62/-0) tests/tokyocabinet_test.c (+1/-1) tests/worker_test.c (+5/-1) unittests/include.am (+0/-1) Text conflict in ChangeLog Text conflict in bin/gearman.c Text conflict in configure.ac Text conflict in libgearman-server/client.cc Contents conflict in libgearman-server/conf.c Contents conflict in libgearman-server/conf_module.c Text conflict in libgearman-server/connection.cc Text conflict in libgearman-server/function.cc Text conflict in libgearman-server/gearmand.cc Text conflict in libgearman-server/gearmand_con.cc Text conflict in libgearman-server/gearmand_thread.cc Text conflict in libgearman-server/job.cc Text conflict in libgearman-server/packet.cc Text conflict in libgearman-server/protocol/http.cc Text conflict in libgearman-server/queue/libdrizzle.cc Text conflict in libgearman-server/queue/libpq.cc Text conflict in libgearman-server/queue/libsqlite3.cc Text conflict in libgearman-server/server.cc Text conflict in libgearman-server/thread.cc Text conflict in libgearman-server/worker.cc Text conflict in tests/client_test.c Text conflict in tests/test_gearmand.c |
To merge this branch: | bzr merge lp:~mordred/gearmand/fix-1.0-build |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brian Aker | Pending | ||
Review via email: mp+28949@code.launchpad.net |
Commit message
Description of the change
Updates pandora.
Fixes boost linking.
Fixes the boost system header include file issue on FreeBSD.
To post a comment you must log in.
- 358. By Monty Taylor
-
Remove two old crufty files.
- 359. By Monty Taylor
-
Updated pandora-build files to version 0.135
- 360. By Monty Taylor
-
Merged in no-error removal.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file '.quickly' | |||
2 | --- .quickly 1970-01-01 00:00:00 +0000 | |||
3 | +++ .quickly 2010-07-01 01:31:26 +0000 | |||
4 | @@ -0,0 +1,5 @@ | |||
5 | 1 | project = gearmand | ||
6 | 2 | version = 1.0 | ||
7 | 3 | template = pandora-build | ||
8 | 4 | project-type = application | ||
9 | 5 | pandora-version = 0.135 | ||
10 | 0 | 6 | ||
11 | === modified file 'ChangeLog' | |||
12 | --- ChangeLog 2010-06-30 20:04:51 +0000 | |||
13 | +++ ChangeLog 2010-07-01 01:31:26 +0000 | |||
14 | @@ -1,8 +1,22 @@ | |||
15 | 1 | <<<<<<< TREE | ||
16 | 1 | 0.14 Wed Jun 30 13:04:39 PDT 2010 | 2 | 0.14 Wed Jun 30 13:04:39 PDT 2010 |
17 | 2 | * Leak in SQLite resolved. | 3 | * Leak in SQLite resolved. |
18 | 3 | * updated build configs | 4 | * updated build configs |
19 | 4 | * Increased testting. | 5 | * Increased testting. |
20 | 5 | 6 | ||
21 | 7 | ======= | ||
22 | 8 | 1.00 Mon Jun 14 12:17:09 PDT 2010 | ||
23 | 9 | * Server written in C++ now. | ||
24 | 10 | * Making use of boost command line arguments. | ||
25 | 11 | * New debugging can now be done with the server. | ||
26 | 12 | * New Logger functionality added so that you can either use syslog, or | ||
27 | 13 | use stderr. | ||
28 | 14 | * It is possible to have "workers" internally in the server that act | ||
29 | 15 | as internal services. | ||
30 | 16 | |||
31 | 17 | |||
32 | 18 | |||
33 | 19 | >>>>>>> MERGE-SOURCE | ||
34 | 6 | 0.13 Sun Apr 4 14:45:08 PDT 2010 | 20 | 0.13 Sun Apr 4 14:45:08 PDT 2010 |
35 | 7 | * Fix for bug #518512. | 21 | * Fix for bug #518512. |
36 | 8 | * Use OR REPLACE syntax for inserting items into the sqlite. | 22 | * Use OR REPLACE syntax for inserting items into the sqlite. |
37 | 9 | 23 | ||
38 | === added file 'HACKING' | |||
39 | --- HACKING 1970-01-01 00:00:00 +0000 | |||
40 | +++ HACKING 2010-07-01 01:31:26 +0000 | |||
41 | @@ -0,0 +1,13 @@ | |||
42 | 1 | Hi! | ||
43 | 2 | |||
44 | 3 | If you are working on the server here are some handy environmental variables | ||
45 | 4 | you can set so that you can debug make test: | ||
46 | 5 | |||
47 | 6 | GEARMAN_VALGRIND <- runs the server under valgrind. | ||
48 | 7 | GEARMAN_MANUAL_GDB <-- runs the server under a remote version of GDB. | ||
49 | 8 | GEARMAN_LOG <-- generates a log file for you with the output of the debug for the server | ||
50 | 9 | |||
51 | 10 | GDB will pause the server while you do run the GDB command. | ||
52 | 11 | |||
53 | 12 | Cheers, | ||
54 | 13 | -Brian | ||
55 | 0 | 14 | ||
56 | === modified file 'Makefile.am' | |||
57 | --- Makefile.am 2010-06-30 15:21:36 +0000 | |||
58 | +++ Makefile.am 2010-07-01 01:31:26 +0000 | |||
59 | @@ -35,12 +35,13 @@ | |||
60 | 35 | TESTS += ${check_PROGRAMS} | 35 | TESTS += ${check_PROGRAMS} |
61 | 36 | 36 | ||
62 | 37 | EXTRA_DIST+= \ | 37 | EXTRA_DIST+= \ |
69 | 38 | docs/Doxyfile.api \ | 38 | HACKING \ |
70 | 39 | docs/Doxyfile.dev \ | 39 | docs/Doxyfile.api \ |
71 | 40 | docs/api_header.html \ | 40 | docs/Doxyfile.dev \ |
72 | 41 | docs/dev_header.html \ | 41 | docs/api_header.html \ |
73 | 42 | docs/doxygen.h \ | 42 | docs/dev_header.html \ |
74 | 43 | scripts/README.solaris | 43 | docs/doxygen.h \ |
75 | 44 | scripts/README.solaris | ||
76 | 44 | 45 | ||
77 | 45 | docs: all | 46 | docs: all |
78 | 46 | ${DOXYGEN} docs/Doxyfile.api | 47 | ${DOXYGEN} docs/Doxyfile.api |
79 | 47 | 48 | ||
80 | === modified file 'bin/gearman.c' | |||
81 | --- bin/gearman.c 2010-06-30 20:04:05 +0000 | |||
82 | +++ bin/gearman.c 2010-07-01 01:31:26 +0000 | |||
83 | @@ -588,9 +588,13 @@ | |||
84 | 588 | { | 588 | { |
85 | 589 | ret= gearman_worker_work(&worker); | 589 | ret= gearman_worker_work(&worker); |
86 | 590 | if (ret != GEARMAN_SUCCESS) | 590 | if (ret != GEARMAN_SUCCESS) |
87 | 591 | <<<<<<< TREE | ||
88 | 591 | { | 592 | { |
89 | 592 | GEARMAN_ERROR("gearman_worker_work:%s", gearman_worker_error(&worker)); | 593 | GEARMAN_ERROR("gearman_worker_work:%s", gearman_worker_error(&worker)); |
90 | 593 | } | 594 | } |
91 | 595 | ======= | ||
92 | 596 | GEARMAN_ERROR("gearman_worker_work:%s", gearman_worker_error(&worker)); | ||
93 | 597 | >>>>>>> MERGE-SOURCE | ||
94 | 594 | 598 | ||
95 | 595 | if (args->count > 0) | 599 | if (args->count > 0) |
96 | 596 | { | 600 | { |
97 | 597 | 601 | ||
98 | === modified file 'config/autorun.sh' | |||
99 | --- config/autorun.sh 2009-12-18 18:02:39 +0000 | |||
100 | +++ config/autorun.sh 2010-07-01 01:31:26 +0000 | |||
101 | @@ -35,7 +35,7 @@ | |||
102 | 35 | LIBTOOLIZE_FLAGS=" --automake --copy --force" | 35 | LIBTOOLIZE_FLAGS=" --automake --copy --force" |
103 | 36 | # --add-missing instructs automake to install missing auxiliary files | 36 | # --add-missing instructs automake to install missing auxiliary files |
104 | 37 | # and --force to overwrite them if they already exist | 37 | # and --force to overwrite them if they already exist |
106 | 38 | AUTOMAKE_FLAGS="--add-missing --copy --force" | 38 | AUTOMAKE_FLAGS="--add-missing --copy --force --foreign" |
107 | 39 | ACLOCAL_FLAGS="-I m4" | 39 | ACLOCAL_FLAGS="-I m4" |
108 | 40 | 40 | ||
109 | 41 | ARGV0=$0 | 41 | ARGV0=$0 |
110 | 42 | 42 | ||
111 | === added file 'config/pandora-plugin' | |||
112 | --- config/pandora-plugin 1970-01-01 00:00:00 +0000 | |||
113 | +++ config/pandora-plugin 2010-07-01 01:31:26 +0000 | |||
114 | @@ -0,0 +1,667 @@ | |||
115 | 1 | #!/usr/bin/python | ||
116 | 2 | |||
117 | 3 | # Copyright (C) 2009 Sun Microsystems | ||
118 | 4 | # | ||
119 | 5 | # This program is free software; you can redistribute it and/or modify | ||
120 | 6 | # it under the terms of the GNU General Public License as published by | ||
121 | 7 | # the Free Software Foundation; version 2 of the License. | ||
122 | 8 | # | ||
123 | 9 | # This program is distributed in the hope that it will be useful, | ||
124 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
125 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
126 | 12 | # GNU General Public License for more details. | ||
127 | 13 | # | ||
128 | 14 | # You should have received a copy of the GNU General Public License | ||
129 | 15 | # along with this program; if not, write to the Free Software | ||
130 | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
131 | 17 | |||
132 | 18 | pandora_plugin_file = 'config/pandora-plugin.ini' | ||
133 | 19 | |||
134 | 20 | # Find plugins in the tree and add them to the build system | ||
135 | 21 | |||
136 | 22 | import ConfigParser, os, sys | ||
137 | 23 | import datetime, time | ||
138 | 24 | import subprocess | ||
139 | 25 | |||
140 | 26 | plugin_am_file=None | ||
141 | 27 | plugin_ac_file=None | ||
142 | 28 | |||
143 | 29 | class ChangeProtectedFile(object): | ||
144 | 30 | |||
145 | 31 | def __init__(self, fname): | ||
146 | 32 | self.bogus_file= False | ||
147 | 33 | self.real_fname= fname | ||
148 | 34 | self.new_fname= "%s.new" % fname | ||
149 | 35 | try: | ||
150 | 36 | self.new_file= open(self.new_fname,'w+') | ||
151 | 37 | except IOError: | ||
152 | 38 | self.bogus_file= True | ||
153 | 39 | |||
154 | 40 | def write(self, text): | ||
155 | 41 | if not self.bogus_file: | ||
156 | 42 | self.new_file.write(text) | ||
157 | 43 | |||
158 | 44 | # We've written all of this out into .new files, now we only copy them | ||
159 | 45 | # over the old ones if they are different, so that we don't cause | ||
160 | 46 | # unnecessary recompiles | ||
161 | 47 | def close(self): | ||
162 | 48 | """Return True if the file had changed.""" | ||
163 | 49 | if self.bogus_file: | ||
164 | 50 | return | ||
165 | 51 | self.new_file.seek(0) | ||
166 | 52 | new_content = self.new_file.read() | ||
167 | 53 | self.new_file.close() | ||
168 | 54 | try: | ||
169 | 55 | old_file = file(self.real_fname, 'r') | ||
170 | 56 | old_content = old_file.read() | ||
171 | 57 | old_file.close() | ||
172 | 58 | except IOError: | ||
173 | 59 | old_content = None | ||
174 | 60 | if new_content != old_content: | ||
175 | 61 | if old_content != None: | ||
176 | 62 | os.unlink(self.real_fname) | ||
177 | 63 | os.rename(self.new_fname, self.real_fname) | ||
178 | 64 | return True | ||
179 | 65 | else: | ||
180 | 66 | try: | ||
181 | 67 | os.unlink(self.new_fname) | ||
182 | 68 | except: | ||
183 | 69 | pass | ||
184 | 70 | |||
185 | 71 | |||
186 | 72 | def write_external_configure(plugin, plugin_file): | ||
187 | 73 | """Write the initial bits of the configure.ac file""" | ||
188 | 74 | if not os.path.exists('m4'): | ||
189 | 75 | os.mkdir('m4') | ||
190 | 76 | plugin_file.write(""" | ||
191 | 77 | AC_PREREQ(2.59)dnl Minimum Autoconf version required. | ||
192 | 78 | AC_INIT([%(name)s],[%(version)s],[%(url)s]) | ||
193 | 79 | AC_CONFIG_SRCDIR([%(main_source)s]) | ||
194 | 80 | AC_CONFIG_AUX_DIR(config) | ||
195 | 81 | |||
196 | 82 | PANDORA_CANONICAL_TARGET(less-warnings, warnings-always-on, require-cxx, force-gcc42,skip-visibility) | ||
197 | 83 | |||
198 | 84 | PANDORA_REQUIRE_LIBPROTOBUF | ||
199 | 85 | PANDORA_PROTOBUF_REQUIRE_VERSION([2.1.0]) | ||
200 | 86 | PANDORA_REQUIRE_PROTOC | ||
201 | 87 | |||
202 | 88 | AC_LANG_PUSH(C++) | ||
203 | 89 | PANDORA_REQUIRE_PTHREAD | ||
204 | 90 | PANDORA_REQUIRE_LIBDL | ||
205 | 91 | AC_LANG_POP | ||
206 | 92 | |||
207 | 93 | PANDORA_USE_BETTER_MALLOC | ||
208 | 94 | |||
209 | 95 | PANDORA_DRIZZLE_BUILD | ||
210 | 96 | """ % plugin) | ||
211 | 97 | |||
212 | 98 | write_plugin_ac(plugin, plugin_file) | ||
213 | 99 | |||
214 | 100 | plugin_file.write(""" | ||
215 | 101 | AC_CONFIG_FILES(Makefile) | ||
216 | 102 | |||
217 | 103 | AC_OUTPUT | ||
218 | 104 | |||
219 | 105 | echo "---" | ||
220 | 106 | echo "Configuration summary for $PACKAGE_NAME version $VERSION $PANDORA_RELEASE_COMMENT" | ||
221 | 107 | echo "" | ||
222 | 108 | echo " * Installation prefix: $prefix" | ||
223 | 109 | echo " * System type: $host_vendor-$host_os" | ||
224 | 110 | echo " * Host CPU: $host_cpu" | ||
225 | 111 | echo " * C Compiler: $CC_VERSION" | ||
226 | 112 | echo " * C++ Compiler: $CXX_VERSION" | ||
227 | 113 | echo " * Debug enabled: $with_debug" | ||
228 | 114 | echo " * Warnings as failure: $ac_cv_warnings_as_errors" | ||
229 | 115 | echo " * C++ cstdint location: $ac_cv_cxx_cstdint" | ||
230 | 116 | echo " * C++ hash_map location: $ac_cv_cxx_hash_map" | ||
231 | 117 | echo " * C++ hash namespace: $ac_cv_cxx_hash_namespace" | ||
232 | 118 | echo " * C++ shared_ptr namespace: $ac_cv_shared_ptr_namespace" | ||
233 | 119 | echo "" | ||
234 | 120 | echo "---" | ||
235 | 121 | |||
236 | 122 | """ % plugin) | ||
237 | 123 | |||
238 | 124 | def write_external_makefile(plugin, plugin_file): | ||
239 | 125 | |||
240 | 126 | plugin_file.write(""" | ||
241 | 127 | ACLOCAL_AMFLAGS = -I m4 --force | ||
242 | 128 | VERSION=$(PANDORA_RELEASE_VERSION) | ||
243 | 129 | |||
244 | 130 | pkgplugindir=%(pkgplugindir)s | ||
245 | 131 | EXTRA_DIST = plugin.ini | ||
246 | 132 | |||
247 | 133 | """ % plugin) | ||
248 | 134 | if plugin['headers'] != "": | ||
249 | 135 | plugin_file.write("noinst_HEADERS = %(headers)s\n" % plugin) | ||
250 | 136 | if plugin['install_headers'] != "": | ||
251 | 137 | plugin_file.write("nobase_include_HEADERS += %(install_headers)s\n" % plugin) | ||
252 | 138 | if plugin['testsuite']: | ||
253 | 139 | if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "": | ||
254 | 140 | plugin_file.write("EXTRA_DIST += %(testsuitedir)s\n" % plugin) | ||
255 | 141 | plugin_file.write(""" | ||
256 | 142 | pkgplugin_LTLIBRARIES=%(libname)s.la | ||
257 | 143 | %(libname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS) | ||
258 | 144 | %(libname)s_la_LIBADD=%(libs)s | ||
259 | 145 | %(libname)s_la_DEPENDENCIES=%(libs)s | ||
260 | 146 | %(libname)s_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_DYNAMIC_PLUGIN -DPANDORA_MODULE_NAME=%(module_name)s -DPANDORA_MODULE_AUTHOR='"%(author)s"' -DPANDORA_MODULE_TITLE='"%(title)s"' -DPANDORA_MODULE_VERSION='"%(version)s"' -DPANDORA_MODULE_LICENSE=%(license)s %(cppflags)s | ||
261 | 147 | %(libname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s | ||
262 | 148 | %(libname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s | ||
263 | 149 | %(libname)s_la_SOURCES=%(sources)s | ||
264 | 150 | check_PROGRAMS += %(tests)s | ||
265 | 151 | """ % plugin) | ||
266 | 152 | plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am') | ||
267 | 153 | if os.path.exists(plugin_am_file): | ||
268 | 154 | plugin_file.write('include %s\n' % plugin_am_file) | ||
269 | 155 | |||
270 | 156 | def write_external_plugin(): | ||
271 | 157 | """Return True if the plugin had changed.""" | ||
272 | 158 | plugin = read_plugin_ini('.') | ||
273 | 159 | expand_plugin_ini(plugin) | ||
274 | 160 | plugin_file = ChangeProtectedFile('configure.ac') | ||
275 | 161 | write_external_configure(plugin, plugin_file) | ||
276 | 162 | result = plugin_file.close() | ||
277 | 163 | plugin_file = ChangeProtectedFile('Makefile.am') | ||
278 | 164 | write_external_makefile(plugin, plugin_file) | ||
279 | 165 | # Write some stub configure.ac and Makefile.am files that include the above | ||
280 | 166 | result = plugin_file.close() or result | ||
281 | 167 | return result | ||
282 | 168 | |||
283 | 169 | def write_plugin(plugin, plugin_ini_list): | ||
284 | 170 | # Since this function is recursive, make sure we're not already in it. | ||
285 | 171 | if plugin.has_key('writing_status'): | ||
286 | 172 | if plugin['writing_status'] == 'done': | ||
287 | 173 | return | ||
288 | 174 | else: | ||
289 | 175 | print "Dependency loop detected with %s" % plugin['name'] | ||
290 | 176 | exit(1) | ||
291 | 177 | |||
292 | 178 | plugin['writing_status'] = 'dependencies' | ||
293 | 179 | |||
294 | 180 | # Write all dependencies first to get around annoying automake bug | ||
295 | 181 | for dependency in plugin['dependency_list']: | ||
296 | 182 | found = False | ||
297 | 183 | for find_plugin in plugin_ini_list: | ||
298 | 184 | if find_plugin['module_name'] == dependency: | ||
299 | 185 | found = True | ||
300 | 186 | write_plugin(find_plugin, plugin_ini_list) | ||
301 | 187 | break | ||
302 | 188 | if found is False: | ||
303 | 189 | print "Could not find dependency %s: %s" % (plugin['name'], dependency) | ||
304 | 190 | exit(1) | ||
305 | 191 | |||
306 | 192 | write_plugin_ac(plugin, plugin_ac_file) | ||
307 | 193 | write_plugin_am(plugin, plugin_am_file) | ||
308 | 194 | plugin['writing_status'] = 'done' | ||
309 | 195 | |||
310 | 196 | def write_plugin_ac(plugin, plugin_ac): | ||
311 | 197 | # | ||
312 | 198 | # Write plugin config instructions into plugin.ac file. | ||
313 | 199 | # | ||
314 | 200 | plugin_ac_file=os.path.join(plugin['rel_path'],'plugin.ac') | ||
315 | 201 | plugin_m4_dir=os.path.join(plugin['rel_path'],'m4') | ||
316 | 202 | plugin_m4_files=[] | ||
317 | 203 | if os.path.exists(plugin_m4_dir) and os.path.isdir(plugin_m4_dir): | ||
318 | 204 | for m4_file in os.listdir(plugin_m4_dir): | ||
319 | 205 | if os.path.splitext(m4_file)[-1] == '.m4': | ||
320 | 206 | plugin_m4_files.append(os.path.join(plugin['rel_path'], m4_file)) | ||
321 | 207 | plugin_ac.write(""" | ||
322 | 208 | dnl Config for %(title)s | ||
323 | 209 | """ % plugin) | ||
324 | 210 | for m4_file in plugin_m4_files: | ||
325 | 211 | plugin_ac.write('m4_sinclude([%s])\n' % m4_file) | ||
326 | 212 | plugin['plugin_dep_libs']=" ".join(["\${top_builddir}/%s" % f for f in plugin['libs'].split()]) | ||
327 | 213 | |||
328 | 214 | plugin_ac.write(""" | ||
329 | 215 | AC_ARG_WITH([%(name_with_dashes)s-plugin],[ | ||
330 | 216 | dnl indented wierd to make the help output correct | ||
331 | 217 | AS_HELP_STRING([--with-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=%(enabled)s@:>@]) | ||
332 | 218 | AS_HELP_STRING([--without-%(name_with_dashes)s-plugin],[Disable building %(title)s]) | ||
333 | 219 | ],[ | ||
334 | 220 | with_%(name)s_plugin="$withval" | ||
335 | 221 | AS_IF([test "x$with_%(name)s_plugin" = "xyes"],[ | ||
336 | 222 | requested_%(name)s_plugin="yes" | ||
337 | 223 | ],[ | ||
338 | 224 | requested_%(name)s_plugin="no" | ||
339 | 225 | ]) | ||
340 | 226 | ],[ | ||
341 | 227 | with_%(name)s_plugin="%(enabled)s" | ||
342 | 228 | requested_%(name)s_plugin="no" | ||
343 | 229 | ]) | ||
344 | 230 | AC_ARG_ENABLE([%(name_with_dashes)s-plugin],[ | ||
345 | 231 | dnl indented wierd to make the help output correct | ||
346 | 232 | AS_HELP_STRING([--enable-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=%(default_yesno)s@:>@]) | ||
347 | 233 | AS_HELP_STRING([--disable-%(name_with_dashes)s-plugin],[Disable building %(title)s]) | ||
348 | 234 | ], | ||
349 | 235 | [enable_%(name)s_plugin="$enableval"], | ||
350 | 236 | [enable_%(name)s_plugin=%(default_yesno)s]) | ||
351 | 237 | |||
352 | 238 | """ % plugin) | ||
353 | 239 | if os.path.exists(plugin_ac_file): | ||
354 | 240 | plugin_ac.write('m4_sinclude([%s])\n' % plugin_ac_file) | ||
355 | 241 | # The plugin author has specified some check to make to determine | ||
356 | 242 | # if the plugin can be built. If the plugin is turned on and this | ||
357 | 243 | # check fails, then configure should error out. If the plugin is not | ||
358 | 244 | # turned on, then the normal conditional build stuff should just let | ||
359 | 245 | # it silently not build | ||
360 | 246 | if plugin['has_build_conditional']: | ||
361 | 247 | plugin_ac.write(""" | ||
362 | 248 | AS_IF([test %(build_conditional)s], | ||
363 | 249 | [], dnl build_conditional can only negate | ||
364 | 250 | [ | ||
365 | 251 | AS_IF([test "x${requested_%(name)s_plugin}" = "xyes"], | ||
366 | 252 | [AC_MSG_ERROR([Plugin %(name)s was explicitly requested, yet failed build dependency checks. Aborting!])]) | ||
367 | 253 | with_%(name)s_plugin=no | ||
368 | 254 | ]) | ||
369 | 255 | |||
370 | 256 | """ % plugin) | ||
371 | 257 | if not plugin['unconditional']: | ||
372 | 258 | plugin_ac.write(""" | ||
373 | 259 | AM_CONDITIONAL([%(build_conditional_tag)s], | ||
374 | 260 | [test %(build_conditional)s]) | ||
375 | 261 | """ % plugin) | ||
376 | 262 | |||
377 | 263 | plugin_ac.write(""" | ||
378 | 264 | AS_IF([test "x$with_%(name)s_plugin" = "xyes"], | ||
379 | 265 | [ | ||
380 | 266 | """ % plugin) | ||
381 | 267 | if plugin['testsuite']: | ||
382 | 268 | plugin_ac.write(""" | ||
383 | 269 | pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}" | ||
384 | 270 | """ % plugin) | ||
385 | 271 | if plugin['static']: | ||
386 | 272 | plugin_ac.write(""" | ||
387 | 273 | AS_IF([test "x$enable_%(name)s_plugin" = "xyes"],[ | ||
388 | 274 | pandora_builtin_list="%(module_name)s,${pandora_builtin_list}" | ||
389 | 275 | pandora_builtin_symbols_list="_drizzled_%(module_name)s_plugin_,${pandora_builtin_symbols_list}" | ||
390 | 276 | pandora_plugin_libs="${pandora_plugin_libs} \${top_builddir}/%(root_plugin_dir)s/%(libname)s.la" | ||
391 | 277 | PANDORA_PLUGIN_DEP_LIBS="${PANDORA_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s" | ||
392 | 278 | ]) | ||
393 | 279 | """ % plugin) | ||
394 | 280 | |||
395 | 281 | else: | ||
396 | 282 | plugin_ac.write(""" | ||
397 | 283 | AS_IF([test "x$enable_%(name)s_plugin" = "xyes"],[ | ||
398 | 284 | pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}" | ||
399 | 285 | ]) | ||
400 | 286 | """ % plugin) | ||
401 | 287 | plugin_ac.write(" ])\n") | ||
402 | 288 | |||
403 | 289 | def fix_file_paths(plugin, files): | ||
404 | 290 | # TODO: determine path to plugin dir relative to top_srcdir... append it to | ||
405 | 291 | # source files if they don't already have it | ||
406 | 292 | new_files="" | ||
407 | 293 | if plugin['plugin_dir'] != ".": | ||
408 | 294 | for file in files.split(): | ||
409 | 295 | if not file.startswith(plugin['rel_path']): | ||
410 | 296 | file= os.path.join(plugin['rel_path'], file) | ||
411 | 297 | new_files= "%s %s" % (new_files, file) | ||
412 | 298 | else: | ||
413 | 299 | new_files= " ".join(plugin['sources'].split()) | ||
414 | 300 | if new_files != "": | ||
415 | 301 | return new_files | ||
416 | 302 | return files | ||
417 | 303 | |||
418 | 304 | def expand_plugin_ini(plugin): | ||
419 | 305 | if plugin['name'] == "**OUT-OF-TREE**": | ||
420 | 306 | print "Out of tree plugins require the name field to be specified in plugin.ini" | ||
421 | 307 | sys.exit(1) | ||
422 | 308 | |||
423 | 309 | if plugin['plugin_dir'] == ".": | ||
424 | 310 | plugin['rel_path']= plugin['plugin_dir'] | ||
425 | 311 | plugin['unconditional']=True | ||
426 | 312 | else: | ||
427 | 313 | plugin['rel_path']= plugin['plugin_dir'][len(config['top_srcdir'])+len(os.path.sep):] | ||
428 | 314 | plugin['unconditional']=False | ||
429 | 315 | |||
430 | 316 | plugin['sources']= fix_file_paths(plugin, plugin['sources']) | ||
431 | 317 | plugin['main_source']= plugin['sources'].split()[0] | ||
432 | 318 | plugin['headers']= fix_file_paths(plugin, plugin['headers']) | ||
433 | 319 | plugin['install_headers']= fix_file_paths(plugin, plugin['install_headers']) | ||
434 | 320 | plugin['tests']= fix_file_paths(plugin, plugin['tests']) | ||
435 | 321 | |||
436 | 322 | # Make a yes/no version for autoconf help messages | ||
437 | 323 | if plugin['load_by_default'] or plugin['static']: | ||
438 | 324 | plugin['default_yesno']="yes" | ||
439 | 325 | else: | ||
440 | 326 | plugin['default_yesno']="no" | ||
441 | 327 | |||
442 | 328 | |||
443 | 329 | plugin['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper() | ||
444 | 330 | plugin['name_with_dashes']= plugin['name'].replace('_','-') | ||
445 | 331 | if plugin.has_key('build_conditional'): | ||
446 | 332 | plugin['has_build_conditional']=True | ||
447 | 333 | plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes" -a %(build_conditional)s' % plugin | ||
448 | 334 | else: | ||
449 | 335 | plugin['has_build_conditional']=False | ||
450 | 336 | plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin | ||
451 | 337 | |||
452 | 338 | if plugin['install']: | ||
453 | 339 | plugin['library_type']= 'pkgplugin' | ||
454 | 340 | else: | ||
455 | 341 | plugin['library_type']= 'noinst' | ||
456 | 342 | |||
457 | 343 | def find_testsuite(plugin_dir): | ||
458 | 344 | for testdir in ['drizzle-tests','tests']: | ||
459 | 345 | if os.path.isdir(os.path.join(plugin_dir,testdir)): | ||
460 | 346 | return testdir | ||
461 | 347 | if os.path.isdir(os.path.join('tests','suite',os.path.basename(plugin_dir))): | ||
462 | 348 | return "" | ||
463 | 349 | return None | ||
464 | 350 | |||
465 | 351 | def read_plugin_ini(plugin_dir): | ||
466 | 352 | if plugin_dir == ".": | ||
467 | 353 | plugin_name="**OUT-OF-TREE**" | ||
468 | 354 | else: | ||
469 | 355 | short_name=os.path.basename(plugin_dir) | ||
470 | 356 | plugin_name = plugin_dir[plugin_dir.index(config['root_plugin_dir']) + len(config['root_plugin_dir']) + 1:] | ||
471 | 357 | module_name = plugin_name.replace("/", config['module_name_separator']).replace("\\", config['module_name_separator']) | ||
472 | 358 | plugin_name = plugin_name.replace("/", config['plugin_name_separator']).replace("\\", config['plugin_name_separator']) | ||
473 | 359 | |||
474 | 360 | |||
475 | 361 | plugin_file= os.path.join(plugin_dir,config['plugin_ini_fname']) | ||
476 | 362 | plugin_defaults= dict(sources="%s.cc" % short_name, | ||
477 | 363 | headers="", | ||
478 | 364 | install_headers="", | ||
479 | 365 | cflags="", | ||
480 | 366 | cppflags="", | ||
481 | 367 | cxxflags="", | ||
482 | 368 | libs="", | ||
483 | 369 | ldflags="", | ||
484 | 370 | author="", | ||
485 | 371 | title="", | ||
486 | 372 | description="", | ||
487 | 373 | license="PLUGIN_LICENSE_GPL", | ||
488 | 374 | name=plugin_name, | ||
489 | 375 | module_name=module_name, | ||
490 | 376 | load_by_default=config['default_load_by_default'], | ||
491 | 377 | disabled="False", | ||
492 | 378 | static="False", | ||
493 | 379 | dependencies="", | ||
494 | 380 | dependency_aliases="", | ||
495 | 381 | tests="", | ||
496 | 382 | install=config['default_install']) | ||
497 | 383 | parser=ConfigParser.ConfigParser(defaults= plugin_defaults) | ||
498 | 384 | parser.read(plugin_file) | ||
499 | 385 | plugin=dict(parser.items('plugin')) | ||
500 | 386 | plugin['plugin_dir'] = plugin_dir | ||
501 | 387 | if plugin_dir == '.': | ||
502 | 388 | if not plugin.has_key('url'): | ||
503 | 389 | print "External Plugins are required to specifiy a url" | ||
504 | 390 | plugin['url']= 'http://launchpad.net/%(name)s' % plugin | ||
505 | 391 | sys.exit(1) | ||
506 | 392 | if plugin_dir == '.' and not plugin.has_key('version'): | ||
507 | 393 | print "External Plugins are required to specifiy a version" | ||
508 | 394 | sys.exit(1) | ||
509 | 395 | if not plugin.has_key('version'): | ||
510 | 396 | plugin['version'] = config['default_plugin_version'] | ||
511 | 397 | |||
512 | 398 | if plugin.has_key('load_by_default'): | ||
513 | 399 | plugin['load_by_default']=parser.getboolean('plugin','load_by_default') | ||
514 | 400 | if plugin.has_key('disabled'): | ||
515 | 401 | plugin['disabled']=parser.getboolean('plugin','disabled') | ||
516 | 402 | if plugin['disabled']: | ||
517 | 403 | plugin['enabled']="no" | ||
518 | 404 | else: | ||
519 | 405 | plugin['enabled']="yes" | ||
520 | 406 | if plugin.has_key('static'): | ||
521 | 407 | plugin['static']= parser.getboolean('plugin','static') | ||
522 | 408 | if plugin.has_key('install'): | ||
523 | 409 | plugin['install']= parser.getboolean('plugin','install') | ||
524 | 410 | if plugin.has_key('testsuite'): | ||
525 | 411 | if plugin['testsuite'] == 'disable': | ||
526 | 412 | plugin['testsuite']= False | ||
527 | 413 | else: | ||
528 | 414 | plugin_testsuite= find_testsuite(plugin_dir) | ||
529 | 415 | plugin['testsuitedir']=plugin_testsuite | ||
530 | 416 | if plugin_testsuite is not None: | ||
531 | 417 | plugin['testsuite']=True | ||
532 | 418 | else: | ||
533 | 419 | plugin['testsuite']=False | ||
534 | 420 | |||
535 | 421 | plugin['cflags']+= ' ' + config['extra_cflags'] | ||
536 | 422 | plugin['cppflags']+= ' ' + config['extra_cppflags'] | ||
537 | 423 | plugin['cxxflags']+= ' ' + config['extra_cxxflags'] | ||
538 | 424 | |||
539 | 425 | plugin['libname']= "lib%s%s%s" % (config['plugin_prefix'], | ||
540 | 426 | plugin['name'], | ||
541 | 427 | config['plugin_suffix']) | ||
542 | 428 | if config['force_lowercase_libname']: | ||
543 | 429 | plugin['libname']= plugin['libname'].lower() | ||
544 | 430 | |||
545 | 431 | plugin['root_plugin_dir']= config['root_plugin_dir'] | ||
546 | 432 | plugin['plugin_prefix']= config['plugin_prefix'] | ||
547 | 433 | plugin['plugin_suffix']= config['plugin_suffix'] | ||
548 | 434 | plugin['pkgplugindir']= config['pkgplugindir'] | ||
549 | 435 | |||
550 | 436 | # Dependencies must have a module but dependency aliases are simply added | ||
551 | 437 | # to the variable passed during compile. | ||
552 | 438 | plugin['dependency_list'] = plugin['dependencies'].split() | ||
553 | 439 | dependency_aliases = plugin['dependency_aliases'].split() | ||
554 | 440 | plugin['dependencies'] = ','.join(plugin['dependency_list'] + | ||
555 | 441 | plugin['dependency_aliases'].split()) | ||
556 | 442 | dependency_libs = ["%s/lib%s%s.la" % (config['root_plugin_dir'], | ||
557 | 443 | dependency.lower().replace('::', '_'), | ||
558 | 444 | config['plugin_suffix']) | ||
559 | 445 | for dependency in plugin['dependency_list']] | ||
560 | 446 | plugin['libs'] = " ".join(plugin['libs'].split() + dependency_libs); | ||
561 | 447 | |||
562 | 448 | # Libtool is going to expand: | ||
563 | 449 | # -DPANDORA_MODULE_AUTHOR='"Padraig O'"'"'Sullivan"' | ||
564 | 450 | # to: | ||
565 | 451 | # "-DPANDORA_MODULE_AUTHOR=\"Padraig O'Sullivan\"" | ||
566 | 452 | # So we have to replace internal ''s to '"'"' | ||
567 | 453 | for key in ('author','title','description','version'): | ||
568 | 454 | plugin[key]=plugin[key].replace('"','\\"') | ||
569 | 455 | plugin[key]=plugin[key].replace("'","'\"'\"'") | ||
570 | 456 | return plugin | ||
571 | 457 | |||
572 | 458 | |||
573 | 459 | def write_plugin_am(plugin, plugin_am): | ||
574 | 460 | """Write an automake fragment for this plugin. | ||
575 | 461 | |||
576 | 462 | :param plugin: The plugin dict. | ||
577 | 463 | :param plugin_am: The file to write to. | ||
578 | 464 | """ | ||
579 | 465 | # The .plugin.ini.stamp avoids changing the datestamp on plugin.ini which can | ||
580 | 466 | # confuse VCS systems. | ||
581 | 467 | plugin_am.write(""" | ||
582 | 468 | EXTRA_DIST += %(rel_path)s/plugin.ini | ||
583 | 469 | |||
584 | 470 | # Prevent errors when a plugin dir is removed | ||
585 | 471 | %(rel_path)s/plugin.ini: | ||
586 | 472 | |||
587 | 473 | """ % plugin) | ||
588 | 474 | if plugin['headers'] != "": | ||
589 | 475 | plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin) | ||
590 | 476 | if plugin['install_headers'] != "": | ||
591 | 477 | plugin_am.write("nobase_include_HEADERS += %(install_headers)s\n" % plugin) | ||
592 | 478 | if plugin['testsuite']: | ||
593 | 479 | if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "": | ||
594 | 480 | plugin_am.write("EXTRA_DIST += %(rel_path)s/%(testsuitedir)s\n" % plugin) | ||
595 | 481 | if plugin['static']: | ||
596 | 482 | plugin_am.write(""" | ||
597 | 483 | %(root_plugin_dir)s_%(plugin_prefix)s%(name)s_dir=${top_srcdir}/%(rel_path)s | ||
598 | 484 | EXTRA_DIST += %(rel_path)s/plugin.ini | ||
599 | 485 | if %(build_conditional_tag)s | ||
600 | 486 | noinst_LTLIBRARIES+=%(root_plugin_dir)s/%(libname)s.la | ||
601 | 487 | %(root_plugin_dir)s_%(libname)s_la_LIBADD=%(libs)s | ||
602 | 488 | %(root_plugin_dir)s_%(libname)s_la_DEPENDENCIES=%(libs)s | ||
603 | 489 | %(root_plugin_dir)s_%(libname)s_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS) | ||
604 | 490 | %(root_plugin_dir)s_%(libname)s_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_MODULE_NAME=%(module_name)s -DPANDORA_MODULE_AUTHOR='"%(author)s"' -DPANDORA_MODULE_TITLE='"%(title)s"' -DPANDORA_MODULE_VERSION='"%(version)s"' -DPANDORA_MODULE_LICENSE=%(license)s -DPANDORA_MODULE_DEPENDENCIES='"%(dependencies)s"' %(cppflags)s | ||
605 | 491 | %(root_plugin_dir)s_%(libname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s | ||
606 | 492 | %(root_plugin_dir)s_%(libname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s | ||
607 | 493 | %(root_plugin_dir)s_%(libname)s_la_SOURCES=%(sources)s | ||
608 | 494 | check_PROGRAMS += %(tests)s | ||
609 | 495 | PANDORA_DYNAMIC_LDADDS+=${top_builddir}/%(root_plugin_dir)s/%(libname)s.la | ||
610 | 496 | endif | ||
611 | 497 | """ % plugin) | ||
612 | 498 | else: | ||
613 | 499 | plugin_am.write(""" | ||
614 | 500 | %(root_plugin_dir)s_%(plugin_prefix)s%(name)s_dir=${top_srcdir}/%(rel_path)s | ||
615 | 501 | EXTRA_DIST += %(rel_path)s/plugin.ini | ||
616 | 502 | if %(build_conditional_tag)s | ||
617 | 503 | %(library_type)s_LTLIBRARIES+=%(root_plugin_dir)s/%(libname)s.la | ||
618 | 504 | %(root_plugin_dir)s_%(libname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS) | ||
619 | 505 | %(root_plugin_dir)s_%(libname)s_la_LIBADD=%(libs)s | ||
620 | 506 | %(root_plugin_dir)s_%(libname)s_la_DEPENDENCIES=%(libs)s | ||
621 | 507 | %(root_plugin_dir)s_%(libname)s_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_DYNAMIC_PLUGIN -DPANDORA_MODULE_NAME=%(module_name)s -DPANDORA_MODULE_AUTHOR='"%(author)s"' -DPANDORA_MODULE_TITLE='"%(title)s"' -DPANDORA_MODULE_VERSION='"%(version)s"' -DPANDORA_MODULE_LICENSE=%(license)s -DPANDORA_MODULE_DEPENDENCIES='"%(dependencies)s"' %(cppflags)s | ||
622 | 508 | %(root_plugin_dir)s_%(libname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s | ||
623 | 509 | %(root_plugin_dir)s_%(libname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s | ||
624 | 510 | %(root_plugin_dir)s_%(libname)s_la_SOURCES=%(sources)s | ||
625 | 511 | check_PROGRAMS += %(tests)s | ||
626 | 512 | endif | ||
627 | 513 | """ % plugin) | ||
628 | 514 | plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am') | ||
629 | 515 | if os.path.exists(plugin_am_file): | ||
630 | 516 | plugin_am.write('include %s\n' % plugin_am_file) | ||
631 | 517 | |||
632 | 518 | # | ||
633 | 519 | # MAIN STARTS HERE: | ||
634 | 520 | # | ||
635 | 521 | |||
636 | 522 | # Parse the pandora-plugin config file | ||
637 | 523 | |||
638 | 524 | config_defaults= dict( | ||
639 | 525 | top_srcdir='.', | ||
640 | 526 | top_builddir='.', | ||
641 | 527 | plugin_ini_fname='plugin.ini', | ||
642 | 528 | plugin_prefix='', | ||
643 | 529 | plugin_suffix='', | ||
644 | 530 | extra_cflags='', | ||
645 | 531 | extra_cppflags='', | ||
646 | 532 | extra_cxxflags='', | ||
647 | 533 | root_plugin_dir='', | ||
648 | 534 | pkgplugindir='', | ||
649 | 535 | default_install='True', | ||
650 | 536 | default_plugin_version='', | ||
651 | 537 | default_load_by_default='False', | ||
652 | 538 | force_lowercase_libname='True', | ||
653 | 539 | plugin_name_separator='_', | ||
654 | 540 | module_name_separator='::' | ||
655 | 541 | ) | ||
656 | 542 | |||
657 | 543 | config_parser = ConfigParser.ConfigParser(defaults=config_defaults) | ||
658 | 544 | config_parser.read(pandora_plugin_file) | ||
659 | 545 | config = dict(config_parser.items('pandora-plugin')) | ||
660 | 546 | config['force_lowercase_libname']=config_parser.getboolean('pandora-plugin','force_lowercase_libname') | ||
661 | 547 | |||
662 | 548 | # I'm 3 seconds away from writing a comprehensive build solution | ||
663 | 549 | if not os.path.exists('config/pandora_vc_revinfo'): | ||
664 | 550 | if os.path.exists('.bzr'): | ||
665 | 551 | bzr_revno= subprocess.Popen(["bzr", "revno"], stdout=subprocess.PIPE).communicate()[0].strip() | ||
666 | 552 | rev_date= datetime.date.fromtimestamp(time.time()) | ||
667 | 553 | config['default_plugin_version'] = "%d.%02d.%s" % (rev_date.year, rev_date.month, bzr_revno) | ||
668 | 554 | else: | ||
669 | 555 | config['default_plugin_version']=datetime.date.fromtimestamp(time.time()).isoformat() | ||
670 | 556 | else: | ||
671 | 557 | # need to read config/pandora_vc_revno | ||
672 | 558 | pandora_vc_revno=open('config/pandora_vc_revinfo','r').read().split() | ||
673 | 559 | rev_date="" | ||
674 | 560 | bzr_revno="" | ||
675 | 561 | for revno_line in pandora_vc_revno: | ||
676 | 562 | (revno_key,revno_val)= revno_line.split("=") | ||
677 | 563 | if revno_key == 'PANDORA_VC_REVNO': | ||
678 | 564 | bzr_revno=revno_val.strip() | ||
679 | 565 | elif revno_key == 'PANDORA_RELEASE_DATE': | ||
680 | 566 | rev_date=revno_val.strip() | ||
681 | 567 | |||
682 | 568 | config['default_plugin_version'] = "%s.%s" % (rev_date, bzr_revno) | ||
683 | 569 | |||
684 | 570 | actions=[] | ||
685 | 571 | for arg in sys.argv: | ||
686 | 572 | if arg.startswith('--top_srcdir='): | ||
687 | 573 | config['top_srcdir']=arg[12:] | ||
688 | 574 | elif arg.startswith('--top_builddir='): | ||
689 | 575 | config['top_builddir']=arg[14:] | ||
690 | 576 | elif arg == "--force-all": | ||
691 | 577 | actions=['plugin-list','pandora-plugin.am','write'] | ||
692 | 578 | break | ||
693 | 579 | else: | ||
694 | 580 | actions.append(arg) | ||
695 | 581 | if len(actions) == 0: | ||
696 | 582 | actions.append('write') | ||
697 | 583 | |||
698 | 584 | plugin_list=[] | ||
699 | 585 | |||
700 | 586 | def accumulate_plugins(arg, dirname, fnames): | ||
701 | 587 | # plugin_ini_fname is a name in dirname indicating dirname is a plugin. | ||
702 | 588 | if config['plugin_ini_fname'] in fnames: | ||
703 | 589 | arg.append(dirname) | ||
704 | 590 | |||
705 | 591 | os.path.walk(os.path.join(config['top_srcdir'], | ||
706 | 592 | config['root_plugin_dir']), | ||
707 | 593 | accumulate_plugins, | ||
708 | 594 | plugin_list) | ||
709 | 595 | |||
710 | 596 | |||
711 | 597 | if not os.path.exists("config/pandora-plugin.am") or "write" in actions: | ||
712 | 598 | plugin_am_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.am')) | ||
713 | 599 | plugin_am_file.write(""" | ||
714 | 600 | # always the current list, generated every build so keep this lean. | ||
715 | 601 | # pandora-plugin.list: datestamp preserved list | ||
716 | 602 | ${srcdir}/config/pandora-plugin.list: .plugin.scan | ||
717 | 603 | .plugin.scan: | ||
718 | 604 | @cd ${top_srcdir} && python config/pandora-plugin plugin-list | ||
719 | 605 | |||
720 | 606 | # Plugins affect configure; so to prevent configure running twice in a tarball | ||
721 | 607 | # build (once up front, once with the right list of plugins, we ship the | ||
722 | 608 | # generated list of plugins and the housekeeping material for that list so it | ||
723 | 609 | # is likewise not updated. | ||
724 | 610 | EXTRA_DIST += \ | ||
725 | 611 | config/pandora-plugin.am \ | ||
726 | 612 | config/pandora-plugin.ac \ | ||
727 | 613 | config/pandora-plugin \ | ||
728 | 614 | config/pandora-plugin.ini | ||
729 | 615 | |||
730 | 616 | |||
731 | 617 | # Seed the list of plugin LDADDS which plugins may extend. | ||
732 | 618 | PANDORA_DYNAMIC_LDADDS= | ||
733 | 619 | |||
734 | 620 | # plugin.stamp: graph dominator for creating all per pandora-plugin.ac/am | ||
735 | 621 | # files. This is invoked when the code to generate such files has altered.""") | ||
736 | 622 | |||
737 | 623 | if not os.path.exists("config/pandora-plugin.ac") or "write" in actions: | ||
738 | 624 | plugin_ac_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.ac')) | ||
739 | 625 | plugin_ac_file.write("dnl Generated file, run make to rebuild\n") | ||
740 | 626 | |||
741 | 627 | |||
742 | 628 | if os.path.exists('plugin.ini'): | ||
743 | 629 | # Are we in a plugin dir which wants to have a self-sufficient build system? | ||
744 | 630 | plugin_list=['.'] | ||
745 | 631 | |||
746 | 632 | write_external_plugin() | ||
747 | 633 | else: | ||
748 | 634 | plugin_list_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.list')) | ||
749 | 635 | for p in plugin_list: | ||
750 | 636 | plugin_list_file.write(p) | ||
751 | 637 | plugin_list_file.write("\n") | ||
752 | 638 | plugin_list.sort() | ||
753 | 639 | plugin_list_file.close() | ||
754 | 640 | |||
755 | 641 | if not os.path.exists("config/pandora-plugin.am") or 'write' in actions: | ||
756 | 642 | plugin_am_file.write("\n${top_srcdir}/config/pandora-plugin.am: ${top_srcdir}/config/pandora-plugin.list ${top_srcdir}/config/pandora-plugin ") | ||
757 | 643 | for plugin_dir in plugin_list: | ||
758 | 644 | plugin_am_file.write("\\\n\t%s/plugin.ini " % plugin_dir) | ||
759 | 645 | plugin_am_file.write("\n\tcd ${top_srcdir} && python config/pandora-plugin write\n") | ||
760 | 646 | plugin_ini_list=[] | ||
761 | 647 | |||
762 | 648 | # Load all plugin.ini files first so we can do dependency tracking. | ||
763 | 649 | for plugin_dir in plugin_list: | ||
764 | 650 | plugin = read_plugin_ini(plugin_dir) | ||
765 | 651 | expand_plugin_ini(plugin) | ||
766 | 652 | plugin_ini_list.append(plugin) | ||
767 | 653 | |||
768 | 654 | # Check for duplicates | ||
769 | 655 | plugin_name_list = [plugin['libname'] for plugin in plugin_ini_list] | ||
770 | 656 | for plugin in plugin_ini_list: | ||
771 | 657 | if plugin_name_list.count(plugin['libname']) != 1: | ||
772 | 658 | print "Duplicate module name %s" % plugin['libname'] | ||
773 | 659 | exit(1) | ||
774 | 660 | |||
775 | 661 | for plugin in plugin_ini_list: | ||
776 | 662 | write_plugin(plugin, plugin_ini_list) | ||
777 | 663 | |||
778 | 664 | if plugin_am_file is not None: | ||
779 | 665 | plugin_am_file.close() | ||
780 | 666 | if plugin_ac_file is not None: | ||
781 | 667 | plugin_ac_file.close() | ||
782 | 0 | 668 | ||
783 | === added file 'config/uncrustify.cfg' | |||
784 | --- config/uncrustify.cfg 1970-01-01 00:00:00 +0000 | |||
785 | +++ config/uncrustify.cfg 2010-07-01 01:31:26 +0000 | |||
786 | @@ -0,0 +1,1112 @@ | |||
787 | 1 | # | ||
788 | 2 | # Uncrustify options (with comments) for Pandora Projects | ||
789 | 3 | # | ||
790 | 4 | |||
791 | 5 | nl_after_brace_close = TRUE | ||
792 | 6 | |||
793 | 7 | # The type of line endings | ||
794 | 8 | newlines = lf # auto/lf/crlf/cr | ||
795 | 9 | |||
796 | 10 | # The original size of tabs in the input | ||
797 | 11 | input_tab_size = 8 # number | ||
798 | 12 | |||
799 | 13 | # The size of tabs in the output (only used if align_with_tabs=true) | ||
800 | 14 | output_tab_size = 3 # number | ||
801 | 15 | |||
802 | 16 | # The ascii value of the string escape char, usually 92 (\) or 94 (^). (Pawn) | ||
803 | 17 | string_escape_char = 92 # number | ||
804 | 18 | |||
805 | 19 | # Alternate string escape char for Pawn. Only works right before the quote char. | ||
806 | 20 | string_escape_char2 = 0 # number | ||
807 | 21 | |||
808 | 22 | # | ||
809 | 23 | # Indenting | ||
810 | 24 | # | ||
811 | 25 | |||
812 | 26 | # The number of columns to indent per level. | ||
813 | 27 | # Usually 2, 3, 4, or 8. | ||
814 | 28 | indent_columns = 2 # number | ||
815 | 29 | |||
816 | 30 | # How to use tabs when indenting code | ||
817 | 31 | # 0=spaces only | ||
818 | 32 | # 1=indent with tabs, align with spaces | ||
819 | 33 | # 2=indent and align with tabs | ||
820 | 34 | indent_with_tabs = 0 # number | ||
821 | 35 | |||
822 | 36 | # Whether to indent strings broken by '\' so that they line up | ||
823 | 37 | indent_align_string = true # false/true | ||
824 | 38 | |||
825 | 39 | # The number of spaces to indent multi-line XML strings. | ||
826 | 40 | # Requires indent_align_string=True | ||
827 | 41 | indent_xml_string = 0 # number | ||
828 | 42 | |||
829 | 43 | # Spaces to indent '{' from level | ||
830 | 44 | indent_brace = 0 # number | ||
831 | 45 | |||
832 | 46 | # Whether braces are indented to the body level | ||
833 | 47 | indent_braces = false # false/true | ||
834 | 48 | |||
835 | 49 | # Disabled indenting function braces if indent_braces is true | ||
836 | 50 | indent_braces_no_func = false # false/true | ||
837 | 51 | |||
838 | 52 | # Indent based on the size of the brace parent, ie 'if' => 3 spaces, 'for' => 4 spaces, etc. | ||
839 | 53 | indent_brace_parent = false # false/true | ||
840 | 54 | |||
841 | 55 | # Whether the 'namespace' body is indented | ||
842 | 56 | indent_namespace = false # false/true | ||
843 | 57 | |||
844 | 58 | # Whether the 'extern "C"' body is indented | ||
845 | 59 | indent_extern = false # false/true | ||
846 | 60 | |||
847 | 61 | # Whether the 'class' body is indented | ||
848 | 62 | indent_class = true # false/true | ||
849 | 63 | |||
850 | 64 | # Whether to indent the stuff after a leading class colon | ||
851 | 65 | indent_class_colon = true # false/true | ||
852 | 66 | |||
853 | 67 | # False=treat 'else\nif' as 'else if' for indenting purposes | ||
854 | 68 | # True=indent the 'if' one level | ||
855 | 69 | indent_else_if = false # false/true | ||
856 | 70 | |||
857 | 71 | # True: indent continued function call parameters one indent level | ||
858 | 72 | # False: align parameters under the open paren | ||
859 | 73 | indent_func_call_param = false # false/true | ||
860 | 74 | |||
861 | 75 | # Same as indent_func_call_param, but for function defs | ||
862 | 76 | indent_func_def_param = false # false/true | ||
863 | 77 | |||
864 | 78 | # Same as indent_func_call_param, but for function protos | ||
865 | 79 | indent_func_proto_param = false # false/true | ||
866 | 80 | |||
867 | 81 | # Same as indent_func_call_param, but for class declarations | ||
868 | 82 | indent_func_class_param = false # false/true | ||
869 | 83 | |||
870 | 84 | # Same as indent_func_call_param, but for class variable constructors | ||
871 | 85 | indent_func_ctor_var_param = false # false/true | ||
872 | 86 | |||
873 | 87 | # Same as indent_func_call_param, but for templates | ||
874 | 88 | indent_template_param = false # false/true | ||
875 | 89 | |||
876 | 90 | # Double the indent for indent_func_xxx_param options | ||
877 | 91 | indent_func_param_double = false # false/true | ||
878 | 92 | |||
879 | 93 | # Indentation column for standalone 'const' function decl/proto qualifier | ||
880 | 94 | indent_func_const = 0 # number | ||
881 | 95 | |||
882 | 96 | # Indentation column for standalone 'throw' function decl/proto qualifier | ||
883 | 97 | indent_func_throw = 0 # number | ||
884 | 98 | |||
885 | 99 | # The number of spaces to indent a continued '->' or '.' | ||
886 | 100 | # Usually set to 0, 1, or indent_columns. | ||
887 | 101 | indent_member = 3 # number | ||
888 | 102 | |||
889 | 103 | # Spaces to indent single line ('//') comments on lines before code | ||
890 | 104 | indent_sing_line_comments = 0 # number | ||
891 | 105 | |||
892 | 106 | # If set, will indent trailing single line ('//') comments relative | ||
893 | 107 | # to the code instead of trying to keep the same absolute column | ||
894 | 108 | indent_relative_single_line_comments = false # false/true | ||
895 | 109 | |||
896 | 110 | # Spaces to indent 'case' from 'switch' | ||
897 | 111 | # Usually 0 or indent_columns. | ||
898 | 112 | indent_switch_case = 0 # number | ||
899 | 113 | |||
900 | 114 | # Spaces to shift the 'case' line, without affecting any other lines | ||
901 | 115 | # Usually 0. | ||
902 | 116 | indent_case_shift = 0 # number | ||
903 | 117 | |||
904 | 118 | # Spaces to indent '{' from 'case'. | ||
905 | 119 | # By default, the brace will appear under the 'c' in case. | ||
906 | 120 | # Usually set to 0 or indent_columns. | ||
907 | 121 | indent_case_brace = 0 # number | ||
908 | 122 | |||
909 | 123 | # Whether to indent comments found in first column | ||
910 | 124 | indent_col1_comment = false # false/true | ||
911 | 125 | |||
912 | 126 | # How to indent goto labels | ||
913 | 127 | # >0 : absolute column where 1 is the leftmost column | ||
914 | 128 | # <=0 : subtract from brace indent | ||
915 | 129 | indent_label = 1 # number | ||
916 | 130 | |||
917 | 131 | # Same as indent_label, but for access specifiers that are followed by a colon | ||
918 | 132 | indent_access_spec = 1 # number | ||
919 | 133 | |||
920 | 134 | # Indent the code after an access specifier by one level. | ||
921 | 135 | # If set, this option forces 'indent_access_spec=0' | ||
922 | 136 | indent_access_spec_body = false # false/true | ||
923 | 137 | |||
924 | 138 | # If an open paren is followed by a newline, indent the next line so that it lines up after the open paren (not recommended) | ||
925 | 139 | indent_paren_nl = false # false/true | ||
926 | 140 | |||
927 | 141 | # Controls the indent of a close paren after a newline. | ||
928 | 142 | # 0: Indent to body level | ||
929 | 143 | # 1: Align under the open paren | ||
930 | 144 | # 2: Indent to the brace level | ||
931 | 145 | indent_paren_close = 0 # number | ||
932 | 146 | |||
933 | 147 | # Controls the indent of a comma when inside a paren.If TRUE, aligns under the open paren | ||
934 | 148 | indent_comma_paren = false # false/true | ||
935 | 149 | |||
936 | 150 | # Controls the indent of a BOOL operator when inside a paren.If TRUE, aligns under the open paren | ||
937 | 151 | indent_bool_paren = false # false/true | ||
938 | 152 | |||
939 | 153 | # If an open square is followed by a newline, indent the next line so that it lines up after the open square (not recommended) | ||
940 | 154 | indent_square_nl = false # false/true | ||
941 | 155 | |||
942 | 156 | # Don't change the relative indent of ESQL/C 'EXEC SQL' bodies | ||
943 | 157 | indent_preserve_sql = false # false/true | ||
944 | 158 | |||
945 | 159 | # | ||
946 | 160 | # Spacing options | ||
947 | 161 | # | ||
948 | 162 | |||
949 | 163 | # Add or remove space around arithmetic operator '+', '-', '/', '*', etc | ||
950 | 164 | sp_arith = force # ignore/add/remove/force | ||
951 | 165 | |||
952 | 166 | # Add or remove space before assignment operator '=', '+=', etc | ||
953 | 167 | sp_before_assign = remove # ignore/add/remove/force | ||
954 | 168 | |||
955 | 169 | # Add or remove space after assignment operator '=', '+=', etc | ||
956 | 170 | sp_after_assign = force # ignore/add/remove/force | ||
957 | 171 | |||
958 | 172 | # Add or remove space around assignment '=' in enum | ||
959 | 173 | sp_enum_assign = ignore # ignore/add/remove/force | ||
960 | 174 | |||
961 | 175 | # Add or remove space around boolean operators '&&' and '||' | ||
962 | 176 | sp_bool = force # ignore/add/remove/force | ||
963 | 177 | |||
964 | 178 | # Add or remove space around compare operator '<', '>', '==', etc | ||
965 | 179 | sp_compare = force # ignore/add/remove/force | ||
966 | 180 | |||
967 | 181 | # Add or remove space inside '(' and ')' | ||
968 | 182 | sp_inside_paren = remove # ignore/add/remove/force | ||
969 | 183 | |||
970 | 184 | # Add or remove space between nested parens | ||
971 | 185 | sp_paren_paren = remove # ignore/add/remove/force | ||
972 | 186 | |||
973 | 187 | # Whether to balance spaces inside nested parens | ||
974 | 188 | sp_balance_nested_parens = false # false/true | ||
975 | 189 | |||
976 | 190 | # Add or remove space between ')' and '{' | ||
977 | 191 | sp_paren_brace = ignore # ignore/add/remove/force | ||
978 | 192 | |||
979 | 193 | # Add or remove space before pointer star '*' | ||
980 | 194 | sp_before_ptr_star = force # ignore/add/remove/force | ||
981 | 195 | |||
982 | 196 | # Add or remove space before pointer star '*' that isn't followed by a variable name | ||
983 | 197 | # If set to 'ignore', sp_before_ptr_star is used instead. | ||
984 | 198 | sp_before_unnamed_ptr_star = ignore # ignore/add/remove/force | ||
985 | 199 | |||
986 | 200 | # Add or remove space between pointer stars '*' | ||
987 | 201 | sp_between_ptr_star = remove # ignore/add/remove/force | ||
988 | 202 | |||
989 | 203 | # Add or remove space after pointer star '*', if followed by a word. | ||
990 | 204 | sp_after_ptr_star = remove # ignore/add/remove/force | ||
991 | 205 | |||
992 | 206 | # Add or remove space after a pointer star '*', if followed by a func proto/def. | ||
993 | 207 | sp_after_ptr_star_func = ignore # ignore/add/remove/force | ||
994 | 208 | |||
995 | 209 | # Add or remove space before a pointer star '*', if followed by a func proto/def. | ||
996 | 210 | sp_before_ptr_star_func = ignore # ignore/add/remove/force | ||
997 | 211 | |||
998 | 212 | # Add or remove space before a reference sign '&' | ||
999 | 213 | sp_before_byref = remove # ignore/add/remove/force | ||
1000 | 214 | |||
1001 | 215 | # Add or remove space before a reference sign '&' that isn't followed by a variable name | ||
1002 | 216 | # If set to 'ignore', sp_before_byref is used instead. | ||
1003 | 217 | sp_before_unnamed_byref = ignore # ignore/add/remove/force | ||
1004 | 218 | |||
1005 | 219 | # Add or remove space after reference sign '&', if followed by a word. | ||
1006 | 220 | sp_after_byref = force # ignore/add/remove/force | ||
1007 | 221 | |||
1008 | 222 | # Add or remove space after a reference sign '&', if followed by a func proto/def. | ||
1009 | 223 | sp_after_byref_func = ignore # ignore/add/remove/force | ||
1010 | 224 | |||
1011 | 225 | # Add or remove space before a reference sign '&', if followed by a func proto/def. | ||
1012 | 226 | sp_before_byref_func = ignore # ignore/add/remove/force | ||
1013 | 227 | |||
1014 | 228 | # Add or remove space between type and word | ||
1015 | 229 | sp_after_type = force # ignore/add/remove/force | ||
1016 | 230 | |||
1017 | 231 | # Add or remove space in 'template <' vs 'template<'. | ||
1018 | 232 | # If set to ignore, sp_before_angle is used. | ||
1019 | 233 | sp_template_angle = ignore # ignore/add/remove/force | ||
1020 | 234 | |||
1021 | 235 | # Add or remove space before '<>' | ||
1022 | 236 | sp_before_angle = remove # ignore/add/remove/force | ||
1023 | 237 | |||
1024 | 238 | # Add or remove space inside '<' and '>' | ||
1025 | 239 | sp_inside_angle = remove # ignore/add/remove/force | ||
1026 | 240 | |||
1027 | 241 | # Add or remove space after '<>' | ||
1028 | 242 | sp_after_angle = force # ignore/add/remove/force | ||
1029 | 243 | |||
1030 | 244 | # Add or remove space between '<>' and '(' as found in 'new List<byte>();' | ||
1031 | 245 | sp_angle_paren = ignore # ignore/add/remove/force | ||
1032 | 246 | |||
1033 | 247 | # Add or remove space between '<>' and a word as in 'List<byte> m;' | ||
1034 | 248 | sp_angle_word = ignore # ignore/add/remove/force | ||
1035 | 249 | |||
1036 | 250 | # Add or remove space before '(' of 'if', 'for', 'switch', and 'while' | ||
1037 | 251 | sp_before_sparen = force # ignore/add/remove/force | ||
1038 | 252 | |||
1039 | 253 | # Add or remove space inside if-condition '(' and ')' | ||
1040 | 254 | sp_inside_sparen = remove # ignore/add/remove/force | ||
1041 | 255 | |||
1042 | 256 | # Add or remove space after ')' of 'if', 'for', 'switch', and 'while' | ||
1043 | 257 | sp_after_sparen = force # ignore/add/remove/force | ||
1044 | 258 | |||
1045 | 259 | # Add or remove space between ')' and '{' of 'if', 'for', 'switch', and 'while' | ||
1046 | 260 | sp_sparen_brace = add # ignore/add/remove/force | ||
1047 | 261 | |||
1048 | 262 | # Add or remove space before empty statement ';' on 'if', 'for' and 'while' | ||
1049 | 263 | sp_special_semi = ignore # ignore/add/remove/force | ||
1050 | 264 | |||
1051 | 265 | # Add or remove space before ';' | ||
1052 | 266 | sp_before_semi = remove # ignore/add/remove/force | ||
1053 | 267 | |||
1054 | 268 | # Add or remove space before ';' in non-empty 'for' statements | ||
1055 | 269 | sp_before_semi_for = ignore # ignore/add/remove/force | ||
1056 | 270 | |||
1057 | 271 | # Add or remove space before a semicolon of an empty part of a for statment. | ||
1058 | 272 | sp_before_semi_for_empty = force # ignore/add/remove/force | ||
1059 | 273 | |||
1060 | 274 | # Add or remove space after the final semicolon of an empty part of a for statment: for ( ; ; <here> ). | ||
1061 | 275 | sp_after_semi_for_empty = ignore # ignore/add/remove/force | ||
1062 | 276 | |||
1063 | 277 | # Add or remove space before '[' (except '[]') | ||
1064 | 278 | sp_before_square = ignore # ignore/add/remove/force | ||
1065 | 279 | |||
1066 | 280 | # Add or remove space before '[]' | ||
1067 | 281 | sp_before_squares = ignore # ignore/add/remove/force | ||
1068 | 282 | |||
1069 | 283 | # Add or remove space inside '[' and ']' | ||
1070 | 284 | sp_inside_square = remove # ignore/add/remove/force | ||
1071 | 285 | |||
1072 | 286 | # Add or remove space after ',' | ||
1073 | 287 | sp_after_comma = force # ignore/add/remove/force | ||
1074 | 288 | |||
1075 | 289 | # Add or remove space before ',' | ||
1076 | 290 | sp_before_comma = remove # ignore/add/remove/force | ||
1077 | 291 | |||
1078 | 292 | # Add or remove space after class ':' | ||
1079 | 293 | sp_after_class_colon = ignore # ignore/add/remove/force | ||
1080 | 294 | |||
1081 | 295 | # Add or remove space before class ':' | ||
1082 | 296 | sp_before_class_colon = ignore # ignore/add/remove/force | ||
1083 | 297 | |||
1084 | 298 | # Add or remove space between 'operator' and operator sign | ||
1085 | 299 | sp_after_operator = ignore # ignore/add/remove/force | ||
1086 | 300 | |||
1087 | 301 | # Add or remove space between the operator symbol and the open paren, as in 'operator ++(' | ||
1088 | 302 | sp_after_operator_sym = ignore # ignore/add/remove/force | ||
1089 | 303 | |||
1090 | 304 | # Add or remove space after C/D cast, ie 'cast(int)a' vs 'cast(int) a' or '(int)a' vs '(int) a' | ||
1091 | 305 | sp_after_cast = remove # ignore/add/remove/force | ||
1092 | 306 | |||
1093 | 307 | # Add or remove spaces inside cast parens | ||
1094 | 308 | sp_inside_paren_cast = remove # ignore/add/remove/force | ||
1095 | 309 | |||
1096 | 310 | # Add or remove space between the type and open paren in a C++ cast, ie 'int(exp)' vs 'int (exp)' | ||
1097 | 311 | sp_cpp_cast_paren = remove # ignore/add/remove/force | ||
1098 | 312 | |||
1099 | 313 | # Add or remove space between 'sizeof' and '(' | ||
1100 | 314 | sp_sizeof_paren = remove # ignore/add/remove/force | ||
1101 | 315 | |||
1102 | 316 | # Add or remove space after the tag keyword (Pawn) | ||
1103 | 317 | sp_after_tag = ignore # ignore/add/remove/force | ||
1104 | 318 | |||
1105 | 319 | # Add or remove space inside enum '{' and '}' | ||
1106 | 320 | sp_inside_braces_enum = force # ignore/add/remove/force | ||
1107 | 321 | |||
1108 | 322 | # Add or remove space inside struct/union '{' and '}' | ||
1109 | 323 | sp_inside_braces_struct = force # ignore/add/remove/force | ||
1110 | 324 | |||
1111 | 325 | # Add or remove space inside '{' and '}' | ||
1112 | 326 | sp_inside_braces = force # ignore/add/remove/force | ||
1113 | 327 | |||
1114 | 328 | # Add or remove space inside '{}' | ||
1115 | 329 | sp_inside_braces_empty = ignore # ignore/add/remove/force | ||
1116 | 330 | |||
1117 | 331 | # Add or remove space between return type and function name | ||
1118 | 332 | # A minimum of 1 is forced except for pointer return types. | ||
1119 | 333 | sp_type_func = force # ignore/add/remove/force | ||
1120 | 334 | |||
1121 | 335 | # Add or remove space between function name and '(' on function declaration | ||
1122 | 336 | sp_func_proto_paren = remove # ignore/add/remove/force | ||
1123 | 337 | |||
1124 | 338 | # Add or remove space between function name and '(' on function definition | ||
1125 | 339 | sp_func_def_paren = remove # ignore/add/remove/force | ||
1126 | 340 | |||
1127 | 341 | # Add or remove space inside empty function '()' | ||
1128 | 342 | sp_inside_fparens = ignore # ignore/add/remove/force | ||
1129 | 343 | |||
1130 | 344 | # Add or remove space inside function '(' and ')' | ||
1131 | 345 | sp_inside_fparen = remove # ignore/add/remove/force | ||
1132 | 346 | |||
1133 | 347 | # Add or remove space between ']' and '(' when part of a function call. | ||
1134 | 348 | sp_square_fparen = ignore # ignore/add/remove/force | ||
1135 | 349 | |||
1136 | 350 | # Add or remove space between ')' and '{' of function | ||
1137 | 351 | sp_fparen_brace = add # ignore/add/remove/force | ||
1138 | 352 | |||
1139 | 353 | # Add or remove space between function name and '(' on function calls | ||
1140 | 354 | sp_func_call_paren = remove # ignore/add/remove/force | ||
1141 | 355 | |||
1142 | 356 | # Add or remove space between the user function name and '(' on function calls | ||
1143 | 357 | # You need to set a keyword to be a user function, like this: 'set func_call_user _' in the config file. | ||
1144 | 358 | sp_func_call_user_paren = ignore # ignore/add/remove/force | ||
1145 | 359 | |||
1146 | 360 | # Add or remove space between a constructor/destructor and the open paren | ||
1147 | 361 | sp_func_class_paren = remove # ignore/add/remove/force | ||
1148 | 362 | |||
1149 | 363 | # Add or remove space between 'return' and '(' | ||
1150 | 364 | sp_return_paren = remove # ignore/add/remove/force | ||
1151 | 365 | |||
1152 | 366 | # Add or remove space between '__attribute__' and '(' | ||
1153 | 367 | sp_attribute_paren = remove # ignore/add/remove/force | ||
1154 | 368 | |||
1155 | 369 | # Add or remove space between 'defined' and '(' in '#if defined (FOO)' | ||
1156 | 370 | sp_defined_paren = remove # ignore/add/remove/force | ||
1157 | 371 | |||
1158 | 372 | # Add or remove space between 'throw' and '(' in 'throw (something)' | ||
1159 | 373 | sp_throw_paren = ignore # ignore/add/remove/force | ||
1160 | 374 | |||
1161 | 375 | # Add or remove space between macro and value | ||
1162 | 376 | sp_macro = ignore # ignore/add/remove/force | ||
1163 | 377 | |||
1164 | 378 | # Add or remove space between macro function ')' and value | ||
1165 | 379 | sp_macro_func = ignore # ignore/add/remove/force | ||
1166 | 380 | |||
1167 | 381 | # Add or remove space between 'else' and '{' if on the same line | ||
1168 | 382 | sp_else_brace = ignore # ignore/add/remove/force | ||
1169 | 383 | |||
1170 | 384 | # Add or remove space between '}' and 'else' if on the same line | ||
1171 | 385 | sp_brace_else = ignore # ignore/add/remove/force | ||
1172 | 386 | |||
1173 | 387 | # Add or remove space between '}' and the name of a typedef on the same line | ||
1174 | 388 | sp_brace_typedef = force # ignore/add/remove/force | ||
1175 | 389 | |||
1176 | 390 | # Add or remove space between 'catch' and '{' if on the same line | ||
1177 | 391 | sp_catch_brace = ignore # ignore/add/remove/force | ||
1178 | 392 | |||
1179 | 393 | # Add or remove space between '}' and 'catch' if on the same line | ||
1180 | 394 | sp_brace_catch = ignore # ignore/add/remove/force | ||
1181 | 395 | |||
1182 | 396 | # Add or remove space between 'finally' and '{' if on the same line | ||
1183 | 397 | sp_finally_brace = ignore # ignore/add/remove/force | ||
1184 | 398 | |||
1185 | 399 | # Add or remove space between '}' and 'finally' if on the same line | ||
1186 | 400 | sp_brace_finally = ignore # ignore/add/remove/force | ||
1187 | 401 | |||
1188 | 402 | # Add or remove space between 'try' and '{' if on the same line | ||
1189 | 403 | sp_try_brace = ignore # ignore/add/remove/force | ||
1190 | 404 | |||
1191 | 405 | # Add or remove space between get/set and '{' if on the same line | ||
1192 | 406 | sp_getset_brace = ignore # ignore/add/remove/force | ||
1193 | 407 | |||
1194 | 408 | # Add or remove space before the '::' operator | ||
1195 | 409 | sp_before_dc = remove # ignore/add/remove/force | ||
1196 | 410 | |||
1197 | 411 | # Add or remove space after the '::' operator | ||
1198 | 412 | sp_after_dc = remove # ignore/add/remove/force | ||
1199 | 413 | |||
1200 | 414 | # Add or remove around the D named array initializer ':' operator | ||
1201 | 415 | sp_d_array_colon = ignore # ignore/add/remove/force | ||
1202 | 416 | |||
1203 | 417 | # Add or remove space after the '!' (not) operator. | ||
1204 | 418 | sp_not = force # ignore/add/remove/force | ||
1205 | 419 | |||
1206 | 420 | # Add or remove space after the '~' (invert) operator. | ||
1207 | 421 | sp_inv = remove # ignore/add/remove/force | ||
1208 | 422 | |||
1209 | 423 | # Add or remove space after the '&' (address-of) operator. | ||
1210 | 424 | # This does not affect the spacing after a '&' that is part of a type. | ||
1211 | 425 | sp_addr = remove # ignore/add/remove/force | ||
1212 | 426 | |||
1213 | 427 | # Add or remove space around the '.' or '->' operators | ||
1214 | 428 | sp_member = remove # ignore/add/remove/force | ||
1215 | 429 | |||
1216 | 430 | # Add or remove space after the '*' (dereference) operator. | ||
1217 | 431 | # This does not affect the spacing after a '*' that is part of a type. | ||
1218 | 432 | sp_deref = remove # ignore/add/remove/force | ||
1219 | 433 | |||
1220 | 434 | # Add or remove space after '+' or '-', as in 'x = -5' or 'y = +7' | ||
1221 | 435 | sp_sign = remove # ignore/add/remove/force | ||
1222 | 436 | |||
1223 | 437 | # Add or remove space before or after '++' and '--', as in '(--x)' or 'y++;' | ||
1224 | 438 | sp_incdec = remove # ignore/add/remove/force | ||
1225 | 439 | |||
1226 | 440 | # Add or remove space before a backslash-newline at the end of a line | ||
1227 | 441 | sp_before_nl_cont = add # ignore/add/remove/force | ||
1228 | 442 | |||
1229 | 443 | # Add or remove space after the scope '+' or '-', as in '-(void) foo;' or '+(int) bar;' | ||
1230 | 444 | sp_after_oc_scope = ignore # ignore/add/remove/force | ||
1231 | 445 | |||
1232 | 446 | # Add or remove space after the colon in message specs | ||
1233 | 447 | # '-(int) f:(int) x;' vs '-(int) f: (int) x;' | ||
1234 | 448 | sp_after_oc_colon = ignore # ignore/add/remove/force | ||
1235 | 449 | |||
1236 | 450 | # Add or remove space before the colon in message specs | ||
1237 | 451 | # '-(int) f: (int) x;' vs '-(int) f : (int) x;' | ||
1238 | 452 | sp_before_oc_colon = ignore # ignore/add/remove/force | ||
1239 | 453 | |||
1240 | 454 | # Add or remove space after the colon in message specs | ||
1241 | 455 | # '[object setValue:1];' vs '[object setValue: 1];' | ||
1242 | 456 | sp_after_send_oc_colon = ignore # ignore/add/remove/force | ||
1243 | 457 | |||
1244 | 458 | # Add or remove space before the colon in message specs | ||
1245 | 459 | # '[object setValue:1];' vs '[object setValue :1];' | ||
1246 | 460 | sp_before_send_oc_colon = ignore # ignore/add/remove/force | ||
1247 | 461 | |||
1248 | 462 | # Add or remove space after the (type) in message specs | ||
1249 | 463 | # '-(int) f: (int) x;' vs '-(int) f: (int)x;' | ||
1250 | 464 | sp_after_oc_type = ignore # ignore/add/remove/force | ||
1251 | 465 | |||
1252 | 466 | # Add or remove space around the ':' in 'b ? t : f' | ||
1253 | 467 | sp_cond_colon = ignore # ignore/add/remove/force | ||
1254 | 468 | |||
1255 | 469 | # Add or remove space around the '?' in 'b ? t : f' | ||
1256 | 470 | sp_cond_question = ignore # ignore/add/remove/force | ||
1257 | 471 | |||
1258 | 472 | # Fix the spacing between 'case' and the label. Only 'ignore' and 'force' make sense here. | ||
1259 | 473 | sp_case_label = remove # ignore/add/remove/force | ||
1260 | 474 | |||
1261 | 475 | # | ||
1262 | 476 | # Code alignment (not left column spaces/tabs) | ||
1263 | 477 | # | ||
1264 | 478 | |||
1265 | 479 | # Whether to keep non-indenting tabs | ||
1266 | 480 | align_keep_tabs = false # false/true | ||
1267 | 481 | |||
1268 | 482 | # Whether to use tabs for alinging | ||
1269 | 483 | align_with_tabs = false # false/true | ||
1270 | 484 | |||
1271 | 485 | # Whether to bump out to the next tab when aligning | ||
1272 | 486 | align_on_tabstop = false # false/true | ||
1273 | 487 | |||
1274 | 488 | # Whether to left-align numbers | ||
1275 | 489 | align_number_left = false # false/true | ||
1276 | 490 | |||
1277 | 491 | # Align variable definitions in prototypes and functions | ||
1278 | 492 | align_func_params = false # false/true | ||
1279 | 493 | |||
1280 | 494 | # Align parameters in single-line functions that have the same name. | ||
1281 | 495 | # The function names must already be aligned with each other. | ||
1282 | 496 | align_same_func_call_params = false # false/true | ||
1283 | 497 | |||
1284 | 498 | # The span for aligning variable definitions (0=don't align) | ||
1285 | 499 | align_var_def_span = 1 # number | ||
1286 | 500 | |||
1287 | 501 | # How to align the star in variable definitions. | ||
1288 | 502 | # 0=Part of the type 'void * foo;' | ||
1289 | 503 | # 1=Part of the variable 'void *foo;' | ||
1290 | 504 | # 2=Dangling 'void *foo;' | ||
1291 | 505 | align_var_def_star_style = 1 # number | ||
1292 | 506 | |||
1293 | 507 | # How to align the '&' in variable definitions. | ||
1294 | 508 | # 0=Part of the type | ||
1295 | 509 | # 1=Part of the variable | ||
1296 | 510 | # 2=Dangling | ||
1297 | 511 | align_var_def_amp_style = 0 # number | ||
1298 | 512 | |||
1299 | 513 | # The threshold for aligning variable definitions (0=no limit) | ||
1300 | 514 | align_var_def_thresh = 1 # number | ||
1301 | 515 | |||
1302 | 516 | # The gap for aligning variable definitions | ||
1303 | 517 | align_var_def_gap = 0 # number | ||
1304 | 518 | |||
1305 | 519 | # Whether to align the colon in struct bit fields | ||
1306 | 520 | align_var_def_colon = false # false/true | ||
1307 | 521 | |||
1308 | 522 | # Whether to align inline struct/enum/union variable definitions | ||
1309 | 523 | align_var_def_inline = false # false/true | ||
1310 | 524 | |||
1311 | 525 | # The span for aligning on '=' in assignments (0=don't align) | ||
1312 | 526 | align_assign_span = 0 # number | ||
1313 | 527 | |||
1314 | 528 | # The threshold for aligning on '=' in assignments (0=no limit) | ||
1315 | 529 | align_assign_thresh = 12 # number | ||
1316 | 530 | |||
1317 | 531 | # The span for aligning on '=' in enums (0=don't align) | ||
1318 | 532 | align_enum_equ_span = 0 # number | ||
1319 | 533 | |||
1320 | 534 | # The threshold for aligning on '=' in enums (0=no limit) | ||
1321 | 535 | align_enum_equ_thresh = 0 # number | ||
1322 | 536 | |||
1323 | 537 | # The span for aligning struct/union (0=don't align) | ||
1324 | 538 | align_var_struct_span = 0 # number | ||
1325 | 539 | |||
1326 | 540 | # The threshold for aligning struct/union member definitions (0=no limit) | ||
1327 | 541 | align_var_struct_thresh = 0 # number | ||
1328 | 542 | |||
1329 | 543 | # The gap for aligning struct/union member definitions | ||
1330 | 544 | align_var_struct_gap = 0 # number | ||
1331 | 545 | |||
1332 | 546 | # The span for aligning struct initializer values (0=don't align) | ||
1333 | 547 | align_struct_init_span = 3 # number | ||
1334 | 548 | |||
1335 | 549 | # The minimum space between the type and the synonym of a typedef | ||
1336 | 550 | align_typedef_gap = 3 # number | ||
1337 | 551 | |||
1338 | 552 | # The span for aligning single-line typedefs (0=don't align) | ||
1339 | 553 | align_typedef_span = 5 # number | ||
1340 | 554 | |||
1341 | 555 | # How to align typedef'd functions with other typedefs | ||
1342 | 556 | # 0: Don't mix them at all | ||
1343 | 557 | # 1: align the open paren with the types | ||
1344 | 558 | # 2: align the function type name with the other type names | ||
1345 | 559 | align_typedef_func = 0 # number | ||
1346 | 560 | |||
1347 | 561 | # Controls the positioning of the '*' in typedefs. Just try it. | ||
1348 | 562 | # 0: Align on typdef type, ignore '*' | ||
1349 | 563 | # 1: The '*' is part of type name: typedef int *pint; | ||
1350 | 564 | # 2: The '*' is part of the type, but dangling: typedef int *pint; | ||
1351 | 565 | align_typedef_star_style = 0 # number | ||
1352 | 566 | |||
1353 | 567 | # Controls the positioning of the '&' in typedefs. Just try it. | ||
1354 | 568 | # 0: Align on typdef type, ignore '&' | ||
1355 | 569 | # 1: The '&' is part of type name: typedef int &pint; | ||
1356 | 570 | # 2: The '&' is part of the type, but dangling: typedef int &pint; | ||
1357 | 571 | align_typedef_amp_style = 0 # number | ||
1358 | 572 | |||
1359 | 573 | # The span for aligning comments that end lines (0=don't align) | ||
1360 | 574 | align_right_cmt_span = 3 # number | ||
1361 | 575 | |||
1362 | 576 | # If aligning comments, mix with comments after '}' and #endif with less than 3 spaces before the comment | ||
1363 | 577 | align_right_cmt_mix = false # false/true | ||
1364 | 578 | |||
1365 | 579 | # If a trailing comment is more than this number of columns away from the text it follows, | ||
1366 | 580 | # it will qualify for being aligned. | ||
1367 | 581 | align_right_cmt_gap = 0 # number | ||
1368 | 582 | |||
1369 | 583 | # The span for aligning function prototypes (0=don't align) | ||
1370 | 584 | align_func_proto_span = 0 # number | ||
1371 | 585 | |||
1372 | 586 | # Minimum gap between the return type and the function name. | ||
1373 | 587 | align_func_proto_gap = 0 # number | ||
1374 | 588 | |||
1375 | 589 | # Whether to mix aligning prototype and variable declarations. | ||
1376 | 590 | # If true, align_var_def_XXX options are used instead of align_func_proto_XXX options. | ||
1377 | 591 | align_mix_var_proto = false # false/true | ||
1378 | 592 | |||
1379 | 593 | # Align single-line functions with function prototypes, uses align_func_proto_span | ||
1380 | 594 | align_single_line_func = false # false/true | ||
1381 | 595 | |||
1382 | 596 | # Aligning the open brace of single-line functions. | ||
1383 | 597 | # Requires align_single_line_func=true, uses align_func_proto_span | ||
1384 | 598 | align_single_line_brace = false # false/true | ||
1385 | 599 | |||
1386 | 600 | # Gap for align_single_line_brace. | ||
1387 | 601 | align_single_line_brace_gap = 0 # number | ||
1388 | 602 | |||
1389 | 603 | # The span for aligning ObjC msg spec (0=don't align) | ||
1390 | 604 | align_oc_msg_spec_span = 0 # number | ||
1391 | 605 | |||
1392 | 606 | # Whether to align macros wrapped with a backslash and a newline. | ||
1393 | 607 | # This will not work right if the macro contains a multi-line comment. | ||
1394 | 608 | align_nl_cont = true # false/true | ||
1395 | 609 | |||
1396 | 610 | # The minimum space between label and value of a preprocessor define | ||
1397 | 611 | align_pp_define_gap = 4 # number | ||
1398 | 612 | |||
1399 | 613 | # The span for aligning on '#define' bodies (0=don't align) | ||
1400 | 614 | align_pp_define_span = 3 # number | ||
1401 | 615 | |||
1402 | 616 | # Align lines that start with '<<' with previous '<<'. Default=true | ||
1403 | 617 | align_left_shift = true # false/true | ||
1404 | 618 | |||
1405 | 619 | # | ||
1406 | 620 | # Newline adding and removing options | ||
1407 | 621 | # | ||
1408 | 622 | |||
1409 | 623 | # Whether to collapse empty blocks between '{' and '}' | ||
1410 | 624 | nl_collapse_empty_body = true # false/true | ||
1411 | 625 | |||
1412 | 626 | # Don't split one-line braced assignments - 'foo_t f = { 1, 2 };' | ||
1413 | 627 | nl_assign_leave_one_liners = false # false/true | ||
1414 | 628 | |||
1415 | 629 | # Don't split one-line braced statements inside a class xx { } body | ||
1416 | 630 | nl_class_leave_one_liners = false # false/true | ||
1417 | 631 | |||
1418 | 632 | # Don't split one-line enums: 'enum foo { BAR = 15 };' | ||
1419 | 633 | nl_enum_leave_one_liners = false # false/true | ||
1420 | 634 | |||
1421 | 635 | # Don't split one-line get or set functions | ||
1422 | 636 | nl_getset_leave_one_liners = false # false/true | ||
1423 | 637 | |||
1424 | 638 | # Don't split one-line function definitions - 'int foo() { return 0; }' | ||
1425 | 639 | nl_func_leave_one_liners = false # false/true | ||
1426 | 640 | |||
1427 | 641 | # Don't split one-line if/else statements - 'if(a) b++;' | ||
1428 | 642 | nl_if_leave_one_liners = false # false/true | ||
1429 | 643 | |||
1430 | 644 | # Add or remove newlines at the start of the file | ||
1431 | 645 | nl_start_of_file = remove # ignore/add/remove/force | ||
1432 | 646 | |||
1433 | 647 | # The number of newlines at the start of the file (only used if nl_start_of_file is 'add' or 'force' | ||
1434 | 648 | nl_start_of_file_min = 0 # number | ||
1435 | 649 | |||
1436 | 650 | # Add or remove newline at the end of the file | ||
1437 | 651 | nl_end_of_file = force # ignore/add/remove/force | ||
1438 | 652 | |||
1439 | 653 | # The number of newlines at the end of the file (only used if nl_end_of_file is 'add' or 'force') | ||
1440 | 654 | nl_end_of_file_min = 1 # number | ||
1441 | 655 | |||
1442 | 656 | # Add or remove newline between '=' and '{' | ||
1443 | 657 | nl_assign_brace = force # ignore/add/remove/force | ||
1444 | 658 | |||
1445 | 659 | # Add or remove newline between '=' and '[' (D only) | ||
1446 | 660 | nl_assign_square = force # ignore/add/remove/force | ||
1447 | 661 | |||
1448 | 662 | # Add or remove newline after '= [' (D only). Will also affect the newline before the ']' | ||
1449 | 663 | nl_after_square_assign = force # ignore/add/remove/force | ||
1450 | 664 | |||
1451 | 665 | # The number of newlines after a block of variable definitions | ||
1452 | 666 | nl_func_var_def_blk = 1 # number | ||
1453 | 667 | |||
1454 | 668 | # Add or remove newline between a function call's ')' and '{', as in: | ||
1455 | 669 | # list_for_each(item, &list) { } | ||
1456 | 670 | nl_fcall_brace = force # ignore/add/remove/force | ||
1457 | 671 | |||
1458 | 672 | # Add or remove newline between 'enum' and '{' | ||
1459 | 673 | nl_enum_brace = force # ignore/add/remove/force | ||
1460 | 674 | |||
1461 | 675 | # Add or remove newline between 'struct and '{' | ||
1462 | 676 | nl_struct_brace = force # ignore/add/remove/force | ||
1463 | 677 | |||
1464 | 678 | # Add or remove newline between 'union' and '{' | ||
1465 | 679 | nl_union_brace = force # ignore/add/remove/force | ||
1466 | 680 | |||
1467 | 681 | # Add or remove newline between 'if' and '{' | ||
1468 | 682 | nl_if_brace = force # ignore/add/remove/force | ||
1469 | 683 | |||
1470 | 684 | # Add or remove newline between '}' and 'else' | ||
1471 | 685 | nl_brace_else = force # ignore/add/remove/force | ||
1472 | 686 | |||
1473 | 687 | # Add or remove newline between 'else if' and '{' | ||
1474 | 688 | # If set to ignore, nl_if_brace is used instead | ||
1475 | 689 | nl_elseif_brace = force # ignore/add/remove/force | ||
1476 | 690 | |||
1477 | 691 | # Add or remove newline between 'else' and '{' | ||
1478 | 692 | nl_else_brace = force # ignore/add/remove/force | ||
1479 | 693 | |||
1480 | 694 | # Add or remove newline between 'else' and 'if' | ||
1481 | 695 | nl_else_if = remove # ignore/add/remove/force | ||
1482 | 696 | |||
1483 | 697 | # Add or remove newline between '}' and 'finally' | ||
1484 | 698 | nl_brace_finally = force # ignore/add/remove/force | ||
1485 | 699 | |||
1486 | 700 | # Add or remove newline between 'finally' and '{' | ||
1487 | 701 | nl_finally_brace = force # ignore/add/remove/force | ||
1488 | 702 | |||
1489 | 703 | # Add or remove newline between 'try' and '{' | ||
1490 | 704 | nl_try_brace = force # ignore/add/remove/force | ||
1491 | 705 | |||
1492 | 706 | # Add or remove newline between get/set and '{' | ||
1493 | 707 | nl_getset_brace = force # ignore/add/remove/force | ||
1494 | 708 | |||
1495 | 709 | # Add or remove newline between 'for' and '{' | ||
1496 | 710 | nl_for_brace = force # ignore/add/remove/force | ||
1497 | 711 | |||
1498 | 712 | # Add or remove newline between 'catch' and '{' | ||
1499 | 713 | nl_catch_brace = force # ignore/add/remove/force | ||
1500 | 714 | |||
1501 | 715 | # Add or remove newline between '}' and 'catch' | ||
1502 | 716 | nl_brace_catch = force # ignore/add/remove/force | ||
1503 | 717 | |||
1504 | 718 | # Add or remove newline between 'while' and '{' | ||
1505 | 719 | nl_while_brace = force # ignore/add/remove/force | ||
1506 | 720 | |||
1507 | 721 | # Add or remove newline between 'do' and '{' | ||
1508 | 722 | nl_do_brace = force # ignore/add/remove/force | ||
1509 | 723 | |||
1510 | 724 | # Add or remove newline between '}' and 'while' of 'do' statement | ||
1511 | 725 | nl_brace_while = force # ignore/add/remove/force | ||
1512 | 726 | |||
1513 | 727 | # Add or remove newline between 'switch' and '{' | ||
1514 | 728 | nl_switch_brace = force # ignore/add/remove/force | ||
1515 | 729 | |||
1516 | 730 | # Add or remove newline when condition spans two or more lines | ||
1517 | 731 | nl_multi_line_cond = false # false/true | ||
1518 | 732 | |||
1519 | 733 | # Force a newline in a define after the macro name for multi-line defines. | ||
1520 | 734 | nl_multi_line_define = true # false/true | ||
1521 | 735 | |||
1522 | 736 | # Whether to put a newline before 'case' statement | ||
1523 | 737 | nl_before_case = true # false/true | ||
1524 | 738 | |||
1525 | 739 | # Add or remove newline between ')' and 'throw' | ||
1526 | 740 | nl_before_throw = ignore # ignore/add/remove/force | ||
1527 | 741 | |||
1528 | 742 | # Whether to put a newline after 'case' statement | ||
1529 | 743 | nl_after_case = true # false/true | ||
1530 | 744 | |||
1531 | 745 | # Newline between namespace and { | ||
1532 | 746 | nl_namespace_brace = add # ignore/add/remove/force | ||
1533 | 747 | |||
1534 | 748 | # Add or remove newline between 'template<>' and whatever follows. | ||
1535 | 749 | nl_template_class = add # ignore/add/remove/force | ||
1536 | 750 | |||
1537 | 751 | # Add or remove newline between 'class' and '{' | ||
1538 | 752 | nl_class_brace = add # ignore/add/remove/force | ||
1539 | 753 | |||
1540 | 754 | # Add or remove newline after each ',' in the constructor member initialization | ||
1541 | 755 | nl_class_init_args = force # ignore/add/remove/force | ||
1542 | 756 | |||
1543 | 757 | # Add or remove newline between return type and function name in definition | ||
1544 | 758 | nl_func_type_name = ignore # ignore/add/remove/force | ||
1545 | 759 | |||
1546 | 760 | # Add or remove newline between return type and function name in a prototype | ||
1547 | 761 | nl_func_proto_type_name = remove # ignore/add/remove/force | ||
1548 | 762 | |||
1549 | 763 | # Add or remove newline between a function name and the opening '(' | ||
1550 | 764 | nl_func_paren = remove # ignore/add/remove/force | ||
1551 | 765 | |||
1552 | 766 | # Add or remove newline after '(' in a function declaration | ||
1553 | 767 | nl_func_decl_start = remove # ignore/add/remove/force | ||
1554 | 768 | |||
1555 | 769 | # Add or remove newline after each ',' in a function declaration | ||
1556 | 770 | nl_func_decl_args = remove # ignore/add/remove/force | ||
1557 | 771 | |||
1558 | 772 | # Add or remove newline before the ')' in a function declaration | ||
1559 | 773 | nl_func_decl_end = remove # ignore/add/remove/force | ||
1560 | 774 | |||
1561 | 775 | # Add or remove newline between function signature and '{' | ||
1562 | 776 | nl_fdef_brace = add # ignore/add/remove/force | ||
1563 | 777 | |||
1564 | 778 | # Whether to put a newline after 'return' statement | ||
1565 | 779 | nl_after_return = true # false/true | ||
1566 | 780 | |||
1567 | 781 | # Add or remove a newline between the return keyword and return expression. | ||
1568 | 782 | nl_return_expr = remove # ignore/add/remove/force | ||
1569 | 783 | |||
1570 | 784 | # Whether to put a newline after semicolons, except in 'for' statements | ||
1571 | 785 | nl_after_semicolon = true # false/true | ||
1572 | 786 | |||
1573 | 787 | # Whether to put a newline after brace open. | ||
1574 | 788 | # This also adds a newline before the matching brace close. | ||
1575 | 789 | nl_after_brace_open = true # false/true | ||
1576 | 790 | |||
1577 | 791 | # If nl_after_brace_open and nl_after_brace_open_cmt are true, a newline is | ||
1578 | 792 | # placed between the open brace and a trailing single-line comment. | ||
1579 | 793 | nl_after_brace_open_cmt = false # false/true | ||
1580 | 794 | |||
1581 | 795 | # Whether to put a newline after a virtual brace open. | ||
1582 | 796 | # These occur in un-braced if/while/do/for statement bodies. | ||
1583 | 797 | nl_after_vbrace_open = true # false/true | ||
1584 | 798 | |||
1585 | 799 | # Whether to alter newlines in '#define' macros | ||
1586 | 800 | nl_define_macro = true # false/true | ||
1587 | 801 | |||
1588 | 802 | # Whether to not put blanks after '#ifxx', '#elxx', or before '#endif' | ||
1589 | 803 | nl_squeeze_ifdef = false # false/true | ||
1590 | 804 | |||
1591 | 805 | # Add or remove newline before 'if' | ||
1592 | 806 | nl_before_if = ignore # ignore/add/remove/force | ||
1593 | 807 | |||
1594 | 808 | # Add or remove newline after 'if' | ||
1595 | 809 | nl_after_if = ignore # ignore/add/remove/force | ||
1596 | 810 | |||
1597 | 811 | # Add or remove newline before 'for' | ||
1598 | 812 | nl_before_for = ignore # ignore/add/remove/force | ||
1599 | 813 | |||
1600 | 814 | # Add or remove newline after 'for' | ||
1601 | 815 | nl_after_for = ignore # ignore/add/remove/force | ||
1602 | 816 | |||
1603 | 817 | # Add or remove newline before 'while' | ||
1604 | 818 | nl_before_while = ignore # ignore/add/remove/force | ||
1605 | 819 | |||
1606 | 820 | # Add or remove newline after 'while' | ||
1607 | 821 | nl_after_while = ignore # ignore/add/remove/force | ||
1608 | 822 | |||
1609 | 823 | # Add or remove newline before 'switch' | ||
1610 | 824 | nl_before_switch = force # ignore/add/remove/force | ||
1611 | 825 | |||
1612 | 826 | # Add or remove newline after 'switch' | ||
1613 | 827 | nl_after_switch = force # ignore/add/remove/force | ||
1614 | 828 | |||
1615 | 829 | # Add or remove newline before 'do' | ||
1616 | 830 | nl_before_do = ignore # ignore/add/remove/force | ||
1617 | 831 | |||
1618 | 832 | # Add or remove newline after 'do' | ||
1619 | 833 | nl_after_do = ignore # ignore/add/remove/force | ||
1620 | 834 | |||
1621 | 835 | # Whether to double-space commented-entries in struct/enum | ||
1622 | 836 | nl_ds_struct_enum_cmt = false # false/true | ||
1623 | 837 | |||
1624 | 838 | # Whether to double-space before the close brace of a struct/union/enum | ||
1625 | 839 | nl_ds_struct_enum_close_brace = false # false/true | ||
1626 | 840 | |||
1627 | 841 | # Add or remove a newline around a class colon. | ||
1628 | 842 | # Related to pos_class_colon, nl_class_init_args, and pos_comma. | ||
1629 | 843 | nl_class_colon = ignore # ignore/add/remove/force | ||
1630 | 844 | |||
1631 | 845 | # Change simple unbraced if statements into a one-liner | ||
1632 | 846 | # 'if(b)\n i++;' => 'if(b) i++;' | ||
1633 | 847 | nl_create_if_one_liner = false # false/true | ||
1634 | 848 | |||
1635 | 849 | # Change simple unbraced for statements into a one-liner | ||
1636 | 850 | # 'for (i=0;i<5;i++)\n foo(i);' => 'for (i=0;i<5;i++) foo(i);' | ||
1637 | 851 | nl_create_for_one_liner = false # false/true | ||
1638 | 852 | |||
1639 | 853 | # Change simple unbraced while statements into a one-liner | ||
1640 | 854 | # 'while (i<5)\n foo(i++);' => 'while (i<5) foo(i++);' | ||
1641 | 855 | nl_create_while_one_liner = false # false/true | ||
1642 | 856 | |||
1643 | 857 | # | ||
1644 | 858 | # Positioning options | ||
1645 | 859 | # | ||
1646 | 860 | |||
1647 | 861 | # The position of arithmetic operators in wrapped expressions | ||
1648 | 862 | pos_arith = lead # ignore/lead/trail | ||
1649 | 863 | |||
1650 | 864 | # The position of assignment in wrapped expressions | ||
1651 | 865 | pos_assign = trail # ignore/lead/trail | ||
1652 | 866 | |||
1653 | 867 | # The position of boolean operators in wrapped expressions | ||
1654 | 868 | pos_bool = lead # ignore/lead/trail | ||
1655 | 869 | |||
1656 | 870 | # The position of the comma in wrapped expressions | ||
1657 | 871 | pos_comma = trail # ignore/lead/trail | ||
1658 | 872 | |||
1659 | 873 | # The position of the comma in the constructor initialization list | ||
1660 | 874 | pos_class_comma = trail # ignore/lead/trail | ||
1661 | 875 | |||
1662 | 876 | # The position of colons between constructor and member initialization | ||
1663 | 877 | pos_class_colon = lead # ignore/lead/trail | ||
1664 | 878 | |||
1665 | 879 | # | ||
1666 | 880 | # Line Splitting options | ||
1667 | 881 | # | ||
1668 | 882 | |||
1669 | 883 | # Try to limit code width to N number of columns | ||
1670 | 884 | code_width = 76 # number | ||
1671 | 885 | |||
1672 | 886 | # Whether to fully split long 'for' statements at semi-colons | ||
1673 | 887 | ls_for_split_full = true # false/true | ||
1674 | 888 | |||
1675 | 889 | # Whether to fully split long function protos/calls at commas | ||
1676 | 890 | ls_func_split_full = true # false/true | ||
1677 | 891 | |||
1678 | 892 | # | ||
1679 | 893 | # Blank line options | ||
1680 | 894 | # | ||
1681 | 895 | |||
1682 | 896 | # The maximum consecutive newlines | ||
1683 | 897 | nl_max = 4 # number | ||
1684 | 898 | |||
1685 | 899 | # The number of newlines after a function prototype, if followed by another function prototype | ||
1686 | 900 | nl_after_func_proto = 0 # number | ||
1687 | 901 | |||
1688 | 902 | # The number of newlines after a function prototype, if not followed by another function prototype | ||
1689 | 903 | nl_after_func_proto_group = 3 # number | ||
1690 | 904 | |||
1691 | 905 | # The number of newlines after '}' of a multi-line function body | ||
1692 | 906 | nl_after_func_body = 3 # number | ||
1693 | 907 | |||
1694 | 908 | # The number of newlines after '}' of a single line function body | ||
1695 | 909 | nl_after_func_body_one_liner = 1 # number | ||
1696 | 910 | |||
1697 | 911 | # The minimum number of newlines before a multi-line comment. | ||
1698 | 912 | # Doesn't apply if after a brace open or another multi-line comment. | ||
1699 | 913 | nl_before_block_comment = 2 # number | ||
1700 | 914 | |||
1701 | 915 | # The minimum number of newlines before a single-line C comment. | ||
1702 | 916 | # Doesn't apply if after a brace open or other single-line C comments. | ||
1703 | 917 | nl_before_c_comment = 1 # number | ||
1704 | 918 | |||
1705 | 919 | # The minimum number of newlines before a CPP comment. | ||
1706 | 920 | # Doesn't apply if after a brace open or other CPP comments. | ||
1707 | 921 | nl_before_cpp_comment = 0 # number | ||
1708 | 922 | |||
1709 | 923 | # Whether to force a newline after a mulit-line comment. | ||
1710 | 924 | nl_after_multiline_comment = false # false/true | ||
1711 | 925 | |||
1712 | 926 | # The number of newlines before a 'private:', 'public:', 'protected:', 'signals:', or 'slots:' label. | ||
1713 | 927 | # Will not change the newline count if after a brace open. | ||
1714 | 928 | # 0 = No change. | ||
1715 | 929 | nl_before_access_spec = 1 # number | ||
1716 | 930 | |||
1717 | 931 | # The number of newlines after a 'private:', 'public:', 'protected:', 'signals:', or 'slots:' label. | ||
1718 | 932 | # 0 = No change. | ||
1719 | 933 | nl_after_access_spec = 1 # number | ||
1720 | 934 | |||
1721 | 935 | # The number of newlines between a function def and the function comment. | ||
1722 | 936 | # 0 = No change. | ||
1723 | 937 | nl_comment_func_def = 0 # number | ||
1724 | 938 | |||
1725 | 939 | # Whether to remove blank lines after '{' | ||
1726 | 940 | eat_blanks_after_open_brace = true # false/true | ||
1727 | 941 | |||
1728 | 942 | # Whether to remove blank lines before '}' | ||
1729 | 943 | eat_blanks_before_close_brace = true # false/true | ||
1730 | 944 | |||
1731 | 945 | # | ||
1732 | 946 | # Code modifying options (non-whitespace) | ||
1733 | 947 | # | ||
1734 | 948 | |||
1735 | 949 | # Add or remove braces on single-line 'do' statement | ||
1736 | 950 | mod_full_brace_do = add # ignore/add/remove/force | ||
1737 | 951 | |||
1738 | 952 | # Add or remove braces on single-line 'for' statement | ||
1739 | 953 | mod_full_brace_for = add # ignore/add/remove/force | ||
1740 | 954 | |||
1741 | 955 | # Add or remove braces on single-line function defintions. (Pawn) | ||
1742 | 956 | mod_full_brace_function = ignore # ignore/add/remove/force | ||
1743 | 957 | |||
1744 | 958 | # Add or remove braces on single-line 'if' statement. Will not remove the braces if they contain an 'else'. | ||
1745 | 959 | mod_full_brace_if = ignore # ignore/add/remove/force | ||
1746 | 960 | |||
1747 | 961 | # Don't remove braces around statements that span N newlines | ||
1748 | 962 | mod_full_brace_nl = 0 # number | ||
1749 | 963 | |||
1750 | 964 | # Add or remove braces on single-line 'while' statement | ||
1751 | 965 | mod_full_brace_while = add # ignore/add/remove/force | ||
1752 | 966 | |||
1753 | 967 | # Add or remove unnecessary paren on 'return' statement | ||
1754 | 968 | mod_paren_on_return = remove # ignore/add/remove/force | ||
1755 | 969 | |||
1756 | 970 | # Whether to change optional semicolons to real semicolons | ||
1757 | 971 | mod_pawn_semicolon = false # false/true | ||
1758 | 972 | |||
1759 | 973 | # Add parens on 'while' and 'if' statement around bools | ||
1760 | 974 | mod_full_paren_if_bool = true # false/true | ||
1761 | 975 | |||
1762 | 976 | # Whether to remove superfluous semicolons | ||
1763 | 977 | mod_remove_extra_semicolon = true # false/true | ||
1764 | 978 | |||
1765 | 979 | # If a function body exceeds the specified number of newlines and doesn't have a comment after | ||
1766 | 980 | # the close brace, a comment will be added. | ||
1767 | 981 | mod_add_long_function_closebrace_comment = 5 # number | ||
1768 | 982 | |||
1769 | 983 | # If a switch body exceeds the specified number of newlines and doesn't have a comment after | ||
1770 | 984 | # the close brace, a comment will be added. | ||
1771 | 985 | mod_add_long_switch_closebrace_comment = 5 # number | ||
1772 | 986 | |||
1773 | 987 | # If TRUE, will sort consecutive single-line 'import' statements [Java, D] | ||
1774 | 988 | mod_sort_import = false # false/true | ||
1775 | 989 | |||
1776 | 990 | # If TRUE, will sort consecutive single-line 'using' statements [C#] | ||
1777 | 991 | mod_sort_using = false # false/true | ||
1778 | 992 | |||
1779 | 993 | # If TRUE, will sort consecutive single-line '#include' statements [C/C++] and '#import' statements [Obj-C] | ||
1780 | 994 | # This is generally a bad idea, as it may break your code. | ||
1781 | 995 | mod_sort_include = false # false/true | ||
1782 | 996 | |||
1783 | 997 | # If TRUE, it will move a 'break' that appears after a fully braced 'case' before the close brace. | ||
1784 | 998 | mod_move_case_break = false # false/true | ||
1785 | 999 | |||
1786 | 1000 | # If TRUE, it will remove a void 'return;' that appears as the last statement in a function. | ||
1787 | 1001 | mod_remove_empty_return = true # false/true | ||
1788 | 1002 | |||
1789 | 1003 | # | ||
1790 | 1004 | # Comment modifications | ||
1791 | 1005 | # | ||
1792 | 1006 | |||
1793 | 1007 | # Try to wrap comments at cmt_width columns | ||
1794 | 1008 | cmt_width = 0 # number | ||
1795 | 1009 | |||
1796 | 1010 | # If false, disable all multi-line comment changes, including cmt_width and leading chars. | ||
1797 | 1011 | # Default is true. | ||
1798 | 1012 | cmt_indent_multi = true # false/true | ||
1799 | 1013 | |||
1800 | 1014 | # Whether to group c-comments that look like they are in a block | ||
1801 | 1015 | cmt_c_group = false # false/true | ||
1802 | 1016 | |||
1803 | 1017 | # Whether to put an empty '/*' on the first line of the combined c-comment | ||
1804 | 1018 | cmt_c_nl_start = false # false/true | ||
1805 | 1019 | |||
1806 | 1020 | # Whether to put a newline before the closing '*/' of the combined c-comment | ||
1807 | 1021 | cmt_c_nl_end = false # false/true | ||
1808 | 1022 | |||
1809 | 1023 | # Whether to group cpp-comments that look like they are in a block | ||
1810 | 1024 | cmt_cpp_group = false # false/true | ||
1811 | 1025 | |||
1812 | 1026 | # Whether to put an empty '/*' on the first line of the combined cpp-comment | ||
1813 | 1027 | cmt_cpp_nl_start = false # false/true | ||
1814 | 1028 | |||
1815 | 1029 | # Whether to put a newline before the closing '*/' of the combined cpp-comment | ||
1816 | 1030 | cmt_cpp_nl_end = false # false/true | ||
1817 | 1031 | |||
1818 | 1032 | # Whether to change cpp-comments into c-comments | ||
1819 | 1033 | cmt_cpp_to_c = false # false/true | ||
1820 | 1034 | |||
1821 | 1035 | # Whether to put a star on subsequent comment lines | ||
1822 | 1036 | cmt_star_cont = true # false/true | ||
1823 | 1037 | |||
1824 | 1038 | # The number of spaces to insert at the start of subsequent comment lines | ||
1825 | 1039 | cmt_sp_before_star_cont = 0 # number | ||
1826 | 1040 | |||
1827 | 1041 | # The number of spaces to insert after the star on subsequent comment lines | ||
1828 | 1042 | cmt_sp_after_star_cont = 1 # number | ||
1829 | 1043 | |||
1830 | 1044 | # For multi-line comments with a '*' lead, remove leading spaces if the first and last lines of | ||
1831 | 1045 | # the comment are the same length. Default=True | ||
1832 | 1046 | cmt_multi_check_last = true # false/true | ||
1833 | 1047 | |||
1834 | 1048 | # The filename that contains text to insert at the head of a file if the file doesn't start with a C/C++ comment. | ||
1835 | 1049 | # Will substitue $(filename) with the current file's name. | ||
1836 | 1050 | cmt_insert_file_header = "" # string | ||
1837 | 1051 | |||
1838 | 1052 | # The filename that contains text to insert before a function implementation if the function isn't preceeded with a C/C++ comment. | ||
1839 | 1053 | # Will substitue $(function) with the function name and $(javaparam) with the javadoc @param and @return stuff. | ||
1840 | 1054 | # Will also substitute $(fclass) with the class name: void CFoo::Bar() { ... } | ||
1841 | 1055 | cmt_insert_func_header = "" # string | ||
1842 | 1056 | |||
1843 | 1057 | # The filename that contains text to insert before a class if the class isn't preceeded with a C/C++ comment. | ||
1844 | 1058 | # Will substitue $(class) with the class name. | ||
1845 | 1059 | cmt_insert_class_header = "" # string | ||
1846 | 1060 | |||
1847 | 1061 | # If a preprocessor is encountered when stepping backwards from a function name, then | ||
1848 | 1062 | # this option decides whether the comment should be inserted. | ||
1849 | 1063 | # Affects cmt_insert_func_header and cmt_insert_class_header. | ||
1850 | 1064 | cmt_insert_before_preproc = false # false/true | ||
1851 | 1065 | |||
1852 | 1066 | # | ||
1853 | 1067 | # Preprocessor options | ||
1854 | 1068 | # | ||
1855 | 1069 | |||
1856 | 1070 | # Control indent of preprocessors inside #if blocks at brace level 0 | ||
1857 | 1071 | pp_indent = remove # ignore/add/remove/force | ||
1858 | 1072 | |||
1859 | 1073 | # Whether to indent #if/#else/#endif at the brace level (true) or from column 1 (false) | ||
1860 | 1074 | pp_indent_at_level = false # false/true | ||
1861 | 1075 | |||
1862 | 1076 | # If pp_indent_at_level=false, specifies the number of columns to indent per level. Default=1. | ||
1863 | 1077 | pp_indent_count = 1 # number | ||
1864 | 1078 | |||
1865 | 1079 | # Add or remove space after # based on pp_level of #if blocks | ||
1866 | 1080 | pp_space = add # ignore/add/remove/force | ||
1867 | 1081 | |||
1868 | 1082 | # Sets the number of spaces added with pp_space | ||
1869 | 1083 | pp_space_count = 1 # number | ||
1870 | 1084 | |||
1871 | 1085 | # The indent for #region and #endregion in C# and '#pragma region' in C/C++ | ||
1872 | 1086 | pp_indent_region = 0 # number | ||
1873 | 1087 | |||
1874 | 1088 | # Whether to indent the code between #region and #endregion | ||
1875 | 1089 | pp_region_indent_code = false # false/true | ||
1876 | 1090 | |||
1877 | 1091 | # If pp_indent_at_level=true, sets the indent for #if, #else, and #endif when not at file-level | ||
1878 | 1092 | pp_indent_if = 0 # number | ||
1879 | 1093 | |||
1880 | 1094 | # Control whether to indent the code between #if, #else and #endif when not at file-level | ||
1881 | 1095 | pp_if_indent_code = false # false/true | ||
1882 | 1096 | |||
1883 | 1097 | # Whether to indent '#define' at the brace level (true) or from column 1 (false) | ||
1884 | 1098 | pp_define_at_level = false # false/true | ||
1885 | 1099 | |||
1886 | 1100 | # You can force a token to be a type with the 'type' option. | ||
1887 | 1101 | # Example: | ||
1888 | 1102 | # type myfoo1 myfoo2 | ||
1889 | 1103 | # | ||
1890 | 1104 | # You can create custom macro-based indentation using macro-open, | ||
1891 | 1105 | # macro-else and macro-close. | ||
1892 | 1106 | # Example: | ||
1893 | 1107 | # macro-open BEGIN_TEMPLATE_MESSAGE_MAP | ||
1894 | 1108 | # macro-open BEGIN_MESSAGE_MAP | ||
1895 | 1109 | # macro-close END_MESSAGE_MAP | ||
1896 | 1110 | # | ||
1897 | 1111 | # You can assign any keyword to any type with the set option. | ||
1898 | 1112 | # set func_call_user _ N_ | ||
1899 | 0 | 1113 | ||
1900 | === modified file 'configure.ac' | |||
1901 | --- configure.ac 2010-06-30 18:41:07 +0000 | |||
1902 | +++ configure.ac 2010-07-01 01:31:26 +0000 | |||
1903 | @@ -6,11 +6,15 @@ | |||
1904 | 6 | # the COPYING file in this directory for full text. | 6 | # the COPYING file in this directory for full text. |
1905 | 7 | 7 | ||
1906 | 8 | AC_PREREQ(2.59) | 8 | AC_PREREQ(2.59) |
1907 | 9 | <<<<<<< TREE | ||
1908 | 9 | AC_INIT([gearmand],[0.14],[https://launchpad.net/gearmand]) | 10 | AC_INIT([gearmand],[0.14],[https://launchpad.net/gearmand]) |
1909 | 11 | ======= | ||
1910 | 12 | AC_INIT([gearmand],[1.00],[https://launchpad.net/gearmand]) | ||
1911 | 13 | >>>>>>> MERGE-SOURCE | ||
1912 | 10 | AC_CONFIG_SRCDIR(libgearman/gearman.c) | 14 | AC_CONFIG_SRCDIR(libgearman/gearman.c) |
1913 | 11 | AC_CONFIG_AUX_DIR(config) | 15 | AC_CONFIG_AUX_DIR(config) |
1914 | 12 | 16 | ||
1916 | 13 | PANDORA_CANONICAL_TARGET(require-cxx) | 17 | PANDORA_CANONICAL_TARGET(require-cxx, less-warnings) |
1917 | 14 | 18 | ||
1918 | 15 | GEARMAN_LIBRARY_VERSION=4:0:0 | 19 | GEARMAN_LIBRARY_VERSION=4:0:0 |
1919 | 16 | # | | | | 20 | # | | | |
1920 | @@ -27,6 +31,9 @@ | |||
1921 | 27 | AC_SUBST(GEARMAN_LIBRARY_VERSION) | 31 | AC_SUBST(GEARMAN_LIBRARY_VERSION) |
1922 | 28 | 32 | ||
1923 | 29 | 33 | ||
1924 | 34 | PANDORA_REQUIRE_BOOST | ||
1925 | 35 | PANDORA_REQUIRE_BOOST_PROGRAM_OPTIONS | ||
1926 | 36 | PANDORA_REQUIRE_BOOST_THREAD | ||
1927 | 30 | PANDORA_REQUIRE_PTHREAD | 37 | PANDORA_REQUIRE_PTHREAD |
1928 | 31 | PANDORA_REQUIRE_LIBEVENT | 38 | PANDORA_REQUIRE_LIBEVENT |
1929 | 32 | PANDORA_REQUIRE_LIBUUID | 39 | PANDORA_REQUIRE_LIBUUID |
1930 | 33 | 40 | ||
1931 | === renamed file 'gearmand/gearmand.c' => 'gearmand/gearmand.cc' | |||
1932 | --- gearmand/gearmand.c 2010-02-02 00:43:22 +0000 | |||
1933 | +++ gearmand/gearmand.cc 2010-07-01 01:31:26 +0000 | |||
1934 | @@ -8,6 +8,9 @@ | |||
1935 | 8 | 8 | ||
1936 | 9 | #include "config.h" | 9 | #include "config.h" |
1937 | 10 | 10 | ||
1938 | 11 | #define __STDC_LIMIT_MACROS | ||
1939 | 12 | #define __STDC_FORMAT_MACROS | ||
1940 | 13 | |||
1941 | 11 | #ifdef HAVE_ERRNO_H | 14 | #ifdef HAVE_ERRNO_H |
1942 | 12 | #include <errno.h> | 15 | #include <errno.h> |
1943 | 13 | #endif | 16 | #endif |
1944 | @@ -53,428 +56,316 @@ | |||
1945 | 53 | # endif | 56 | # endif |
1946 | 54 | #endif | 57 | #endif |
1947 | 55 | 58 | ||
1948 | 59 | #include <boost/program_options/options_description.hpp> | ||
1949 | 60 | #include <boost/program_options/parsers.hpp> | ||
1950 | 61 | #include <boost/program_options/variables_map.hpp> | ||
1951 | 62 | #include <boost/tokenizer.hpp> | ||
1952 | 63 | #include <boost/token_functions.hpp> | ||
1953 | 64 | using namespace boost; | ||
1954 | 65 | using namespace boost::program_options; | ||
1955 | 66 | |||
1956 | 56 | #include <libgearman-server/gearmand.h> | 67 | #include <libgearman-server/gearmand.h> |
1957 | 57 | 68 | ||
1979 | 58 | #ifdef HAVE_LIBDRIZZLE | 69 | |
1980 | 59 | #include <libgearman-server/queue_libdrizzle.h> | 70 | #include <iostream> |
1981 | 60 | #endif | 71 | #include <fstream> |
1982 | 61 | 72 | using namespace std; | |
1983 | 62 | #ifdef HAVE_LIBMEMCACHED | 73 | |
1984 | 63 | #include <libgearman-server/queue_libmemcached.h> | 74 | #include <string> |
1985 | 64 | #endif | 75 | |
1986 | 65 | 76 | using std::string; | |
1966 | 66 | #ifdef HAVE_LIBSQLITE3 | ||
1967 | 67 | #include <libgearman-server/queue_libsqlite3.h> | ||
1968 | 68 | #endif | ||
1969 | 69 | |||
1970 | 70 | #ifdef HAVE_LIBPQ | ||
1971 | 71 | #include <libgearman-server/queue_libpq.h> | ||
1972 | 72 | #endif | ||
1973 | 73 | |||
1974 | 74 | #ifdef HAVE_LIBTOKYOCABINET | ||
1975 | 75 | #include <libgearman-server/queue_libtokyocabinet.h> | ||
1976 | 76 | #endif | ||
1977 | 77 | |||
1978 | 78 | #include <libgearman-server/protocol_http.h> | ||
1987 | 79 | 77 | ||
1988 | 80 | #define GEARMAND_LOG_REOPEN_TIME 60 | 78 | #define GEARMAND_LOG_REOPEN_TIME 60 |
1989 | 81 | #define GEARMAND_LISTEN_BACKLOG 32 | 79 | #define GEARMAND_LISTEN_BACKLOG 32 |
1990 | 82 | 80 | ||
1992 | 83 | typedef struct | 81 | struct gearmand_log_info_st |
1993 | 84 | { | 82 | { |
1995 | 85 | const char *file; | 83 | string file; |
1996 | 86 | int fd; | 84 | int fd; |
1997 | 87 | time_t reopen; | 85 | time_t reopen; |
1999 | 88 | } gearmand_log_info_st; | 86 | |
2000 | 87 | gearmand_log_info_st() : | ||
2001 | 88 | fd(-1), | ||
2002 | 89 | reopen(0) | ||
2003 | 90 | {} | ||
2004 | 91 | |||
2005 | 92 | ~gearmand_log_info_st() {} | ||
2006 | 93 | |||
2007 | 94 | }; | ||
2008 | 89 | 95 | ||
2009 | 90 | static gearmand_st *_gearmand; | 96 | static gearmand_st *_gearmand; |
2010 | 91 | 97 | ||
2011 | 92 | static bool _set_fdlimit(rlim_t fds); | 98 | static bool _set_fdlimit(rlim_t fds); |
2012 | 93 | static bool _pid_write(const char *pid_file); | 99 | static bool _pid_write(const char *pid_file); |
2013 | 94 | static void _pid_delete(const char *pid_file); | 100 | static void _pid_delete(const char *pid_file); |
2015 | 95 | static bool _switch_user(const char *user); | 101 | static bool _switch_user(const string user); |
2016 | 96 | static bool _set_signals(void); | 102 | static bool _set_signals(void); |
2017 | 97 | static void _shutdown_handler(int signal_arg); | 103 | static void _shutdown_handler(int signal_arg); |
2019 | 98 | static void _log(const char *line, gearman_verbose_t verbose, void *context); | 104 | |
2020 | 99 | 105 | ||
2021 | 100 | int main(int argc, char *argv[]) | 106 | int main(int argc, char *argv[]) |
2022 | 101 | { | 107 | { |
2027 | 102 | gearman_conf_st conf; | 108 | options_description general("General options"); |
2028 | 103 | gearman_conf_module_st module; | 109 | |
2025 | 104 | const char *name; | ||
2026 | 105 | const char *value; | ||
2029 | 106 | int backlog= GEARMAND_LISTEN_BACKLOG; | 110 | int backlog= GEARMAND_LISTEN_BACKLOG; |
2030 | 107 | rlim_t fds= 0; | 111 | rlim_t fds= 0; |
2031 | 112 | string pid_file; | ||
2032 | 108 | uint8_t job_retries= 0; | 113 | uint8_t job_retries= 0; |
2033 | 109 | uint8_t worker_wakeup= 0; | 114 | uint8_t worker_wakeup= 0; |
2041 | 110 | in_port_t port= 0; | 115 | in_port_t port; |
2042 | 111 | const char *host= NULL; | 116 | string host; |
2043 | 112 | const char *pid_file= NULL; | 117 | string queue_type; |
2044 | 113 | const char *queue_type= NULL; | 118 | uint32_t threads; |
2045 | 114 | uint32_t threads= 0; | 119 | string user; |
2046 | 115 | const char *user= NULL; | 120 | gearman_verbose_t verbose; |
2047 | 116 | uint8_t verbose= 0; | 121 | string verbose_string; |
2048 | 117 | gearman_return_t ret; | 122 | gearman_return_t ret; |
2049 | 118 | gearmand_log_info_st log_info; | 123 | gearmand_log_info_st log_info; |
2050 | 119 | bool close_stdio= false; | 124 | bool close_stdio= false; |
2053 | 120 | int fd; | 125 | string protocol; |
2054 | 121 | bool round_robin= false; | 126 | bool round_robin; |
2055 | 122 | 127 | ||
2056 | 123 | log_info.file= NULL; | ||
2057 | 124 | log_info.fd= -1; | 128 | log_info.fd= -1; |
2058 | 125 | log_info.reopen= 0; | 129 | log_info.reopen= 0; |
2059 | 126 | 130 | ||
2113 | 127 | if (gearman_conf_create(&conf) == NULL) | 131 | general.add_options() |
2114 | 128 | { | 132 | ("backlog,b", value(&backlog)->default_value(GEARMAND_LISTEN_BACKLOG), "Number of backlog connections for listen.") |
2115 | 129 | fprintf(stderr, "gearmand: gearman_conf_create: NULL\n"); | 133 | ("daemon,d", "Daemon, detach and run in the background.") |
2116 | 130 | return 1; | 134 | ("file-descriptors,f", value(&fds), "Number of file descriptors to allow for the process (total connections will be slightly less). Default is max allowed for user.") |
2117 | 131 | } | 135 | ("help,h", "Print this help menu.") |
2118 | 132 | 136 | ("job-retries,j", value(&job_retries), "Number of attempts to run the job before the job server removes it. This is helpful to ensure a bad job does not crash all available workers. Default is no limit.") | |
2119 | 133 | if (gearman_conf_module_create(&conf, &module, NULL) == NULL) | 137 | ("listen,L", value(&host), "Address the server should listen on. Default is INADDR_ANY.") |
2120 | 134 | { | 138 | ("port,p", value(&port)->default_value(GEARMAN_DEFAULT_TCP_PORT), "Port the server should listen on.") |
2121 | 135 | fprintf(stderr, "gearmand: gearman_conf_module_create: NULL\n"); | 139 | ("pid-file,P", value(&pid_file), "File to write process ID out to.") |
2122 | 136 | return 1; | 140 | ("protocol,r", value(&protocol), "Load protocol module.") |
2123 | 137 | } | 141 | ("round-robin,R", bool_switch(&round_robin)->default_value(false), "Assign work in round-robin order per worker connection. The default is to assign work in the order of functions added by the worker.") |
2124 | 138 | 142 | ("queue-type,q", value(&queue_type), "Persistent queue type to use.") | |
2125 | 139 | /* Add all main configuration options. */ | 143 | ("threads,t", value(&threads)->default_value(0), "Number of I/O threads to use. Default=4.") |
2126 | 140 | #define MCO(__name, __short, __value, __help) \ | 144 | ("user,u", value(&user), "Switch to given user after startup.") |
2127 | 141 | gearman_conf_module_add_option(&module, __name, __short, __value, __help); | 145 | ("verbose,v", value(&verbose_string)->default_value("v"), "Increase verbosity level by one.") |
2128 | 142 | 146 | ("version,V", "Display the version of gearmand and exit.") | |
2129 | 143 | MCO("backlog", 'b', "BACKLOG", "Number of backlog connections for listen.") | 147 | ("worker-wakeup,w", value(&worker_wakeup), "Number of workers to wakeup for each job received. The default is to wakeup all available workers.") |
2130 | 144 | MCO("daemon", 'd', NULL, "Daemon, detach and run in the background.") | 148 | ; |
2131 | 145 | MCO("file-descriptors", 'f', "FDS", | 149 | options_description all("Allowed options"); |
2132 | 146 | "Number of file descriptors to allow for the process (total connections " | 150 | all.add(general); |
2133 | 147 | "will be slightly less). Default is max allowed for user.") | 151 | |
2134 | 148 | MCO("help", 'h', NULL, "Print this help menu."); | 152 | // Add in all of the options found for our logging modules |
2135 | 149 | MCO("job-retries", 'j', "RETRIES", | 153 | all.add(Log::Instance()->options()); |
2083 | 150 | "Number of attempts to run the job before the job server removes it. This" | ||
2084 | 151 | "is helpful to ensure a bad job does not crash all available workers. " | ||
2085 | 152 | "Default is no limit.") | ||
2086 | 153 | MCO("log-file", 'l', "FILE", | ||
2087 | 154 | "Log file to write errors and information to. Turning this option on " | ||
2088 | 155 | "also forces the first verbose level to be enabled.") | ||
2089 | 156 | MCO("listen", 'L', "ADDRESS", | ||
2090 | 157 | "Address the server should listen on. Default is INADDR_ANY.") | ||
2091 | 158 | MCO("port", 'p', "PORT", "Port the server should listen on.") | ||
2092 | 159 | MCO("pid-file", 'P', "FILE", "File to write process ID out to.") | ||
2093 | 160 | MCO("protocol", 'r', "PROTOCOL", "Load protocol module.") | ||
2094 | 161 | MCO("round-robin", 'R', NULL, "Assign work in round-robin order per worker" | ||
2095 | 162 | "connection. The default is to assign work in the order of functions " | ||
2096 | 163 | "added by the worker.") | ||
2097 | 164 | MCO("queue-type", 'q', "QUEUE", "Persistent queue type to use.") | ||
2098 | 165 | MCO("threads", 't', "THREADS", "Number of I/O threads to use. Default=0.") | ||
2099 | 166 | MCO("user", 'u', "USER", "Switch to given user after startup.") | ||
2100 | 167 | MCO("verbose", 'v', NULL, "Increase verbosity level by one.") | ||
2101 | 168 | MCO("version", 'V', NULL, "Display the version of gearmand and exit.") | ||
2102 | 169 | MCO("worker-wakeup", 'w', "WORKERS", | ||
2103 | 170 | "Number of workers to wakeup for each job received. The default is to " | ||
2104 | 171 | "wakeup all available workers.") | ||
2105 | 172 | |||
2106 | 173 | /* Make sure none of the gearman_conf_module_add_option calls failed. */ | ||
2107 | 174 | if (gearman_conf_return(&conf) != GEARMAN_SUCCESS) | ||
2108 | 175 | { | ||
2109 | 176 | fprintf(stderr, "gearmand: gearman_conf_module_add_option: %s\n", | ||
2110 | 177 | gearman_conf_error(&conf)); | ||
2111 | 178 | return 1; | ||
2112 | 179 | } | ||
2136 | 180 | 154 | ||
2137 | 181 | /* Add queue configuration options. */ | 155 | /* Add queue configuration options. */ |
2138 | 156 | #ifdef HAVE_LIBSQLITE3 | ||
2139 | 157 | SqliteQueue libsqlite; | ||
2140 | 158 | all.add(libsqlite.options()); | ||
2141 | 159 | #endif | ||
2142 | 182 | 160 | ||
2143 | 183 | #ifdef HAVE_LIBDRIZZLE | 161 | #ifdef HAVE_LIBDRIZZLE |
2150 | 184 | if (gearman_server_queue_libdrizzle_conf(&conf) != GEARMAN_SUCCESS) | 162 | LibDrizzleQueue libdrizzle; |
2151 | 185 | { | 163 | all.add(libdrizzle.options()); |
2152 | 186 | fprintf(stderr, "gearmand: gearman_queue_libdrizzle_conf: %s\n", | 164 | #endif |
2153 | 187 | gearman_conf_error(&conf)); | 165 | |
2154 | 188 | return 1; | 166 | #ifdef HAVE_LIBTOKYOCABINET |
2155 | 189 | } | 167 | TokyoCabinetQueue libtokyocabinet; |
2156 | 168 | all.add(libtokyocabinet.options()); | ||
2157 | 190 | #endif | 169 | #endif |
2158 | 191 | 170 | ||
2159 | 192 | #ifdef HAVE_LIBMEMCACHED | 171 | #ifdef HAVE_LIBMEMCACHED |
2183 | 193 | if (gearman_server_queue_libmemcached_conf(&conf) != GEARMAN_SUCCESS) | 172 | LibmemcachedQueue libmemcached; |
2184 | 194 | { | 173 | all.add(libmemcached.options()); |
2162 | 195 | fprintf(stderr, "gearmand: gearman_queue_libmemcached_conf: %s\n", | ||
2163 | 196 | gearman_conf_error(&conf)); | ||
2164 | 197 | return 1; | ||
2165 | 198 | } | ||
2166 | 199 | #endif | ||
2167 | 200 | #ifdef HAVE_LIBTOKYOCABINET | ||
2168 | 201 | if (gearman_server_queue_libtokyocabinet_conf(&conf) != GEARMAN_SUCCESS) | ||
2169 | 202 | { | ||
2170 | 203 | fprintf(stderr, "gearmand: gearman_queue_libtokyocabinet_conf: %s\n", | ||
2171 | 204 | gearman_conf_error(&conf)); | ||
2172 | 205 | return 1; | ||
2173 | 206 | } | ||
2174 | 207 | #endif | ||
2175 | 208 | |||
2176 | 209 | #ifdef HAVE_LIBSQLITE3 | ||
2177 | 210 | if (gearman_server_queue_libsqlite3_conf(&conf) != GEARMAN_SUCCESS) | ||
2178 | 211 | { | ||
2179 | 212 | fprintf(stderr, "gearmand: gearman_queue_libsqlite3_conf: %s\n", | ||
2180 | 213 | gearman_conf_error(&conf)); | ||
2181 | 214 | return 1; | ||
2182 | 215 | } | ||
2185 | 216 | #endif | 174 | #endif |
2186 | 217 | 175 | ||
2187 | 218 | #ifdef HAVE_LIBPQ | 176 | #ifdef HAVE_LIBPQ |
2194 | 219 | if (gearman_server_queue_libpq_conf(&conf) != GEARMAN_SUCCESS) | 177 | LibPqQueue postgres; |
2195 | 220 | { | 178 | all.add(postgres.options()); |
2190 | 221 | fprintf(stderr, "gearmand: gearman_queue_libpq_conf: %s\n", | ||
2191 | 222 | gearman_conf_error(&conf)); | ||
2192 | 223 | return 1; | ||
2193 | 224 | } | ||
2196 | 225 | #endif | 179 | #endif |
2197 | 226 | 180 | ||
2283 | 227 | if (gearmand_protocol_http_conf(&conf) != GEARMAN_SUCCESS) | 181 | GearmanHTTP http; |
2284 | 228 | { | 182 | all.add(http.options()); |
2285 | 229 | fprintf(stderr, "gearmand: gearman_protocol_http_conf: %s\n", | 183 | |
2286 | 230 | gearman_conf_error(&conf)); | 184 | variables_map vm; |
2287 | 231 | return 1; | 185 | |
2288 | 232 | } | 186 | try { |
2289 | 233 | 187 | store(parse_command_line(argc, argv, all), vm); | |
2290 | 234 | /* Let gearman conf parse the command line arguments. */ | 188 | notify(vm); |
2291 | 235 | if (gearman_conf_parse_args(&conf, argc, argv) != GEARMAN_SUCCESS) | 189 | } |
2292 | 236 | { | 190 | |
2293 | 237 | printf("\n%s\n\n", gearman_conf_error(&conf)); | 191 | catch(std::exception &e) |
2294 | 238 | printf("gearmand %s - %s\n\n", gearman_version(), gearman_bugreport()); | 192 | { |
2295 | 239 | printf("usage: %s [OPTIONS]\n", argv[0]); | 193 | cout << e.what() << "\n"; |
2296 | 240 | gearman_conf_usage(&conf); | 194 | return 1; |
2297 | 241 | return 1; | 195 | } |
2298 | 242 | } | 196 | |
2299 | 243 | 197 | if (vm.count("help")) | |
2300 | 244 | /* Check for option values that were given. */ | 198 | { |
2301 | 245 | while (gearman_conf_module_value(&module, &name, &value)) | 199 | cout << all << "\n"; |
2302 | 246 | { | 200 | return 1; |
2303 | 247 | if (!strcmp(name, "backlog")) | 201 | } |
2304 | 248 | backlog= atoi(value); | 202 | |
2305 | 249 | else if (!strcmp(name, "daemon")) | 203 | if (vm.count("version")) |
2306 | 250 | { | 204 | { |
2307 | 251 | switch (fork()) | 205 | cout << "\ngearmand " << gearman_version() << " - " << gearman_bugreport() << "\n"; |
2308 | 252 | { | 206 | return 1; |
2309 | 253 | case -1: | 207 | } |
2310 | 254 | fprintf(stderr, "gearmand: fork:%d\n", errno); | 208 | |
2311 | 255 | return 1; | 209 | verbose= static_cast<gearman_verbose_t>(verbose_string.length()); |
2312 | 256 | 210 | ||
2313 | 257 | case 0: | 211 | /* |
2314 | 258 | break; | 212 | @note Logging begins from this point on. |
2315 | 259 | 213 | */ | |
2316 | 260 | default: | 214 | Log::Instance()->start(verbose); |
2317 | 261 | return 0; | 215 | |
2318 | 262 | } | 216 | if (vm.count("daemon")) |
2319 | 263 | 217 | { | |
2320 | 264 | if (setsid() == -1) | 218 | switch (fork()) |
2321 | 265 | { | 219 | { |
2322 | 266 | fprintf(stderr, "gearmand: setsid:%d\n", errno); | 220 | case -1: |
2323 | 267 | return 1; | 221 | Log::Instance()->fatal("gearmand: fork:%d\n", errno); |
2324 | 268 | } | 222 | return 1; |
2325 | 269 | 223 | ||
2326 | 270 | close_stdio= true; | 224 | case 0: |
2327 | 271 | } | 225 | break; |
2328 | 272 | else if (!strcmp(name, "file-descriptors")) | 226 | |
2329 | 273 | fds= (rlim_t)atoi(value); | 227 | default: |
2330 | 274 | else if (!strcmp(name, "help")) | 228 | return 0; |
2331 | 275 | { | 229 | } |
2332 | 276 | printf("\ngearmand %s - %s\n\n", gearman_version(), gearman_bugreport()); | 230 | |
2333 | 277 | printf("usage: %s [OPTIONS]\n", argv[0]); | 231 | if (setsid() == -1) |
2334 | 278 | gearman_conf_usage(&conf); | 232 | { |
2335 | 279 | return 1; | 233 | Log::Instance()->fatal("gearmand: setsid:%d\n", errno); |
2336 | 280 | } | 234 | return 1; |
2337 | 281 | else if (!strcmp(name, "job-retries")) | 235 | } |
2338 | 282 | job_retries= (uint8_t)atoi(value); | 236 | |
2339 | 283 | else if (!strcmp(name, "log-file")) | 237 | close_stdio= true; |
2255 | 284 | log_info.file= value; | ||
2256 | 285 | else if (!strcmp(name, "listen")) | ||
2257 | 286 | host= value; | ||
2258 | 287 | else if (!strcmp(name, "port")) | ||
2259 | 288 | port= (in_port_t)atoi(value); | ||
2260 | 289 | else if (!strcmp(name, "pid-file")) | ||
2261 | 290 | pid_file= value; | ||
2262 | 291 | else if (!strcmp(name, "protocol")) | ||
2263 | 292 | continue; | ||
2264 | 293 | else if (!strcmp(name, "queue-type")) | ||
2265 | 294 | queue_type= value; | ||
2266 | 295 | else if (!strcmp(name, "threads")) | ||
2267 | 296 | threads= (uint32_t)atoi(value); | ||
2268 | 297 | else if (!strcmp(name, "user")) | ||
2269 | 298 | user= value; | ||
2270 | 299 | else if (!strcmp(name, "verbose")) | ||
2271 | 300 | verbose++; | ||
2272 | 301 | else if (!strcmp(name, "round-robin")) | ||
2273 | 302 | round_robin++; | ||
2274 | 303 | else if (!strcmp(name, "version")) | ||
2275 | 304 | printf("\ngearmand %s - %s\n", gearman_version(), gearman_bugreport()); | ||
2276 | 305 | else if (!strcmp(name, "worker-wakeup")) | ||
2277 | 306 | worker_wakeup= (uint8_t)atoi(value); | ||
2278 | 307 | else | ||
2279 | 308 | { | ||
2280 | 309 | fprintf(stderr, "gearmand: Unknown option:%s\n", name); | ||
2281 | 310 | return 1; | ||
2282 | 311 | } | ||
2340 | 312 | } | 238 | } |
2341 | 313 | 239 | ||
2342 | 314 | if (verbose == 0 && close_stdio) | 240 | if (verbose == 0 && close_stdio) |
2343 | 315 | { | 241 | { |
2344 | 316 | /* If we can't remap stdio, it should not a fatal error. */ | 242 | /* If we can't remap stdio, it should not a fatal error. */ |
2346 | 317 | fd = open("/dev/null", O_RDWR, 0); | 243 | int fd= open("/dev/null", O_RDWR, 0); |
2347 | 244 | |||
2348 | 318 | if (fd != -1) | 245 | if (fd != -1) |
2349 | 319 | { | 246 | { |
2350 | 320 | if (dup2(fd, STDIN_FILENO) == -1) | 247 | if (dup2(fd, STDIN_FILENO) == -1) |
2351 | 321 | { | 248 | { |
2353 | 322 | fprintf(stderr, "gearmand: dup2:%d\n", errno); | 249 | Log::Instance()->fatal("gearmand: dup2:%d\n", errno); |
2354 | 323 | return 1; | 250 | return 1; |
2355 | 324 | } | 251 | } |
2356 | 325 | 252 | ||
2357 | 326 | if (dup2(fd, STDOUT_FILENO) == -1) | 253 | if (dup2(fd, STDOUT_FILENO) == -1) |
2358 | 327 | { | 254 | { |
2360 | 328 | fprintf(stderr, "gearmand: dup2:%d\n", errno); | 255 | Log::Instance()->fatal("gearmand: dup2:%d\n", errno); |
2361 | 329 | return 1; | 256 | return 1; |
2362 | 330 | } | 257 | } |
2363 | 331 | 258 | ||
2364 | 332 | if (dup2(fd, STDERR_FILENO) == -1) | 259 | if (dup2(fd, STDERR_FILENO) == -1) |
2365 | 333 | { | 260 | { |
2367 | 334 | fprintf(stderr, "gearmand: dup2:%d\n", errno); | 261 | Log::Instance()->fatal("gearmand: dup2:%d\n", errno); |
2368 | 335 | return 1; | 262 | return 1; |
2369 | 336 | } | 263 | } |
2370 | 337 | 264 | ||
2371 | 338 | close(fd); | 265 | close(fd); |
2372 | 339 | } | 266 | } |
2373 | 340 | } | 267 | } |
2374 | 341 | |||
2375 | 342 | if ((fds > 0 && _set_fdlimit(fds)) || _switch_user(user) || _set_signals()) | 268 | if ((fds > 0 && _set_fdlimit(fds)) || _switch_user(user) || _set_signals()) |
2382 | 343 | return 1; | 269 | return -1; |
2383 | 344 | 270 | ||
2384 | 345 | if (pid_file != NULL && _pid_write(pid_file)) | 271 | if (not pid_file.empty() && _pid_write(pid_file.c_str())) |
2385 | 346 | return 1; | 272 | return -1; |
2386 | 347 | 273 | ||
2387 | 348 | _gearmand= gearmand_create(host, port); | 274 | _gearmand= new gearmand_st(host.empty() ? NULL : host.c_str(), |
2388 | 275 | port, | ||
2389 | 276 | threads); | ||
2390 | 349 | if (_gearmand == NULL) | 277 | if (_gearmand == NULL) |
2391 | 350 | { | 278 | { |
2394 | 351 | fprintf(stderr, "gearmand: Could not create gearmand library instance\n"); | 279 | Log::Instance()->fatal("gearmand: Could not create gearmand library instance\n"); |
2395 | 352 | return 1; | 280 | return -1; |
2396 | 353 | } | 281 | } |
2397 | 354 | 282 | ||
2404 | 355 | gearmand_set_backlog(_gearmand, backlog); | 283 | _gearmand->set_backlog(backlog); |
2405 | 356 | gearmand_set_threads(_gearmand, threads); | 284 | _gearmand->set_server_job_retries(job_retries); |
2406 | 357 | gearmand_set_job_retries(_gearmand, job_retries); | 285 | _gearmand->set_worker_wakeup(worker_wakeup); |
2407 | 358 | gearmand_set_worker_wakeup(_gearmand, worker_wakeup); | 286 | _gearmand->set_round_robin(round_robin); |
2402 | 359 | gearmand_set_log_fn(_gearmand, _log, &log_info, verbose); | ||
2403 | 360 | gearmand_set_round_robin(_gearmand, round_robin); | ||
2408 | 361 | 287 | ||
2410 | 362 | if (queue_type != NULL) | 288 | if (not queue_type.empty()) |
2411 | 363 | { | 289 | { |
2412 | 290 | #ifdef HAVE_LIBSQLITE3 | ||
2413 | 291 | if (not queue_type.compare("libsqlite3")) | ||
2414 | 292 | { | ||
2415 | 293 | ret= libsqlite.start(); | ||
2416 | 294 | if (ret != GEARMAN_SUCCESS) | ||
2417 | 295 | return 1; | ||
2418 | 296 | _gearmand->server.queue= &libsqlite; | ||
2419 | 297 | //_gearmand->server.queue= static_cast<GQueue *>(libsqlite); | ||
2420 | 298 | } | ||
2421 | 299 | else | ||
2422 | 300 | #endif | ||
2423 | 364 | #ifdef HAVE_LIBDRIZZLE | 301 | #ifdef HAVE_LIBDRIZZLE |
2425 | 365 | if (!strcmp(queue_type, "libdrizzle")) | 302 | if (not queue_type.compare("libdrizzle")) |
2426 | 366 | { | 303 | { |
2428 | 367 | ret= gearmand_queue_libdrizzle_init(_gearmand, &conf); | 304 | ret= libdrizzle.start(); |
2429 | 368 | if (ret != GEARMAN_SUCCESS) | 305 | if (ret != GEARMAN_SUCCESS) |
2430 | 369 | return 1; | 306 | return 1; |
2431 | 307 | _gearmand->server.queue= &libdrizzle; | ||
2432 | 370 | } | 308 | } |
2433 | 371 | else | 309 | else |
2434 | 372 | #endif | 310 | #endif |
2435 | 373 | #ifdef HAVE_LIBMEMCACHED | 311 | #ifdef HAVE_LIBMEMCACHED |
2450 | 374 | if (!strcmp(queue_type, "libmemcached")) | 312 | if (not queue_type.compare("libmemcached")) |
2451 | 375 | { | 313 | { |
2452 | 376 | ret= gearmand_queue_libmemcached_init(_gearmand, &conf); | 314 | ret= libmemcached.start(); |
2453 | 377 | if (ret != GEARMAN_SUCCESS) | 315 | if (ret != GEARMAN_SUCCESS) |
2454 | 378 | return 1; | 316 | return 1; |
2455 | 379 | } | 317 | _gearmand->server.queue= &libmemcached; |
2442 | 380 | else | ||
2443 | 381 | #endif | ||
2444 | 382 | #ifdef HAVE_LIBSQLITE3 | ||
2445 | 383 | if (!strcmp(queue_type, "libsqlite3")) | ||
2446 | 384 | { | ||
2447 | 385 | ret= gearmand_queue_libsqlite3_init(_gearmand, &conf); | ||
2448 | 386 | if (ret != GEARMAN_SUCCESS) | ||
2449 | 387 | return 1; | ||
2456 | 388 | } | 318 | } |
2457 | 389 | else | 319 | else |
2458 | 390 | #endif | 320 | #endif |
2459 | 391 | #ifdef HAVE_LIBPQ | 321 | #ifdef HAVE_LIBPQ |
2461 | 392 | if (!strcmp(queue_type, "libpq")) | 322 | if (not queue_type.compare("libpq")) |
2462 | 393 | { | 323 | { |
2464 | 394 | ret= gearmand_queue_libpq_init(_gearmand, &conf); | 324 | ret= postgres.start(); |
2465 | 395 | if (ret != GEARMAN_SUCCESS) | 325 | if (ret != GEARMAN_SUCCESS) |
2466 | 396 | return 1; | 326 | return 1; |
2467 | 327 | _gearmand->server.queue= &postgres; | ||
2468 | 397 | } | 328 | } |
2469 | 398 | else | 329 | else |
2470 | 399 | #endif | 330 | #endif |
2471 | 400 | #ifdef HAVE_LIBTOKYOCABINET | 331 | #ifdef HAVE_LIBTOKYOCABINET |
2473 | 401 | if (!strcmp(queue_type, "libtokyocabinet")) | 332 | if (not queue_type.compare("libtokyocabinet")) |
2474 | 402 | { | 333 | { |
2476 | 403 | ret= gearmand_queue_libtokyocabinet_init(_gearmand, &conf); | 334 | ret= libtokyocabinet.start(); |
2477 | 404 | if (ret != GEARMAN_SUCCESS) | 335 | if (ret != GEARMAN_SUCCESS) |
2478 | 405 | return 1; | 336 | return 1; |
2479 | 337 | _gearmand->server.queue= &libtokyocabinet; | ||
2480 | 406 | } | 338 | } |
2481 | 407 | else | 339 | else |
2482 | 408 | #endif | 340 | #endif |
2483 | 409 | { | 341 | { |
2546 | 410 | fprintf(stderr, "gearmand: Unknown queue module: %s\n", queue_type); | 342 | Log::Instance()->fatal("gearmand: Unknown queue module: %s\n", queue_type.c_str()); |
2547 | 411 | return 1; | 343 | return 1; |
2548 | 412 | } | 344 | } |
2549 | 413 | } | 345 | } |
2550 | 414 | 346 | ||
2551 | 415 | while (gearman_conf_module_value(&module, &name, &value)) | 347 | if (not protocol.compare("http")) |
2552 | 416 | { | 348 | { |
2553 | 417 | if (strcmp(name, "protocol")) | 349 | ret= http.start(_gearmand); |
2554 | 418 | continue; | 350 | if (ret != GEARMAN_SUCCESS) |
2555 | 419 | 351 | return 1; | |
2556 | 420 | if (!strcmp(value, "http")) | 352 | } |
2557 | 421 | { | 353 | else if (not protocol.empty()) |
2558 | 422 | ret= gearmand_protocol_http_init(_gearmand, &conf); | 354 | { |
2559 | 423 | if (ret != GEARMAN_SUCCESS) | 355 | Log::Instance()->fatal("gearmand: Unknown protocol module: %s\n", protocol.c_str()); |
2560 | 424 | return 1; | 356 | return 1; |
2561 | 425 | } | 357 | } |
2562 | 426 | else | 358 | |
2563 | 427 | { | 359 | ret= _gearmand->run(); |
2564 | 428 | fprintf(stderr, "gearmand: Unknown protocol module: %s\n", value); | 360 | |
2565 | 429 | return 1; | 361 | delete _gearmand; |
2566 | 430 | } | 362 | |
2567 | 431 | } | 363 | if (not pid_file.empty()) |
2568 | 432 | 364 | _pid_delete(pid_file.c_str()); | |
2507 | 433 | ret= gearmand_run(_gearmand); | ||
2508 | 434 | |||
2509 | 435 | if (queue_type != NULL) | ||
2510 | 436 | { | ||
2511 | 437 | #ifdef HAVE_LIBDRIZZLE | ||
2512 | 438 | if (!strcmp(queue_type, "libdrizzle")) | ||
2513 | 439 | gearmand_queue_libdrizzle_deinit(_gearmand); | ||
2514 | 440 | #endif | ||
2515 | 441 | #ifdef HAVE_LIBMEMCACHED | ||
2516 | 442 | if (!strcmp(queue_type, "libmemcached")) | ||
2517 | 443 | gearmand_queue_libmemcached_deinit(_gearmand); | ||
2518 | 444 | #endif | ||
2519 | 445 | #ifdef HAVE_LIBSQLITE3 | ||
2520 | 446 | if (!strcmp(queue_type, "libsqlite3")) | ||
2521 | 447 | gearmand_queue_libsqlite3_deinit(_gearmand); | ||
2522 | 448 | #endif | ||
2523 | 449 | #ifdef HAVE_LIBPQ | ||
2524 | 450 | if (!strcmp(queue_type, "libpq")) | ||
2525 | 451 | gearmand_queue_libpq_deinit(_gearmand); | ||
2526 | 452 | #endif | ||
2527 | 453 | #ifdef HAVE_LIBTOKYOCABINET | ||
2528 | 454 | if (!strcmp(queue_type, "libtokyocabinet")) | ||
2529 | 455 | gearmand_queue_libtokyocabinet_deinit(_gearmand); | ||
2530 | 456 | #endif | ||
2531 | 457 | } | ||
2532 | 458 | |||
2533 | 459 | while (gearman_conf_module_value(&module, &name, &value)) | ||
2534 | 460 | { | ||
2535 | 461 | if (strcmp(name, "protocol")) | ||
2536 | 462 | continue; | ||
2537 | 463 | |||
2538 | 464 | if (!strcmp(value, "http")) | ||
2539 | 465 | gearmand_protocol_http_deinit(_gearmand); | ||
2540 | 466 | } | ||
2541 | 467 | |||
2542 | 468 | gearmand_free(_gearmand); | ||
2543 | 469 | |||
2544 | 470 | if (pid_file != NULL) | ||
2545 | 471 | _pid_delete(pid_file); | ||
2569 | 472 | 365 | ||
2570 | 473 | if (log_info.fd != -1) | 366 | if (log_info.fd != -1) |
2571 | 474 | (void) close(log_info.fd); | 367 | (void) close(log_info.fd); |
2572 | 475 | 368 | ||
2573 | 476 | gearman_conf_free(&conf); | ||
2574 | 477 | |||
2575 | 478 | return (ret == GEARMAN_SUCCESS || ret == GEARMAN_SHUTDOWN) ? 0 : 1; | 369 | return (ret == GEARMAN_SUCCESS || ret == GEARMAN_SHUTDOWN) ? 0 : 1; |
2576 | 479 | } | 370 | } |
2577 | 480 | 371 | ||
2578 | @@ -484,8 +375,7 @@ | |||
2579 | 484 | 375 | ||
2580 | 485 | if (getrlimit(RLIMIT_NOFILE, &rl) == -1) | 376 | if (getrlimit(RLIMIT_NOFILE, &rl) == -1) |
2581 | 486 | { | 377 | { |
2584 | 487 | fprintf(stderr, "gearmand: Could not get file descriptor limit:%d\n", | 378 | Log::Instance()->fatal("gearmand: Could not get file descriptor limit:%d\n", errno); |
2583 | 488 | errno); | ||
2585 | 489 | return true; | 379 | return true; |
2586 | 490 | } | 380 | } |
2587 | 491 | 381 | ||
2588 | @@ -495,10 +385,10 @@ | |||
2589 | 495 | 385 | ||
2590 | 496 | if (setrlimit(RLIMIT_NOFILE, &rl) == -1) | 386 | if (setrlimit(RLIMIT_NOFILE, &rl) == -1) |
2591 | 497 | { | 387 | { |
2596 | 498 | fprintf(stderr, "gearmand: Failed to set limit for the number of file " | 388 | Log::Instance()->fatal("gearmand: Failed to set limit for the number of file " |
2597 | 499 | "descriptors (%d). Try running as root or giving a " | 389 | "descriptors (%d). Try running as root or giving a " |
2598 | 500 | "smaller value to -f.\n", | 390 | "smaller value to -f.\n", |
2599 | 501 | errno); | 391 | errno); |
2600 | 502 | return true; | 392 | return true; |
2601 | 503 | } | 393 | } |
2602 | 504 | 394 | ||
2603 | @@ -512,8 +402,8 @@ | |||
2604 | 512 | f= fopen(pid_file, "w"); | 402 | f= fopen(pid_file, "w"); |
2605 | 513 | if (f == NULL) | 403 | if (f == NULL) |
2606 | 514 | { | 404 | { |
2609 | 515 | fprintf(stderr, "gearmand: Could not open pid file for writing: %s (%d)\n", | 405 | Log::Instance()->fatal("gearmand: Could not open pid file for writing: %s (%d)\n", |
2610 | 516 | pid_file, errno); | 406 | pid_file, errno); |
2611 | 517 | return true; | 407 | return true; |
2612 | 518 | } | 408 | } |
2613 | 519 | 409 | ||
2614 | @@ -521,8 +411,8 @@ | |||
2615 | 521 | 411 | ||
2616 | 522 | if (fclose(f) == -1) | 412 | if (fclose(f) == -1) |
2617 | 523 | { | 413 | { |
2620 | 524 | fprintf(stderr, "gearmand: Could not close the pid file: %s (%d)\n", | 414 | Log::Instance()->fatal("gearmand: Could not close the pid file: %s (%d)\n", |
2621 | 525 | pid_file, errno); | 415 | pid_file, errno); |
2622 | 526 | return true; | 416 | return true; |
2623 | 527 | } | 417 | } |
2624 | 528 | 418 | ||
2625 | @@ -533,40 +423,39 @@ | |||
2626 | 533 | { | 423 | { |
2627 | 534 | if (unlink(pid_file) == -1) | 424 | if (unlink(pid_file) == -1) |
2628 | 535 | { | 425 | { |
2631 | 536 | fprintf(stderr, "gearmand: Could not remove the pid file: %s (%d)\n", | 426 | Log::Instance()->fatal("gearmand: Could not remove the pid file: %s (%d)\n", |
2632 | 537 | pid_file, errno); | 427 | pid_file, errno); |
2633 | 538 | } | 428 | } |
2634 | 539 | } | 429 | } |
2635 | 540 | 430 | ||
2637 | 541 | static bool _switch_user(const char *user) | 431 | static bool _switch_user(const string user) |
2638 | 542 | { | 432 | { |
2639 | 543 | struct passwd *pw; | 433 | struct passwd *pw; |
2640 | 544 | 434 | ||
2641 | 545 | if (getuid() == 0 || geteuid() == 0) | 435 | if (getuid() == 0 || geteuid() == 0) |
2642 | 546 | { | 436 | { |
2644 | 547 | if (user == NULL || user[0] == 0) | 437 | if (user.empty()) |
2645 | 548 | { | 438 | { |
2648 | 549 | fprintf(stderr, | 439 | Log::Instance()->fatal("gearmand: Must specify '-u root' if you want to run as root\n"); |
2647 | 550 | "gearmand: Must specify '-u root' if you want to run as root\n"); | ||
2649 | 551 | return true; | 440 | return true; |
2650 | 552 | } | 441 | } |
2651 | 553 | 442 | ||
2653 | 554 | pw= getpwnam(user); | 443 | pw= getpwnam(user.c_str()); |
2654 | 555 | if (pw == NULL) | 444 | if (pw == NULL) |
2655 | 556 | { | 445 | { |
2658 | 557 | fprintf(stderr, "gearmand: Could not find user '%s'\n", user); | 446 | Log::Instance()->fatal("gearmand: Could not find user '%s'\n", user.c_str()); |
2659 | 558 | return 1; | 447 | return true; |
2660 | 559 | } | 448 | } |
2661 | 560 | 449 | ||
2662 | 561 | if (setgid(pw->pw_gid) == -1 || setuid(pw->pw_uid) == -1) | 450 | if (setgid(pw->pw_gid) == -1 || setuid(pw->pw_uid) == -1) |
2663 | 562 | { | 451 | { |
2665 | 563 | fprintf(stderr, "gearmand: Could not switch to user '%s'\n", user); | 452 | Log::Instance()->fatal("gearmand: Could not switch to user '%s'\n", user.c_str()); |
2666 | 564 | return 1; | 453 | return 1; |
2667 | 565 | } | 454 | } |
2668 | 566 | } | 455 | } |
2670 | 567 | else if (user != NULL) | 456 | else if (not user.empty()) |
2671 | 568 | { | 457 | { |
2673 | 569 | fprintf(stderr, "gearmand: Must be root to switch users\n"); | 458 | Log::Instance()->fatal("gearmand: Must be root to switch users\n"); |
2674 | 570 | return true; | 459 | return true; |
2675 | 571 | } | 460 | } |
2676 | 572 | 461 | ||
2677 | @@ -583,26 +472,26 @@ | |||
2678 | 583 | if (sigemptyset(&sa.sa_mask) == -1 || | 472 | if (sigemptyset(&sa.sa_mask) == -1 || |
2679 | 584 | sigaction(SIGPIPE, &sa, 0) == -1) | 473 | sigaction(SIGPIPE, &sa, 0) == -1) |
2680 | 585 | { | 474 | { |
2682 | 586 | fprintf(stderr, "gearmand: Could not set SIGPIPE handler (%d)\n", errno); | 475 | Log::Instance()->fatal("gearmand: Could not set SIGPIPE handler (%d)\n", errno); |
2683 | 587 | return true; | 476 | return true; |
2684 | 588 | } | 477 | } |
2685 | 589 | 478 | ||
2686 | 590 | sa.sa_handler= _shutdown_handler; | 479 | sa.sa_handler= _shutdown_handler; |
2687 | 591 | if (sigaction(SIGTERM, &sa, 0) == -1) | 480 | if (sigaction(SIGTERM, &sa, 0) == -1) |
2688 | 592 | { | 481 | { |
2690 | 593 | fprintf(stderr, "gearmand: Could not set SIGTERM handler (%d)\n", errno); | 482 | Log::Instance()->fatal("gearmand: Could not set SIGTERM handler (%d)\n", errno); |
2691 | 594 | return true; | 483 | return true; |
2692 | 595 | } | 484 | } |
2693 | 596 | 485 | ||
2694 | 597 | if (sigaction(SIGINT, &sa, 0) == -1) | 486 | if (sigaction(SIGINT, &sa, 0) == -1) |
2695 | 598 | { | 487 | { |
2697 | 599 | fprintf(stderr, "gearmand: Could not set SIGINT handler (%d)\n", errno); | 488 | Log::Instance()->fatal("gearmand: Could not set SIGINT handler (%d)\n", errno); |
2698 | 600 | return true; | 489 | return true; |
2699 | 601 | } | 490 | } |
2700 | 602 | 491 | ||
2701 | 603 | if (sigaction(SIGUSR1, &sa, 0) == -1) | 492 | if (sigaction(SIGUSR1, &sa, 0) == -1) |
2702 | 604 | { | 493 | { |
2704 | 605 | fprintf(stderr, "gearmand: Could not set SIGUSR1 handler (%d)\n", errno); | 494 | Log::Instance()->fatal("gearmand: Could not set SIGUSR1 handler (%d)\n", errno); |
2705 | 606 | return true; | 495 | return true; |
2706 | 607 | } | 496 | } |
2707 | 608 | 497 | ||
2708 | @@ -612,48 +501,11 @@ | |||
2709 | 612 | static void _shutdown_handler(int signal_arg) | 501 | static void _shutdown_handler(int signal_arg) |
2710 | 613 | { | 502 | { |
2711 | 614 | if (signal_arg == SIGUSR1) | 503 | if (signal_arg == SIGUSR1) |
2756 | 615 | gearmand_wakeup(_gearmand, GEARMAND_WAKEUP_SHUTDOWN_GRACEFUL); | 504 | { |
2757 | 616 | else | 505 | _gearmand->set_wakeup(GEARMAND_WAKEUP_SHUTDOWN_GRACEFUL); |
2758 | 617 | gearmand_wakeup(_gearmand, GEARMAND_WAKEUP_SHUTDOWN); | 506 | } |
2759 | 618 | } | 507 | else |
2760 | 619 | 508 | { | |
2761 | 620 | static void _log(const char *line, gearman_verbose_t verbose, void *context) | 509 | _gearmand->set_wakeup(GEARMAND_WAKEUP_SHUTDOWN); |
2762 | 621 | { | 510 | } |
2719 | 622 | gearmand_log_info_st *log_info= (gearmand_log_info_st *)context; | ||
2720 | 623 | int fd; | ||
2721 | 624 | time_t t; | ||
2722 | 625 | char buffer[GEARMAN_MAX_ERROR_SIZE]; | ||
2723 | 626 | |||
2724 | 627 | if (log_info->file == NULL) | ||
2725 | 628 | fd= 1; | ||
2726 | 629 | else | ||
2727 | 630 | { | ||
2728 | 631 | t= time(NULL); | ||
2729 | 632 | |||
2730 | 633 | if (log_info->fd != -1 && log_info->reopen < t) | ||
2731 | 634 | { | ||
2732 | 635 | (void) close(log_info->fd); | ||
2733 | 636 | log_info->fd= -1; | ||
2734 | 637 | } | ||
2735 | 638 | |||
2736 | 639 | if (log_info->fd == -1) | ||
2737 | 640 | { | ||
2738 | 641 | log_info->fd= open(log_info->file, O_CREAT | O_WRONLY | O_APPEND, 0644); | ||
2739 | 642 | if (log_info->fd == -1) | ||
2740 | 643 | { | ||
2741 | 644 | fprintf(stderr, "gearmand: Could not open log file for writing (%d)\n", | ||
2742 | 645 | errno); | ||
2743 | 646 | return; | ||
2744 | 647 | } | ||
2745 | 648 | |||
2746 | 649 | log_info->reopen= t + GEARMAND_LOG_REOPEN_TIME; | ||
2747 | 650 | } | ||
2748 | 651 | |||
2749 | 652 | fd= log_info->fd; | ||
2750 | 653 | } | ||
2751 | 654 | |||
2752 | 655 | snprintf(buffer, GEARMAN_MAX_ERROR_SIZE, "%5s %s\n", | ||
2753 | 656 | gearman_verbose_name(verbose), line); | ||
2754 | 657 | if (write(fd, buffer, strlen(buffer)) == -1) | ||
2755 | 658 | fprintf(stderr, "gearmand: Could not write to log file: %d\n", errno); | ||
2763 | 659 | } | 511 | } |
2764 | 660 | 512 | ||
2765 | === modified file 'gearmand/include.am' | |||
2766 | --- gearmand/include.am 2009-12-18 18:19:29 +0000 | |||
2767 | +++ gearmand/include.am 2010-07-01 01:31:26 +0000 | |||
2768 | @@ -13,10 +13,11 @@ | |||
2769 | 13 | sbin_PROGRAMS+= gearmand/gearmand | 13 | sbin_PROGRAMS+= gearmand/gearmand |
2770 | 14 | 14 | ||
2771 | 15 | gearmand_gearmand_LDADD= \ | 15 | gearmand_gearmand_LDADD= \ |
2774 | 16 | libgearman-server/libgearman-server.la \ | 16 | ${BOOST_LIBS} \ |
2775 | 17 | ${BETTER_MALLOC_LIBS} | 17 | libgearman-server/libgearman-server.la \ |
2776 | 18 | ${BETTER_MALLOC_LIBS} | ||
2777 | 18 | 19 | ||
2779 | 19 | gearmand_gearmand_SOURCES= gearmand/gearmand.c | 20 | gearmand_gearmand_SOURCES= gearmand/gearmand.cc |
2780 | 20 | 21 | ||
2781 | 21 | gearmand-valgrind: gearmand/gearmand | 22 | gearmand-valgrind: gearmand/gearmand |
2782 | 22 | $(LIBTOOL) --mode=execute valgrind --leak-check=yes --show-reachable=yes gearmand/gearmand | 23 | $(LIBTOOL) --mode=execute valgrind --leak-check=yes --show-reachable=yes gearmand/gearmand |
2783 | 23 | 24 | ||
2784 | === renamed file 'libgearman-server/client.c' => 'libgearman-server/client.cc' | |||
2785 | --- libgearman-server/client.c 2010-04-06 21:41:46 +0000 | |||
2786 | +++ libgearman-server/client.cc 2010-07-01 01:31:26 +0000 | |||
2787 | @@ -1,4 +1,5 @@ | |||
2788 | 1 | /* Gearman server and library | 1 | /* Gearman server and library |
2789 | 2 | * Copyright (C) 2010 Data Differential | ||
2790 | 2 | * Copyright (C) 2008 Brian Aker, Eric Day | 3 | * Copyright (C) 2008 Brian Aker, Eric Day |
2791 | 3 | * All rights reserved. | 4 | * All rights reserved. |
2792 | 4 | * | 5 | * |
2793 | @@ -11,12 +12,13 @@ | |||
2794 | 11 | * @brief Server client definitions | 12 | * @brief Server client definitions |
2795 | 12 | */ | 13 | */ |
2796 | 13 | 14 | ||
2798 | 14 | #include "common.h" | 15 | #include "libgearman-server/common.h" |
2799 | 15 | 16 | ||
2800 | 16 | /* | 17 | /* |
2801 | 17 | * Public definitions | 18 | * Public definitions |
2802 | 18 | */ | 19 | */ |
2803 | 19 | 20 | ||
2804 | 21 | <<<<<<< TREE | ||
2805 | 20 | gearman_server_client_st * | 22 | gearman_server_client_st * |
2806 | 21 | gearman_server_client_add(gearman_server_con_st *con) | 23 | gearman_server_client_add(gearman_server_con_st *con) |
2807 | 22 | { | 24 | { |
2808 | @@ -93,4 +95,15 @@ | |||
2809 | 93 | else | 95 | else |
2810 | 94 | free(client); | 96 | free(client); |
2811 | 95 | } | 97 | } |
2812 | 98 | ======= | ||
2813 | 99 | gearman_server_client_st::gearman_server_client_st() : | ||
2814 | 100 | job(NULL), | ||
2815 | 101 | job_next(NULL), | ||
2816 | 102 | job_prev(NULL) | ||
2817 | 103 | { | ||
2818 | 104 | } | ||
2819 | 105 | |||
2820 | 106 | gearman_server_client_st::~gearman_server_client_st() | ||
2821 | 107 | { | ||
2822 | 108 | >>>>>>> MERGE-SOURCE | ||
2823 | 96 | } | 109 | } |
2824 | 97 | 110 | ||
2825 | === modified file 'libgearman-server/client.h' | |||
2826 | --- libgearman-server/client.h 2010-03-11 19:58:32 +0000 | |||
2827 | +++ libgearman-server/client.h 2010-07-01 01:31:26 +0000 | |||
2828 | @@ -1,4 +1,5 @@ | |||
2829 | 1 | /* Gearman server and library | 1 | /* Gearman server and library |
2830 | 2 | * Copyright (C) 2010 Data Differential | ||
2831 | 2 | * Copyright (C) 2008 Brian Aker, Eric Day | 3 | * Copyright (C) 2008 Brian Aker, Eric Day |
2832 | 3 | * All rights reserved. | 4 | * All rights reserved. |
2833 | 4 | * | 5 | * |
2834 | @@ -14,61 +15,20 @@ | |||
2835 | 14 | #ifndef __GEARMAN_SERVER_CLIENT_H__ | 15 | #ifndef __GEARMAN_SERVER_CLIENT_H__ |
2836 | 15 | #define __GEARMAN_SERVER_CLIENT_H__ | 16 | #define __GEARMAN_SERVER_CLIENT_H__ |
2837 | 16 | 17 | ||
2838 | 17 | #ifdef __cplusplus | ||
2839 | 18 | extern "C" { | ||
2840 | 19 | #endif | ||
2841 | 20 | |||
2842 | 21 | /** | 18 | /** |
2843 | 22 | * @ingroup gearman_server_client | 19 | * @ingroup gearman_server_client |
2844 | 23 | */ | 20 | */ |
2845 | 24 | struct gearman_server_client_st | 21 | struct gearman_server_client_st |
2846 | 25 | { | 22 | { |
2847 | 26 | struct { | ||
2848 | 27 | bool allocated; | ||
2849 | 28 | } options; | ||
2850 | 29 | gearman_server_con_st *con; | 23 | gearman_server_con_st *con; |
2851 | 30 | gearman_server_client_st *con_next; | 24 | gearman_server_client_st *con_next; |
2852 | 31 | gearman_server_client_st *con_prev; | 25 | gearman_server_client_st *con_prev; |
2853 | 32 | gearman_server_job_st *job; | 26 | gearman_server_job_st *job; |
2854 | 33 | gearman_server_client_st *job_next; | 27 | gearman_server_client_st *job_next; |
2855 | 34 | gearman_server_client_st *job_prev; | 28 | gearman_server_client_st *job_prev; |
2856 | 29 | |||
2857 | 30 | gearman_server_client_st(); | ||
2858 | 31 | ~gearman_server_client_st(); | ||
2859 | 35 | }; | 32 | }; |
2860 | 36 | 33 | ||
2861 | 37 | /** | ||
2862 | 38 | * @addtogroup gearman_server_client Client Declarations | ||
2863 | 39 | * @ingroup gearman_server | ||
2864 | 40 | * | ||
2865 | 41 | * This is a low level interface for gearman server clients. This is used | ||
2866 | 42 | * internally by the server interface, so you probably want to look there first. | ||
2867 | 43 | * | ||
2868 | 44 | * @{ | ||
2869 | 45 | */ | ||
2870 | 46 | |||
2871 | 47 | /** | ||
2872 | 48 | * Add a new client to a server instance. | ||
2873 | 49 | */ | ||
2874 | 50 | GEARMAN_API | ||
2875 | 51 | gearman_server_client_st * | ||
2876 | 52 | gearman_server_client_add(gearman_server_con_st *con); | ||
2877 | 53 | |||
2878 | 54 | /** | ||
2879 | 55 | * Initialize a server client structure. | ||
2880 | 56 | */ | ||
2881 | 57 | GEARMAN_API | ||
2882 | 58 | gearman_server_client_st * | ||
2883 | 59 | gearman_server_client_create(gearman_server_con_st *con, | ||
2884 | 60 | gearman_server_client_st *client); | ||
2885 | 61 | |||
2886 | 62 | /** | ||
2887 | 63 | * Free a server client structure. | ||
2888 | 64 | */ | ||
2889 | 65 | GEARMAN_API | ||
2890 | 66 | void gearman_server_client_free(gearman_server_client_st *client); | ||
2891 | 67 | |||
2892 | 68 | /** @} */ | ||
2893 | 69 | |||
2894 | 70 | #ifdef __cplusplus | ||
2895 | 71 | } | ||
2896 | 72 | #endif | ||
2897 | 73 | |||
2898 | 74 | #endif /* __GEARMAN_SERVER_CLIENT_H__ */ | 34 | #endif /* __GEARMAN_SERVER_CLIENT_H__ */ |
2899 | 75 | 35 | ||
2900 | === modified file 'libgearman-server/common.h' | |||
2901 | --- libgearman-server/common.h 2010-04-02 02:04:04 +0000 | |||
2902 | +++ libgearman-server/common.h 2010-07-01 01:31:26 +0000 | |||
2903 | @@ -1,4 +1,5 @@ | |||
2904 | 1 | /* Gearman server and library | 1 | /* Gearman server and library |
2905 | 2 | * Copyright (C) 2010 Data Differential | ||
2906 | 2 | * Copyright (C) 2008 Brian Aker, Eric Day | 3 | * Copyright (C) 2008 Brian Aker, Eric Day |
2907 | 3 | * All rights reserved. | 4 | * All rights reserved. |
2908 | 4 | * | 5 | * |
2909 | @@ -16,8 +17,13 @@ | |||
2910 | 16 | 17 | ||
2911 | 17 | #include "config.h" | 18 | #include "config.h" |
2912 | 18 | 19 | ||
2913 | 20 | #define __STDC_LIMIT_MACROS | ||
2914 | 21 | #define __STDC_FORMAT_MACROS | ||
2915 | 22 | |||
2916 | 23 | #include <cstdarg> | ||
2917 | 24 | |||
2918 | 19 | #define GEARMAN_CORE | 25 | #define GEARMAN_CORE |
2920 | 20 | #include "gearmand.h" | 26 | #include "libgearman-server/gearmand.h" |
2921 | 21 | 27 | ||
2922 | 22 | #ifdef HAVE_ASSERT_H | 28 | #ifdef HAVE_ASSERT_H |
2923 | 23 | #include <assert.h> | 29 | #include <assert.h> |
2924 | @@ -34,9 +40,6 @@ | |||
2925 | 34 | #ifdef HAVE_PTHREAD | 40 | #ifdef HAVE_PTHREAD |
2926 | 35 | #include <pthread.h> | 41 | #include <pthread.h> |
2927 | 36 | #endif | 42 | #endif |
2928 | 37 | #ifdef HAVE_STDARG_H | ||
2929 | 38 | #include <stdarg.h> | ||
2930 | 39 | #endif | ||
2931 | 40 | #ifdef HAVE_STDDEF_H | 43 | #ifdef HAVE_STDDEF_H |
2932 | 41 | #include <stddef.h> | 44 | #include <stddef.h> |
2933 | 42 | #endif | 45 | #endif |
2934 | @@ -116,30 +119,6 @@ | |||
2935 | 116 | } | 119 | } |
2936 | 117 | 120 | ||
2937 | 118 | /** | 121 | /** |
2938 | 119 | * Add an object to a fifo list. | ||
2939 | 120 | * @ingroup gearman_constants | ||
2940 | 121 | */ | ||
2941 | 122 | #define GEARMAN_FIFO_ADD(__list, __obj, __prefix) { \ | ||
2942 | 123 | if (__list ## _end == NULL) \ | ||
2943 | 124 | __list ## _list= __obj; \ | ||
2944 | 125 | else \ | ||
2945 | 126 | __list ## _end->__prefix ## next= __obj; \ | ||
2946 | 127 | __list ## _end= __obj; \ | ||
2947 | 128 | __list ## _count++; \ | ||
2948 | 129 | } | ||
2949 | 130 | |||
2950 | 131 | /** | ||
2951 | 132 | * Delete an object from a fifo list. | ||
2952 | 133 | * @ingroup gearman_constants | ||
2953 | 134 | */ | ||
2954 | 135 | #define GEARMAN_FIFO_DEL(__list, __obj, __prefix) { \ | ||
2955 | 136 | __list ## _list= __obj->__prefix ## next; \ | ||
2956 | 137 | if (__list ## _list == NULL) \ | ||
2957 | 138 | __list ## _end= NULL; \ | ||
2958 | 139 | __list ## _count--; \ | ||
2959 | 140 | } | ||
2960 | 141 | |||
2961 | 142 | /** | ||
2962 | 143 | * Add an object to a hash. | 122 | * Add an object to a hash. |
2963 | 144 | * @ingroup gearman_constants | 123 | * @ingroup gearman_constants |
2964 | 145 | */ | 124 | */ |
2965 | @@ -184,4 +163,18 @@ | |||
2966 | 184 | } | 163 | } |
2967 | 185 | #endif | 164 | #endif |
2968 | 186 | 165 | ||
2969 | 166 | #include <boost/bind.hpp> | ||
2970 | 167 | #include <boost/foreach.hpp> | ||
2971 | 168 | #include <boost/program_options/options_description.hpp> | ||
2972 | 169 | #include <boost/program_options/parsers.hpp> | ||
2973 | 170 | #include <boost/program_options/variables_map.hpp> | ||
2974 | 171 | #include <boost/shared_ptr.hpp> | ||
2975 | 172 | #include <boost/smart_ptr/shared_ptr.hpp> | ||
2976 | 173 | #include <boost/thread/condition.hpp> | ||
2977 | 174 | #include <boost/thread/mutex.hpp> | ||
2978 | 175 | #include <boost/thread/thread.hpp> | ||
2979 | 176 | #include <boost/token_functions.hpp> | ||
2980 | 177 | #include <boost/tokenizer.hpp> | ||
2981 | 178 | #include <boost/unordered_map.hpp> | ||
2982 | 179 | |||
2983 | 187 | #endif /* __GEARMAN_SERVER_COMMON_H__ */ | 180 | #endif /* __GEARMAN_SERVER_COMMON_H__ */ |
2984 | 188 | 181 | ||
2985 | === renamed file 'libgearman-server/conf.c' => 'libgearman-server/conf.c.THIS' | |||
2986 | === removed file 'libgearman-server/conf.h' | |||
2987 | --- libgearman-server/conf.h 2010-03-11 20:33:13 +0000 | |||
2988 | +++ libgearman-server/conf.h 1970-01-01 00:00:00 +0000 | |||
2989 | @@ -1,103 +0,0 @@ | |||
2990 | 1 | /* Gearman server and library | ||
2991 | 2 | * Copyright (C) 2009 Eric Day | ||
2992 | 3 | * All rights reserved. | ||
2993 | 4 | * | ||
2994 | 5 | * Use and distribution licensed under the BSD license. See | ||
2995 | 6 | * the COPYING file in the parent directory for full text. | ||
2996 | 7 | */ | ||
2997 | 8 | |||
2998 | 9 | /** | ||
2999 | 10 | * @file | ||
3000 | 11 | * @brief Configuration Declarations | ||
3001 | 12 | */ | ||
3002 | 13 | |||
3003 | 14 | #ifndef __GEARMAN_SERVER_CONF_H__ | ||
3004 | 15 | #define __GEARMAN_SERVER_CONF_H__ | ||
3005 | 16 | |||
3006 | 17 | #ifdef __cplusplus | ||
3007 | 18 | extern "C" { | ||
3008 | 19 | #endif | ||
3009 | 20 | |||
3010 | 21 | /** | ||
3011 | 22 | * @addtogroup gearman_conf Configuration Declarations | ||
3012 | 23 | * @ingroup gearman_server | ||
3013 | 24 | * @{ | ||
3014 | 25 | */ | ||
3015 | 26 | |||
3016 | 27 | struct gearman_conf_option_st | ||
3017 | 28 | { | ||
3018 | 29 | size_t value_count; | ||
3019 | 30 | gearman_conf_module_st *module; | ||
3020 | 31 | const char *name; | ||
3021 | 32 | const char *value_name; | ||
3022 | 33 | const char *help; | ||
3023 | 34 | char **value_list; | ||
3024 | 35 | }; | ||
3025 | 36 | |||
3026 | 37 | struct gearman_conf_st | ||
3027 | 38 | { | ||
3028 | 39 | struct { | ||
3029 | 40 | bool allocated; | ||
3030 | 41 | } options; | ||
3031 | 42 | gearman_return_t last_return; | ||
3032 | 43 | int last_errno; | ||
3033 | 44 | size_t module_count; | ||
3034 | 45 | size_t option_count; | ||
3035 | 46 | size_t short_count; | ||
3036 | 47 | gearman_conf_module_st **module_list; | ||
3037 | 48 | gearman_conf_option_st *option_list; | ||
3038 | 49 | struct option *option_getopt; | ||
3039 | 50 | char option_short[GEARMAN_CONF_MAX_OPTION_SHORT]; | ||
3040 | 51 | char last_error[GEARMAN_MAX_ERROR_SIZE]; | ||
3041 | 52 | }; | ||
3042 | 53 | |||
3043 | 54 | /** | ||
3044 | 55 | * Initialize a gearman conf structure. | ||
3045 | 56 | */ | ||
3046 | 57 | GEARMAN_API | ||
3047 | 58 | gearman_conf_st *gearman_conf_create(gearman_conf_st *conf); | ||
3048 | 59 | |||
3049 | 60 | /** | ||
3050 | 61 | * Free a gearman conf structure. | ||
3051 | 62 | */ | ||
3052 | 63 | GEARMAN_API | ||
3053 | 64 | void gearman_conf_free(gearman_conf_st *conf); | ||
3054 | 65 | |||
3055 | 66 | /** | ||
3056 | 67 | * Return an return code for the last library error encountered. | ||
3057 | 68 | */ | ||
3058 | 69 | GEARMAN_API | ||
3059 | 70 | gearman_return_t gearman_conf_return(gearman_conf_st *conf); | ||
3060 | 71 | |||
3061 | 72 | /** | ||
3062 | 73 | * Return an error string for last library error encountered. | ||
3063 | 74 | */ | ||
3064 | 75 | GEARMAN_API | ||
3065 | 76 | const char *gearman_conf_error(gearman_conf_st *conf); | ||
3066 | 77 | |||
3067 | 78 | /** | ||
3068 | 79 | * Value of errno in the case of a GEARMAN_ERRNO return value. | ||
3069 | 80 | */ | ||
3070 | 81 | GEARMAN_API | ||
3071 | 82 | int gearman_conf_errno(gearman_conf_st *conf); | ||
3072 | 83 | |||
3073 | 84 | /** | ||
3074 | 85 | * Parse command line arguments. | ||
3075 | 86 | */ | ||
3076 | 87 | GEARMAN_API | ||
3077 | 88 | gearman_return_t gearman_conf_parse_args(gearman_conf_st *conf, int argc, | ||
3078 | 89 | char *argv[]); | ||
3079 | 90 | |||
3080 | 91 | /** | ||
3081 | 92 | * Print usage information to stdout. | ||
3082 | 93 | */ | ||
3083 | 94 | GEARMAN_API | ||
3084 | 95 | void gearman_conf_usage(gearman_conf_st *conf); | ||
3085 | 96 | |||
3086 | 97 | /** @} */ | ||
3087 | 98 | |||
3088 | 99 | #ifdef __cplusplus | ||
3089 | 100 | } | ||
3090 | 101 | #endif | ||
3091 | 102 | |||
3092 | 103 | #endif /* __GEARMAN_SERVER_CONF_H__ */ | ||
3093 | 104 | 0 | ||
3094 | === renamed file 'libgearman-server/conf_module.c' => 'libgearman-server/conf_module.c.THIS' | |||
3095 | === removed file 'libgearman-server/conf_module.h' | |||
3096 | --- libgearman-server/conf_module.h 2010-03-11 22:45:34 +0000 | |||
3097 | +++ libgearman-server/conf_module.h 1970-01-01 00:00:00 +0000 | |||
3098 | @@ -1,80 +0,0 @@ | |||
3099 | 1 | /* Module configuration library | ||
3100 | 2 | * Copyright (C) 2009 Eric Day | ||
3101 | 3 | * All rights reserved. | ||
3102 | 4 | * | ||
3103 | 5 | * Use and distribution licensed under the BSD license. See | ||
3104 | 6 | * the COPYING file in the parent directory for full text. | ||
3105 | 7 | */ | ||
3106 | 8 | |||
3107 | 9 | /** | ||
3108 | 10 | * @file | ||
3109 | 11 | * @brief Configuration Module Declarations | ||
3110 | 12 | */ | ||
3111 | 13 | |||
3112 | 14 | #ifndef __GEARMAN_SERVER_CONF_MODULE_H__ | ||
3113 | 15 | #define __GEARMAN_SERVER_CONF_MODULE_H__ | ||
3114 | 16 | |||
3115 | 17 | #ifdef __cplusplus | ||
3116 | 18 | extern "C" { | ||
3117 | 19 | #endif | ||
3118 | 20 | |||
3119 | 21 | /** | ||
3120 | 22 | * @addtogroup gearman_conf_module Configuration Module Declarations | ||
3121 | 23 | * @ingroup gearman_server | ||
3122 | 24 | * @{ | ||
3123 | 25 | */ | ||
3124 | 26 | |||
3125 | 27 | struct gearman_conf_module_st | ||
3126 | 28 | { | ||
3127 | 29 | struct { | ||
3128 | 30 | bool allocated; | ||
3129 | 31 | } options; | ||
3130 | 32 | size_t current_option; | ||
3131 | 33 | size_t current_value; | ||
3132 | 34 | gearman_conf_st *conf; | ||
3133 | 35 | const char *name; | ||
3134 | 36 | }; | ||
3135 | 37 | |||
3136 | 38 | /** | ||
3137 | 39 | * Initialize a gearman conf module structure. | ||
3138 | 40 | */ | ||
3139 | 41 | GEARMAN_API | ||
3140 | 42 | gearman_conf_module_st *gearman_conf_module_create(gearman_conf_st *conf, | ||
3141 | 43 | gearman_conf_module_st *module, | ||
3142 | 44 | const char *name); | ||
3143 | 45 | |||
3144 | 46 | /** | ||
3145 | 47 | * Free a gearman conf module structure. | ||
3146 | 48 | */ | ||
3147 | 49 | GEARMAN_API | ||
3148 | 50 | void gearman_conf_module_free(gearman_conf_module_st *module); | ||
3149 | 51 | |||
3150 | 52 | /** | ||
3151 | 53 | * Find a gearman conf module structure by name. | ||
3152 | 54 | */ | ||
3153 | 55 | GEARMAN_API | ||
3154 | 56 | gearman_conf_module_st *gearman_conf_module_find(gearman_conf_st *conf, | ||
3155 | 57 | const char *name); | ||
3156 | 58 | |||
3157 | 59 | /** | ||
3158 | 60 | * Add option for a module. | ||
3159 | 61 | */ | ||
3160 | 62 | GEARMAN_API | ||
3161 | 63 | void gearman_conf_module_add_option(gearman_conf_module_st *module, | ||
3162 | 64 | const char *name, int short_name, | ||
3163 | 65 | const char *value_name, const char *help); | ||
3164 | 66 | |||
3165 | 67 | /** | ||
3166 | 68 | * Loop through all values that were given for a set of module options. | ||
3167 | 69 | */ | ||
3168 | 70 | GEARMAN_API | ||
3169 | 71 | bool gearman_conf_module_value(gearman_conf_module_st *module, | ||
3170 | 72 | const char **name, const char **value); | ||
3171 | 73 | |||
3172 | 74 | /** @} */ | ||
3173 | 75 | |||
3174 | 76 | #ifdef __cplusplus | ||
3175 | 77 | } | ||
3176 | 78 | #endif | ||
3177 | 79 | |||
3178 | 80 | #endif /* __GEARMAN_SERVER_CONF_MODULE_H__ */ | ||
3179 | 81 | 0 | ||
3180 | === renamed file 'libgearman-server/connection.c' => 'libgearman-server/connection.cc' | |||
3181 | --- libgearman-server/connection.c 2010-04-06 21:41:46 +0000 | |||
3182 | +++ libgearman-server/connection.cc 2010-07-01 01:31:26 +0000 | |||
3183 | @@ -1,4 +1,5 @@ | |||
3184 | 1 | /* Gearman server and library | 1 | /* Gearman server and library |
3185 | 2 | * Copyright (C) 2010 Data Differential | ||
3186 | 2 | * Copyright (C) 2008 Brian Aker, Eric Day | 3 | * Copyright (C) 2008 Brian Aker, Eric Day |
3187 | 3 | * All rights reserved. | 4 | * All rights reserved. |
3188 | 4 | * | 5 | * |
3189 | @@ -11,12 +12,13 @@ | |||
3190 | 11 | * @brief Server connection definitions | 12 | * @brief Server connection definitions |
3191 | 12 | */ | 13 | */ |
3192 | 13 | 14 | ||
3194 | 14 | #include "common.h" | 15 | #include "libgearman-server/common.h" |
3195 | 15 | 16 | ||
3196 | 16 | /* | 17 | /* |
3197 | 17 | * Public definitions | 18 | * Public definitions |
3198 | 18 | */ | 19 | */ |
3199 | 19 | 20 | ||
3200 | 21 | <<<<<<< TREE | ||
3201 | 20 | gearman_server_con_st *gearman_server_con_add(gearman_server_thread_st *thread, | 22 | gearman_server_con_st *gearman_server_con_add(gearman_server_thread_st *thread, |
3202 | 21 | int fd, void *data) | 23 | int fd, void *data) |
3203 | 22 | { | 24 | { |
3204 | @@ -115,128 +117,150 @@ | |||
3205 | 115 | 117 | ||
3206 | 116 | con->host= NULL; | 118 | con->host= NULL; |
3207 | 117 | con->port= NULL; | 119 | con->port= NULL; |
3208 | 120 | ======= | ||
3209 | 121 | gearman_server_con_st::gearman_server_con_st(gearman_server_thread_st *thread_arg) : | ||
3210 | 122 | is_sleeping(false), | ||
3211 | 123 | is_exceptions(false), | ||
3212 | 124 | is_dead(false), | ||
3213 | 125 | is_noop_sent(false), | ||
3214 | 126 | ret(GEARMAN_SUCCESS), | ||
3215 | 127 | io_list(false), | ||
3216 | 128 | proc_list(false), | ||
3217 | 129 | proc_removed(false), | ||
3218 | 130 | worker_count(0), | ||
3219 | 131 | client_count(0), | ||
3220 | 132 | thread(thread_arg), | ||
3221 | 133 | packet(NULL), | ||
3222 | 134 | io_next(NULL), | ||
3223 | 135 | io_prev(NULL), | ||
3224 | 136 | proc_next(NULL), | ||
3225 | 137 | proc_prev(NULL), | ||
3226 | 138 | worker_list(NULL), | ||
3227 | 139 | client_list(NULL), | ||
3228 | 140 | _host(NULL), | ||
3229 | 141 | _port(NULL) | ||
3230 | 142 | { | ||
3231 | 143 | strcpy(_id, "-"); | ||
3232 | 144 | |||
3233 | 145 | gearman_connection_options_t _options[] = { GEARMAN_CON_IGNORE_LOST_CONNECTION, GEARMAN_CON_MAX }; | ||
3234 | 146 | if (gearman_connection_create(&thread_arg->gearman, con(), _options) == NULL) | ||
3235 | 147 | { | ||
3236 | 148 | abort(); // Should be impossible | ||
3237 | 149 | } | ||
3238 | 150 | } | ||
3239 | 151 | |||
3240 | 152 | gearman_server_con_st::~gearman_server_con_st() | ||
3241 | 153 | { | ||
3242 | 154 | _host= NULL; | ||
3243 | 155 | _port= NULL; | ||
3244 | 156 | |||
3245 | 157 | { | ||
3246 | 158 | boost::mutex::scoped_lock l(thread->lock); | ||
3247 | 159 | thread->con_list.erase(this); | ||
3248 | 160 | } | ||
3249 | 161 | >>>>>>> MERGE-SOURCE | ||
3250 | 118 | 162 | ||
3251 | 119 | if (thread->server->flags.threaded && | 163 | if (thread->server->flags.threaded && |
3253 | 120 | !(con->proc_removed) && !(thread->server->proc_shutdown)) | 164 | !(proc_removed) && !(thread->server->proc_shutdown)) |
3254 | 121 | { | 165 | { |
3260 | 122 | con->is_dead= true; | 166 | is_dead= true; |
3261 | 123 | con->is_sleeping= false; | 167 | is_sleeping= false; |
3262 | 124 | con->is_exceptions= false; | 168 | is_exceptions= false; |
3263 | 125 | con->is_noop_sent= false; | 169 | is_noop_sent= false; |
3264 | 126 | gearman_server_con_proc_add(con); | 170 | proc_add(); |
3265 | 127 | return; | 171 | return; |
3266 | 128 | } | 172 | } |
3267 | 129 | 173 | ||
3350 | 130 | gearman_connection_free(&(con->con)); | 174 | if (proc_list) |
3351 | 131 | 175 | proc_remove(); | |
3352 | 132 | if (con->proc_list) | 176 | |
3353 | 133 | gearman_server_con_proc_remove(con); | 177 | if (io_list) |
3354 | 134 | 178 | io_remove(); | |
3355 | 135 | if (con->io_list) | 179 | |
3356 | 136 | gearman_server_con_io_remove(con); | 180 | if (packet != NULL) |
3357 | 137 | 181 | { | |
3358 | 138 | if (con->packet != NULL) | 182 | if (&packet->packet != con()->recv_packet) |
3359 | 139 | { | 183 | { } |
3360 | 140 | if (&(con->packet->packet) != con->con.recv_packet) | 184 | else |
3361 | 141 | gearman_packet_free(&(con->packet->packet)); | 185 | { |
3362 | 142 | gearman_server_packet_free(con->packet, con->thread, true); | 186 | packet->release_packet= false; |
3363 | 143 | } | 187 | } |
3364 | 144 | 188 | delete packet; | |
3365 | 145 | while (con->io_packet_list != NULL) | 189 | } |
3366 | 146 | gearman_server_io_packet_remove(con); | 190 | |
3367 | 147 | 191 | assert(con()->options.allocated == false); | |
3368 | 148 | while (con->proc_packet_list != NULL) | 192 | gearman_connection_free(con()); |
3369 | 149 | { | 193 | |
3370 | 150 | packet= gearman_server_proc_packet_remove(con); | 194 | while (io_packet_list.size()) |
3371 | 151 | gearman_packet_free(&(packet->packet)); | 195 | { |
3372 | 152 | gearman_server_packet_free(packet, con->thread, true); | 196 | io_packet_remove(); |
3373 | 153 | } | 197 | } |
3374 | 154 | 198 | ||
3375 | 155 | gearman_server_con_free_workers(con); | 199 | while (proc_packet_list.size()) |
3376 | 156 | 200 | { | |
3377 | 157 | while (con->client_list != NULL) | 201 | gearman_server_packet_st *packet_ptr; |
3378 | 158 | gearman_server_client_free(con->client_list); | 202 | |
3379 | 159 | 203 | packet_ptr= proc_packet_remove(); | |
3380 | 160 | (void) pthread_mutex_lock(&thread->lock); | 204 | delete packet_ptr; |
3381 | 161 | GEARMAN_LIST_DEL(con->thread->con, con,) | 205 | } |
3382 | 162 | (void) pthread_mutex_unlock(&thread->lock); | 206 | |
3383 | 163 | 207 | while (worker_list != NULL) | |
3384 | 164 | if (thread->free_con_count < GEARMAN_MAX_FREE_SERVER_CON) | 208 | { |
3385 | 165 | GEARMAN_LIST_ADD(thread->free_con, con,) | 209 | delete worker_list; |
3386 | 166 | else | 210 | } |
3387 | 167 | free(con); | 211 | |
3388 | 168 | } | 212 | while (client_list != NULL) |
3389 | 169 | 213 | { | |
3390 | 170 | gearman_connection_st *gearman_server_con_con(gearman_server_con_st *con) | 214 | client_list->con->thread->server->client_free(client_list); |
3391 | 171 | { | 215 | } |
3392 | 172 | return &con->con; | 216 | } |
3393 | 173 | } | 217 | |
3394 | 174 | 218 | const void *gearman_server_con_st::data() | |
3395 | 175 | const void *gearman_server_con_data(const gearman_server_con_st *con) | 219 | { |
3396 | 176 | { | 220 | return gearman_connection_context(con()); |
3397 | 177 | return gearman_connection_context(&(con->con)); | 221 | } |
3398 | 178 | } | 222 | |
3399 | 179 | 223 | void gearman_server_con_st::set_host(const char *host_arg) | |
3400 | 180 | void gearman_server_con_set_data(gearman_server_con_st *con, void *data) | 224 | { |
3401 | 181 | { | 225 | _host= host_arg; |
3402 | 182 | gearman_connection_set_context(&(con->con), data); | 226 | } |
3403 | 183 | } | 227 | |
3404 | 184 | 228 | void gearman_server_con_st::set_port(const char *port_arg) | |
3405 | 185 | const char *gearman_server_con_host(gearman_server_con_st *con) | 229 | { |
3406 | 186 | { | 230 | _port= port_arg; |
3407 | 187 | return con->host; | 231 | } |
3408 | 188 | } | 232 | |
3409 | 189 | 233 | void gearman_server_con_st::set_id(char *id_arg, size_t size) | |
3328 | 190 | void gearman_server_con_set_host(gearman_server_con_st *con, const char *host) | ||
3329 | 191 | { | ||
3330 | 192 | con->host= host; | ||
3331 | 193 | } | ||
3332 | 194 | |||
3333 | 195 | const char *gearman_server_con_port(gearman_server_con_st *con) | ||
3334 | 196 | { | ||
3335 | 197 | return con->port; | ||
3336 | 198 | } | ||
3337 | 199 | |||
3338 | 200 | void gearman_server_con_set_port(gearman_server_con_st *con, const char *port) | ||
3339 | 201 | { | ||
3340 | 202 | con->port= port; | ||
3341 | 203 | } | ||
3342 | 204 | |||
3343 | 205 | const char *gearman_server_con_id(gearman_server_con_st *con) | ||
3344 | 206 | { | ||
3345 | 207 | return con->id; | ||
3346 | 208 | } | ||
3347 | 209 | |||
3348 | 210 | void gearman_server_con_set_id(gearman_server_con_st *con, char *id, | ||
3349 | 211 | size_t size) | ||
3410 | 212 | { | 234 | { |
3411 | 213 | if (size >= GEARMAN_SERVER_CON_ID_SIZE) | 235 | if (size >= GEARMAN_SERVER_CON_ID_SIZE) |
3412 | 214 | size= GEARMAN_SERVER_CON_ID_SIZE - 1; | 236 | size= GEARMAN_SERVER_CON_ID_SIZE - 1; |
3413 | 215 | 237 | ||
3416 | 216 | memcpy(con->id, id, size); | 238 | memcpy(_id, id_arg, size); |
3417 | 217 | con->id[size]= 0; | 239 | _id[size]= 0; |
3418 | 218 | } | 240 | } |
3419 | 219 | 241 | ||
3423 | 220 | void gearman_server_con_free_worker(gearman_server_con_st *con, | 242 | void gearman_server_con_st::free_worker(const char *function_name_arg, |
3424 | 221 | char *function_name, | 243 | size_t function_name_size_arg) |
3422 | 222 | size_t function_name_size) | ||
3425 | 223 | { | 244 | { |
3427 | 224 | gearman_server_worker_st *worker= con->worker_list; | 245 | gearman_server_worker_st *worker= worker_list; |
3428 | 225 | gearman_server_worker_st *prev_worker= NULL; | 246 | gearman_server_worker_st *prev_worker= NULL; |
3429 | 226 | 247 | ||
3430 | 227 | while (worker != NULL) | 248 | while (worker != NULL) |
3431 | 228 | { | 249 | { |
3435 | 229 | if (worker->function->function_name_size == function_name_size && | 250 | if (worker->function->function_name.length() == function_name_size_arg && |
3436 | 230 | !memcmp(worker->function->function_name, function_name, | 251 | !memcmp(worker->function->function_name.c_str(), function_name_arg, function_name_size_arg)) |
3434 | 231 | function_name_size)) | ||
3437 | 232 | { | 252 | { |
3439 | 233 | gearman_server_worker_free(worker); | 253 | delete worker; |
3440 | 234 | 254 | ||
3441 | 235 | /* Set worker to the last kept worker, or the beginning of the list. */ | 255 | /* Set worker to the last kept worker, or the beginning of the list. */ |
3442 | 236 | if (prev_worker == NULL) | 256 | if (prev_worker == NULL) |
3444 | 237 | worker= con->worker_list; | 257 | { |
3445 | 258 | worker= worker_list; | ||
3446 | 259 | } | ||
3447 | 238 | else | 260 | else |
3448 | 261 | { | ||
3449 | 239 | worker= prev_worker; | 262 | worker= prev_worker; |
3450 | 263 | } | ||
3451 | 240 | } | 264 | } |
3452 | 241 | else | 265 | else |
3453 | 242 | { | 266 | { |
3454 | @@ -247,111 +271,424 @@ | |||
3455 | 247 | } | 271 | } |
3456 | 248 | } | 272 | } |
3457 | 249 | 273 | ||
3459 | 250 | void gearman_server_con_free_workers(gearman_server_con_st *con) | 274 | void gearman_server_con_st::free_workers() |
3460 | 251 | { | 275 | { |
3463 | 252 | while (con->worker_list != NULL) | 276 | while (worker_list != NULL) |
3464 | 253 | gearman_server_worker_free(con->worker_list); | 277 | { |
3465 | 278 | delete worker_list; | ||
3466 | 279 | } | ||
3467 | 254 | } | 280 | } |
3468 | 255 | 281 | ||
3470 | 256 | void gearman_server_con_io_add(gearman_server_con_st *con) | 282 | void gearman_server_con_st::io_add() |
3471 | 257 | { | 283 | { |
3473 | 258 | if (con->io_list) | 284 | if (io_list) |
3474 | 259 | return; | 285 | return; |
3475 | 260 | 286 | ||
3477 | 261 | (void) pthread_mutex_lock(&con->thread->lock); | 287 | thread->lock.lock(); |
3478 | 262 | 288 | ||
3481 | 263 | GEARMAN_LIST_ADD(con->thread->io, con, io_) | 289 | GEARMAN_LIST_ADD(thread->io, this, io_) |
3482 | 264 | con->io_list= true; | 290 | io_list= true; |
3483 | 265 | 291 | ||
3484 | 266 | /* Looks funny, but need to check io_count locked, but call run unlocked. */ | 292 | /* Looks funny, but need to check io_count locked, but call run unlocked. */ |
3486 | 267 | if (con->thread->io_count == 1 && con->thread->run_fn) | 293 | if (thread->io_count == 1 && thread->run_fn) |
3487 | 268 | { | 294 | { |
3490 | 269 | (void) pthread_mutex_unlock(&con->thread->lock); | 295 | thread->lock.unlock(); |
3491 | 270 | (*con->thread->run_fn)(con->thread, con->thread->run_fn_arg); | 296 | (*thread->run_fn)(thread, thread->run_fn_arg); |
3492 | 271 | } | 297 | } |
3493 | 272 | else | 298 | else |
3494 | 273 | { | 299 | { |
3496 | 274 | (void) pthread_mutex_unlock(&con->thread->lock); | 300 | thread->lock.unlock(); |
3497 | 275 | } | 301 | } |
3498 | 276 | } | 302 | } |
3499 | 277 | 303 | ||
3501 | 278 | void gearman_server_con_io_remove(gearman_server_con_st *con) | 304 | void gearman_server_con_st::io_remove() |
3502 | 279 | { | 305 | { |
3505 | 280 | (void) pthread_mutex_lock(&con->thread->lock); | 306 | boost::mutex::scoped_lock l(thread->lock); |
3506 | 281 | if (con->io_list) | 307 | if (io_list) |
3507 | 282 | { | 308 | { |
3510 | 283 | GEARMAN_LIST_DEL(con->thread->io, con, io_) | 309 | GEARMAN_LIST_DEL(thread->io, this, io_) |
3511 | 284 | con->io_list= false; | 310 | io_list= false; |
3512 | 285 | } | 311 | } |
3532 | 286 | (void) pthread_mutex_unlock(&con->thread->lock); | 312 | } |
3533 | 287 | } | 313 | |
3534 | 288 | 314 | void gearman_server_con_st::proc_add() | |
3535 | 289 | gearman_server_con_st * | 315 | { |
3536 | 290 | gearman_server_con_io_next(gearman_server_thread_st *thread) | 316 | if (proc_list) |
3518 | 291 | { | ||
3519 | 292 | gearman_server_con_st *con= thread->io_list; | ||
3520 | 293 | |||
3521 | 294 | if (con == NULL) | ||
3522 | 295 | return NULL; | ||
3523 | 296 | |||
3524 | 297 | gearman_server_con_io_remove(con); | ||
3525 | 298 | |||
3526 | 299 | return con; | ||
3527 | 300 | } | ||
3528 | 301 | |||
3529 | 302 | void gearman_server_con_proc_add(gearman_server_con_st *con) | ||
3530 | 303 | { | ||
3531 | 304 | if (con->proc_list) | ||
3537 | 305 | return; | 317 | return; |
3538 | 306 | 318 | ||
3589 | 307 | (void) pthread_mutex_lock(&con->thread->lock); | 319 | { |
3590 | 308 | GEARMAN_LIST_ADD(con->thread->proc, con, proc_) | 320 | boost::mutex::scoped_lock l(thread->lock); |
3591 | 309 | con->proc_list= true; | 321 | GEARMAN_LIST_ADD(thread->proc, this, proc_); |
3592 | 310 | (void) pthread_mutex_unlock(&con->thread->lock); | 322 | proc_list= true; |
3593 | 311 | 323 | } | |
3594 | 312 | if (! (con->thread->server->proc_shutdown) && | 324 | |
3595 | 313 | !(con->thread->server->proc_wakeup)) | 325 | if (! (thread->server->proc_shutdown) && |
3596 | 314 | { | 326 | !(thread->server->proc_wakeup)) |
3597 | 315 | (void) pthread_mutex_lock(&(con->thread->server->proc_lock)); | 327 | { |
3598 | 316 | con->thread->server->proc_wakeup= true; | 328 | |
3599 | 317 | (void) pthread_cond_signal(&(con->thread->server->proc_cond)); | 329 | // Rethink this (copied from straight pthread) |
3600 | 318 | (void) pthread_mutex_unlock(&(con->thread->server->proc_lock)); | 330 | boost::mutex::scoped_lock l(thread->server->proc_lock); |
3601 | 319 | } | 331 | thread->server->proc_wakeup= true; |
3602 | 320 | } | 332 | thread->server->proc_cond.notify_all(); |
3603 | 321 | 333 | } | |
3604 | 322 | void gearman_server_con_proc_remove(gearman_server_con_st *con) | 334 | } |
3605 | 323 | { | 335 | |
3606 | 324 | (void) pthread_mutex_lock(&con->thread->lock); | 336 | void gearman_server_con_st::proc_remove() |
3607 | 325 | 337 | { | |
3608 | 326 | if (con->proc_list) | 338 | boost::mutex::scoped_lock l(thread->lock); |
3609 | 327 | { | 339 | |
3610 | 328 | GEARMAN_LIST_DEL(con->thread->proc, con, proc_) | 340 | if (proc_list) |
3611 | 329 | con->proc_list= false; | 341 | { |
3612 | 330 | } | 342 | GEARMAN_LIST_DEL(thread->proc, this, proc_) |
3613 | 331 | (void) pthread_mutex_unlock(&con->thread->lock); | 343 | proc_list= false; |
3614 | 332 | } | 344 | } |
3615 | 333 | 345 | } | |
3616 | 334 | gearman_server_con_st * | 346 | |
3617 | 335 | gearman_server_con_proc_next(gearman_server_thread_st *thread) | 347 | gearman_server_client_st *gearman_server_con_st::client_create() |
3618 | 336 | { | 348 | { |
3619 | 337 | gearman_server_con_st *con; | 349 | gearman_server_client_st *client; |
3620 | 338 | 350 | ||
3621 | 339 | if (thread->proc_list == NULL) | 351 | { |
3622 | 340 | return NULL; | 352 | client= new gearman_server_client_st; |
3623 | 341 | 353 | if (client == NULL) | |
3624 | 342 | (void) pthread_mutex_lock(&thread->lock); | 354 | { |
3625 | 343 | 355 | Log::Instance()->error("gearman_server_client_create: new()"); | |
3626 | 344 | con= thread->proc_list; | 356 | |
3627 | 345 | while (con != NULL) | 357 | return NULL; |
3628 | 346 | { | 358 | } |
3629 | 347 | GEARMAN_LIST_DEL(thread->proc, con, proc_) | 359 | } |
3630 | 348 | con->proc_list= false; | 360 | |
3631 | 349 | if (!(con->proc_removed)) | 361 | client->con= this; |
3632 | 350 | break; | 362 | GEARMAN_LIST_ADD(client, client, con_) |
3633 | 351 | con= thread->proc_list; | 363 | |
3634 | 352 | } | 364 | return client; |
3635 | 353 | 365 | } | |
3636 | 354 | (void) pthread_mutex_unlock(&thread->lock); | 366 | |
3637 | 355 | 367 | gearman_server_client_st *gearman_server_con_st::client_add() | |
3638 | 356 | return con; | 368 | { |
3639 | 369 | gearman_server_client_st *client; | ||
3640 | 370 | |||
3641 | 371 | client= client_create(); | ||
3642 | 372 | if (client == NULL) | ||
3643 | 373 | return NULL; | ||
3644 | 374 | |||
3645 | 375 | return client; | ||
3646 | 376 | } | ||
3647 | 377 | |||
3648 | 378 | |||
3649 | 379 | gearman_server_worker_st * | ||
3650 | 380 | gearman_server_con_st::worker_create(gearman_server_function_st *function) | ||
3651 | 381 | { | ||
3652 | 382 | gearman_server_worker_st *worker= NULL; | ||
3653 | 383 | |||
3654 | 384 | worker= new gearman_server_worker_st(this, function); | ||
3655 | 385 | |||
3656 | 386 | GEARMAN_LIST_ADD(worker, worker, con_); | ||
3657 | 387 | |||
3658 | 388 | Log::Instance()->event(Logger::WORKER_CREATED, NULL); | ||
3659 | 389 | |||
3660 | 390 | /* Add worker to the function list, which is a double-linked circular list. */ | ||
3661 | 391 | if (function->worker_list == NULL) | ||
3662 | 392 | { | ||
3663 | 393 | function->worker_list= worker; | ||
3664 | 394 | worker->function_next= worker; | ||
3665 | 395 | worker->function_prev= worker; | ||
3666 | 396 | } | ||
3667 | 397 | else | ||
3668 | 398 | { | ||
3669 | 399 | worker->function_next= function->worker_list; | ||
3670 | 400 | worker->function_prev= function->worker_list->function_prev; | ||
3671 | 401 | worker->function_next->function_prev= worker; | ||
3672 | 402 | worker->function_prev->function_next= worker; | ||
3673 | 403 | } | ||
3674 | 404 | function->worker_count++; | ||
3675 | 405 | |||
3676 | 406 | return worker; | ||
3677 | 407 | } | ||
3678 | 408 | |||
3679 | 409 | gearman_server_worker_st * | ||
3680 | 410 | gearman_server_con_st::worker_add(const char *function_name_arg, size_t length, uint32_t timeout) | ||
3681 | 411 | { | ||
3682 | 412 | std::string function_name(function_name_arg, length); | ||
3683 | 413 | gearman_server_worker_st *worker; | ||
3684 | 414 | gearman_server_function_st *function; | ||
3685 | 415 | |||
3686 | 416 | if (function_name.empty()) | ||
3687 | 417 | return NULL; | ||
3688 | 418 | |||
3689 | 419 | function= thread->server->function_get(function_name); | ||
3690 | 420 | |||
3691 | 421 | if (function == NULL) | ||
3692 | 422 | return NULL; | ||
3693 | 423 | |||
3694 | 424 | worker= worker_create(function); | ||
3695 | 425 | if (worker == NULL) | ||
3696 | 426 | return NULL; | ||
3697 | 427 | |||
3698 | 428 | worker->set_timeout(timeout); | ||
3699 | 429 | |||
3700 | 430 | return worker; | ||
3701 | 431 | } | ||
3702 | 432 | |||
3703 | 433 | |||
3704 | 434 | gearman_server_job_st *gearman_server_con_st::job_peek() | ||
3705 | 435 | { | ||
3706 | 436 | gearman_server_worker_st *server_worker; | ||
3707 | 437 | |||
3708 | 438 | for (server_worker= worker_list; server_worker != NULL; | ||
3709 | 439 | server_worker= server_worker->con_next) | ||
3710 | 440 | { | ||
3711 | 441 | if (server_worker->function->job_count != 0) | ||
3712 | 442 | { | ||
3713 | 443 | for (uint32_t priority= GEARMAN_JOB_PRIORITY_HIGH; | ||
3714 | 444 | priority != GEARMAN_JOB_PRIORITY_MAX; priority++) | ||
3715 | 445 | { | ||
3716 | 446 | if (server_worker->function->job_list[priority] != NULL) | ||
3717 | 447 | { | ||
3718 | 448 | if (server_worker->function->job_list[priority]->ignore_job()) | ||
3719 | 449 | { | ||
3720 | 450 | /* This is only happens when a client disconnects from a foreground | ||
3721 | 451 | job. We do this because we don't want to run the job anymore. */ | ||
3722 | 452 | server_worker->function->job_list[priority]->set_ignore_job(false); | ||
3723 | 453 | |||
3724 | 454 | delete job_take(); | ||
3725 | 455 | |||
3726 | 456 | return job_peek(); | ||
3727 | 457 | } | ||
3728 | 458 | return server_worker->function->job_list[priority]; | ||
3729 | 459 | } | ||
3730 | 460 | } | ||
3731 | 461 | } | ||
3732 | 462 | } | ||
3733 | 463 | |||
3734 | 464 | return NULL; | ||
3735 | 465 | } | ||
3736 | 466 | |||
3737 | 467 | /** | ||
3738 | 468 | * Appends a worker onto the end of a list of workers. | ||
3739 | 469 | */ | ||
3740 | 470 | static inline void _server_con_worker_list_append(gearman_server_worker_st *list, | ||
3741 | 471 | gearman_server_worker_st *worker) | ||
3742 | 472 | { | ||
3743 | 473 | worker->con_prev= NULL; | ||
3744 | 474 | worker->con_next= list; | ||
3745 | 475 | while (worker->con_next != NULL) | ||
3746 | 476 | { | ||
3747 | 477 | worker->con_prev= worker->con_next; | ||
3748 | 478 | worker->con_next= worker->con_next->con_next; | ||
3749 | 479 | } | ||
3750 | 480 | if (worker->con_prev) | ||
3751 | 481 | worker->con_prev->con_next= worker; | ||
3752 | 482 | } | ||
3753 | 483 | |||
3754 | 484 | |||
3755 | 485 | gearman_server_job_st *gearman_server_con_st::job_take() | ||
3756 | 486 | { | ||
3757 | 487 | gearman_server_worker_st *server_worker; | ||
3758 | 488 | gearman_server_job_st *server_job; | ||
3759 | 489 | gearman_job_priority_t priority; | ||
3760 | 490 | |||
3761 | 491 | for (server_worker= worker_list; server_worker != NULL; | ||
3762 | 492 | server_worker= server_worker->con_next) | ||
3763 | 493 | { | ||
3764 | 494 | if (server_worker->function->job_count != 0) | ||
3765 | 495 | break; | ||
3766 | 496 | } | ||
3767 | 497 | |||
3768 | 498 | if (server_worker == NULL) | ||
3769 | 499 | return NULL; | ||
3770 | 500 | |||
3771 | 501 | if (thread->server->flags.round_robin) | ||
3772 | 502 | { | ||
3773 | 503 | GEARMAN_LIST_DEL(worker, server_worker, con_) | ||
3774 | 504 | _server_con_worker_list_append(worker_list, server_worker); | ||
3775 | 505 | ++worker_count; | ||
3776 | 506 | if (worker_list == NULL) | ||
3777 | 507 | { | ||
3778 | 508 | worker_list= server_worker; | ||
3779 | 509 | } | ||
3780 | 510 | } | ||
3781 | 511 | |||
3782 | 512 | uint32_t x; | ||
3783 | 513 | for (x= (uint32_t)GEARMAN_JOB_PRIORITY_HIGH; x != GEARMAN_JOB_PRIORITY_MAX; x++) | ||
3784 | 514 | { | ||
3785 | 515 | if (server_worker->function->job_list[x] != NULL) | ||
3786 | 516 | break; | ||
3787 | 517 | } | ||
3788 | 518 | priority= (gearman_job_priority_t)x; | ||
3789 | 519 | |||
3790 | 520 | server_job= server_worker->function->job_list[priority]; | ||
3791 | 521 | server_job->function->job_list[priority]= server_job->function_next; | ||
3792 | 522 | if (server_job->function->job_end[priority] == server_job) | ||
3793 | 523 | server_job->function->job_end[priority]= NULL; | ||
3794 | 524 | server_job->function->job_count--; | ||
3795 | 525 | |||
3796 | 526 | server_job->worker= server_worker; | ||
3797 | 527 | server_worker->add_job(server_job); | ||
3798 | 528 | server_job->function->job_running++; | ||
3799 | 529 | |||
3800 | 530 | if (server_job->ignore_job()) | ||
3801 | 531 | { | ||
3802 | 532 | delete server_job; | ||
3803 | 533 | return job_take(); | ||
3804 | 534 | } | ||
3805 | 535 | |||
3806 | 536 | return server_job; | ||
3807 | 537 | } | ||
3808 | 538 | |||
3809 | 539 | gearman_return_t gearman_server_con_st::_server_error_packet(const char *error_code, const char *error_string) | ||
3810 | 540 | { | ||
3811 | 541 | return io_packet_add(false, GEARMAN_MAGIC_RESPONSE, | ||
3812 | 542 | GEARMAN_COMMAND_ERROR, error_code, | ||
3813 | 543 | (size_t)(strlen(error_code) + 1), | ||
3814 | 544 | error_string, | ||
3815 | 545 | (size_t)strlen(error_string), NULL); | ||
3816 | 546 | } | ||
3817 | 547 | |||
3818 | 548 | |||
3819 | 549 | gearman_return_t gearman_server_con_st::_thread_packet_read() | ||
3820 | 550 | { | ||
3821 | 551 | gearman_return_t rc; | ||
3822 | 552 | gearman_server_con_st *con_this= this; | ||
3823 | 553 | |||
3824 | 554 | while (1) | ||
3825 | 555 | { | ||
3826 | 556 | if (con_this->packet == NULL) | ||
3827 | 557 | { | ||
3828 | 558 | con_this->packet= new gearman_server_packet_st; | ||
3829 | 559 | if (con_this->packet == NULL) | ||
3830 | 560 | return GEARMAN_MEMORY_ALLOCATION_FAILURE; | ||
3831 | 561 | } | ||
3832 | 562 | |||
3833 | 563 | (void)gearman_connection_recv(con_this->con(), &(con_this->packet->packet), &rc, true); | ||
3834 | 564 | if (rc != GEARMAN_SUCCESS) | ||
3835 | 565 | { | ||
3836 | 566 | if (rc == GEARMAN_IO_WAIT) | ||
3837 | 567 | break; | ||
3838 | 568 | |||
3839 | 569 | delete con_this->packet; | ||
3840 | 570 | con_this->packet= NULL; | ||
3841 | 571 | return rc; | ||
3842 | 572 | } | ||
3843 | 573 | |||
3844 | 574 | Log::Instance()->debug("%15s:%5s Received %s", | ||
3845 | 575 | con_this->_host == NULL ? "-" : con_this->_host, | ||
3846 | 576 | con_this->_port == NULL ? "-" : con_this->_port, | ||
3847 | 577 | gearman_command_info_list[con_this->packet->packet.command].name); | ||
3848 | 578 | |||
3849 | 579 | /* We read a complete packet. */ | ||
3850 | 580 | if (con_this->thread->server->flags.threaded) | ||
3851 | 581 | { | ||
3852 | 582 | /* Multi-threaded, queue for the processing thread to run. */ | ||
3853 | 583 | con_this->gearman_server_proc_packet_add(con_this->packet); | ||
3854 | 584 | con_this->packet= NULL; | ||
3855 | 585 | } | ||
3856 | 586 | else | ||
3857 | 587 | { | ||
3858 | 588 | /* Single threaded, run the command here. */ | ||
3859 | 589 | rc= gearman_server_run_command(con_this, &(con_this->packet->packet)); | ||
3860 | 590 | delete con_this->packet; | ||
3861 | 591 | con_this->packet= NULL; | ||
3862 | 592 | if (rc != GEARMAN_SUCCESS) | ||
3863 | 593 | return rc; | ||
3864 | 594 | } | ||
3865 | 595 | } | ||
3866 | 596 | |||
3867 | 597 | return GEARMAN_SUCCESS; | ||
3868 | 598 | } | ||
3869 | 599 | |||
3870 | 600 | gearman_return_t gearman_server_con_st::io_packet_add(bool take_data, | ||
3871 | 601 | enum gearman_magic_t magic, | ||
3872 | 602 | gearman_command_t command, | ||
3873 | 603 | const void *arg, ...) | ||
3874 | 604 | { | ||
3875 | 605 | gearman_server_packet_st *server_packet; | ||
3876 | 606 | va_list ap; | ||
3877 | 607 | size_t arg_size; | ||
3878 | 608 | gearman_return_t rc; | ||
3879 | 609 | |||
3880 | 610 | server_packet= new gearman_server_packet_st(thread->gearman, magic, command); | ||
3881 | 611 | if (server_packet == NULL) | ||
3882 | 612 | return GEARMAN_MEMORY_ALLOCATION_FAILURE; | ||
3883 | 613 | |||
3884 | 614 | va_start(ap, arg); | ||
3885 | 615 | |||
3886 | 616 | while (arg != NULL) | ||
3887 | 617 | { | ||
3888 | 618 | arg_size = va_arg(ap, size_t); | ||
3889 | 619 | |||
3890 | 620 | rc= gearman_packet_create_arg(&(server_packet->packet), arg, arg_size); | ||
3891 | 621 | if (rc != GEARMAN_SUCCESS) | ||
3892 | 622 | { | ||
3893 | 623 | va_end(ap); | ||
3894 | 624 | delete server_packet; | ||
3895 | 625 | |||
3896 | 626 | return rc; | ||
3897 | 627 | } | ||
3898 | 628 | |||
3899 | 629 | arg = va_arg(ap, void *); | ||
3900 | 630 | } | ||
3901 | 631 | |||
3902 | 632 | va_end(ap); | ||
3903 | 633 | |||
3904 | 634 | rc= gearman_packet_pack_header(&(server_packet->packet)); | ||
3905 | 635 | if (rc != GEARMAN_SUCCESS) | ||
3906 | 636 | { | ||
3907 | 637 | delete server_packet; | ||
3908 | 638 | |||
3909 | 639 | return rc; | ||
3910 | 640 | } | ||
3911 | 641 | |||
3912 | 642 | if (take_data) | ||
3913 | 643 | { | ||
3914 | 644 | server_packet->packet.options.free_data= true; | ||
3915 | 645 | } | ||
3916 | 646 | |||
3917 | 647 | { | ||
3918 | 648 | boost::mutex::scoped_lock l(thread->lock); | ||
3919 | 649 | io_packet_list.push(server_packet); | ||
3920 | 650 | } | ||
3921 | 651 | |||
3922 | 652 | io_add(); | ||
3923 | 653 | |||
3924 | 654 | return GEARMAN_SUCCESS; | ||
3925 | 655 | } | ||
3926 | 656 | |||
3927 | 657 | void gearman_server_con_st::io_packet_remove() | ||
3928 | 658 | { | ||
3929 | 659 | gearman_server_packet_st *server_packet; | ||
3930 | 660 | { | ||
3931 | 661 | boost::mutex::scoped_lock l(thread->lock); | ||
3932 | 662 | server_packet= io_packet_list.front(); | ||
3933 | 663 | io_packet_list.pop(); | ||
3934 | 664 | assert(server_packet); | ||
3935 | 665 | } | ||
3936 | 666 | |||
3937 | 667 | delete server_packet; | ||
3938 | 668 | } | ||
3939 | 669 | |||
3940 | 670 | void gearman_server_con_st::gearman_server_proc_packet_add(gearman_server_packet_st *arg) | ||
3941 | 671 | { | ||
3942 | 672 | { | ||
3943 | 673 | boost::mutex::scoped_lock l(thread->lock); | ||
3944 | 674 | proc_packet_list.push(arg); | ||
3945 | 675 | } | ||
3946 | 676 | |||
3947 | 677 | proc_add(); | ||
3948 | 678 | } | ||
3949 | 679 | |||
3950 | 680 | gearman_server_packet_st *gearman_server_con_st::proc_packet_remove() | ||
3951 | 681 | { | ||
3952 | 682 | if (proc_packet_list.size() == 0) | ||
3953 | 683 | return NULL; | ||
3954 | 684 | |||
3955 | 685 | gearman_server_packet_st *server_packet; | ||
3956 | 686 | { | ||
3957 | 687 | boost::mutex::scoped_lock l(thread->lock); | ||
3958 | 688 | server_packet= proc_packet_list.front(); | ||
3959 | 689 | proc_packet_list.pop(); | ||
3960 | 690 | assert(server_packet); | ||
3961 | 691 | } | ||
3962 | 692 | |||
3963 | 693 | return server_packet; | ||
3964 | 357 | } | 694 | } |
3965 | 358 | 695 | ||
3966 | === modified file 'libgearman-server/connection.h' | |||
3967 | --- libgearman-server/connection.h 2010-04-06 16:34:30 +0000 | |||
3968 | +++ libgearman-server/connection.h 2010-07-01 01:31:26 +0000 | |||
3969 | @@ -1,4 +1,5 @@ | |||
3970 | 1 | /* Gearman server and library | 1 | /* Gearman server and library |
3971 | 2 | * Copyright (C) 2010 Data Differential | ||
3972 | 2 | * Copyright (C) 2008 Brian Aker, Eric Day | 3 | * Copyright (C) 2008 Brian Aker, Eric Day |
3973 | 3 | * All rights reserved. | 4 | * All rights reserved. |
3974 | 4 | * | 5 | * |
3975 | @@ -14,9 +15,7 @@ | |||
3976 | 14 | #ifndef __GEARMAN_SERVER_CON_H__ | 15 | #ifndef __GEARMAN_SERVER_CON_H__ |
3977 | 15 | #define __GEARMAN_SERVER_CON_H__ | 16 | #define __GEARMAN_SERVER_CON_H__ |
3978 | 16 | 17 | ||
3982 | 17 | #ifdef __cplusplus | 18 | #include <queue> |
3980 | 18 | extern "C" { | ||
3981 | 19 | #endif | ||
3983 | 20 | 19 | ||
3984 | 21 | /** | 20 | /** |
3985 | 22 | * @addtogroup gearman_server_con Connection Declarations | 21 | * @addtogroup gearman_server_con Connection Declarations |
3986 | @@ -28,9 +27,11 @@ | |||
3987 | 28 | * @{ | 27 | * @{ |
3988 | 29 | */ | 28 | */ |
3989 | 30 | 29 | ||
3990 | 30 | typedef std::queue<gearman_server_packet_st *> ProcPacketList; | ||
3991 | 31 | |||
3992 | 31 | struct gearman_server_con_st | 32 | struct gearman_server_con_st |
3993 | 32 | { | 33 | { |
3995 | 33 | gearman_connection_st con; /* This must be the first struct member. */ | 34 | gearman_connection_st _con; /* This must be the first struct member. */ |
3996 | 34 | bool is_sleeping; | 35 | bool is_sleeping; |
3997 | 35 | bool is_exceptions; | 36 | bool is_exceptions; |
3998 | 36 | bool is_dead; | 37 | bool is_dead; |
3999 | @@ -39,166 +40,158 @@ | |||
4000 | 39 | bool io_list; | 40 | bool io_list; |
4001 | 40 | bool proc_list; | 41 | bool proc_list; |
4002 | 41 | bool proc_removed; | 42 | bool proc_removed; |
4003 | 42 | uint32_t io_packet_count; | ||
4004 | 43 | uint32_t proc_packet_count; | ||
4005 | 44 | uint32_t worker_count; | 43 | uint32_t worker_count; |
4006 | 45 | uint32_t client_count; | 44 | uint32_t client_count; |
4007 | 46 | gearman_server_thread_st *thread; | 45 | gearman_server_thread_st *thread; |
4008 | 47 | gearman_server_con_st *next; | ||
4009 | 48 | gearman_server_con_st *prev; | ||
4010 | 49 | gearman_server_packet_st *packet; | 46 | gearman_server_packet_st *packet; |
4015 | 50 | gearman_server_packet_st *io_packet_list; | 47 | ProcPacketList io_packet_list; |
4016 | 51 | gearman_server_packet_st *io_packet_end; | 48 | ProcPacketList proc_packet_list; |
4013 | 52 | gearman_server_packet_st *proc_packet_list; | ||
4014 | 53 | gearman_server_packet_st *proc_packet_end; | ||
4017 | 54 | gearman_server_con_st *io_next; | 49 | gearman_server_con_st *io_next; |
4018 | 55 | gearman_server_con_st *io_prev; | 50 | gearman_server_con_st *io_prev; |
4019 | 56 | gearman_server_con_st *proc_next; | 51 | gearman_server_con_st *proc_next; |
4020 | 57 | gearman_server_con_st *proc_prev; | 52 | gearman_server_con_st *proc_prev; |
4021 | 58 | gearman_server_worker_st *worker_list; | 53 | gearman_server_worker_st *worker_list; |
4022 | 59 | gearman_server_client_st *client_list; | 54 | gearman_server_client_st *client_list; |
4026 | 60 | const char *host; | 55 | const char *_host; |
4027 | 61 | const char *port; | 56 | const char *_port; |
4028 | 62 | char id[GEARMAN_SERVER_CON_ID_SIZE]; | 57 | char _id[GEARMAN_SERVER_CON_ID_SIZE]; |
4029 | 58 | |||
4030 | 59 | gearman_server_con_st(gearman_server_thread_st *thread_arg); | ||
4031 | 60 | ~gearman_server_con_st(); | ||
4032 | 61 | |||
4033 | 62 | void free_workers(); | ||
4034 | 63 | public: | ||
4035 | 64 | gearman_server_client_st *client_create(); | ||
4036 | 65 | gearman_server_client_st *client_add(); | ||
4037 | 66 | |||
4038 | 67 | gearman_return_t _server_run_text(gearman_packet_st *packet); | ||
4039 | 68 | |||
4040 | 69 | /** | ||
4041 | 70 | * Remove connection from the io thread list. | ||
4042 | 71 | */ | ||
4043 | 72 | void io_remove(); | ||
4044 | 73 | |||
4045 | 74 | /** | ||
4046 | 75 | * Add connection to the proc thread list. | ||
4047 | 76 | */ | ||
4048 | 77 | void proc_add(); | ||
4049 | 78 | |||
4050 | 79 | gearman_server_packet_st *proc_packet_remove(); | ||
4051 | 80 | |||
4052 | 81 | /** | ||
4053 | 82 | * Remove the first server packet structure from io queue for a connection. | ||
4054 | 83 | */ | ||
4055 | 84 | void io_packet_remove(); | ||
4056 | 85 | |||
4057 | 86 | /** | ||
4058 | 87 | * Remove connection from the proc thread list. | ||
4059 | 88 | */ | ||
4060 | 89 | void proc_remove(); | ||
4061 | 90 | |||
4062 | 91 | /** | ||
4063 | 92 | * Get gearman connection pointer the server connection uses. | ||
4064 | 93 | */ | ||
4065 | 94 | gearman_connection_st *con() | ||
4066 | 95 | { | ||
4067 | 96 | return &_con; | ||
4068 | 97 | } | ||
4069 | 98 | |||
4070 | 99 | /** | ||
4071 | 100 | * Set client id. | ||
4072 | 101 | */ | ||
4073 | 102 | void set_id(char *id_arg, size_t size); | ||
4074 | 103 | |||
4075 | 104 | /** | ||
4076 | 105 | * Set client port. | ||
4077 | 106 | */ | ||
4078 | 107 | void set_port(const char *port); | ||
4079 | 108 | |||
4080 | 109 | /** | ||
4081 | 110 | * Set client host. | ||
4082 | 111 | */ | ||
4083 | 112 | void set_host(const char *host_arg); | ||
4084 | 113 | |||
4085 | 114 | /** | ||
4086 | 115 | * Get client host. | ||
4087 | 116 | */ | ||
4088 | 117 | const char *host() | ||
4089 | 118 | { | ||
4090 | 119 | return _host; | ||
4091 | 120 | } | ||
4092 | 121 | |||
4093 | 122 | /** | ||
4094 | 123 | * Get client port. | ||
4095 | 124 | */ | ||
4096 | 125 | const char *port() | ||
4097 | 126 | { | ||
4098 | 127 | return _port; | ||
4099 | 128 | } | ||
4100 | 129 | |||
4101 | 130 | /** | ||
4102 | 131 | * Get client id. | ||
4103 | 132 | */ | ||
4104 | 133 | const char *id() | ||
4105 | 134 | { | ||
4106 | 135 | return _id; | ||
4107 | 136 | } | ||
4108 | 137 | |||
4109 | 138 | /** | ||
4110 | 139 | * Get application data pointer. | ||
4111 | 140 | */ | ||
4112 | 141 | const void *data(); | ||
4113 | 142 | |||
4114 | 143 | /** | ||
4115 | 144 | * Add connection to the io thread list. | ||
4116 | 145 | */ | ||
4117 | 146 | void io_add(); | ||
4118 | 147 | |||
4119 | 148 | /** | ||
4120 | 149 | * Free server worker struction with name for a server connection. | ||
4121 | 150 | */ | ||
4122 | 151 | void free_worker(const char *function_name_arg, | ||
4123 | 152 | size_t function_name_size_arg); | ||
4124 | 153 | |||
4125 | 154 | /** | ||
4126 | 155 | * Add a server packet structure to io queue for a connection. | ||
4127 | 156 | */ | ||
4128 | 157 | gearman_return_t io_packet_add(bool take_data, | ||
4129 | 158 | enum gearman_magic_t magic, | ||
4130 | 159 | gearman_command_t command, | ||
4131 | 160 | const void *arg, ...); | ||
4132 | 161 | |||
4133 | 162 | /** | ||
4134 | 163 | * Add a new worker to a server instance. | ||
4135 | 164 | */ | ||
4136 | 165 | gearman_server_worker_st * | ||
4137 | 166 | worker_add(const char *function_name, size_t function_name_size, uint32_t timeout); | ||
4138 | 167 | |||
4139 | 168 | gearman_server_worker_st * | ||
4140 | 169 | worker_create(gearman_server_function_st *function); | ||
4141 | 170 | |||
4142 | 171 | /** | ||
4143 | 172 | * See if there are any jobs to be run for the server worker connection. | ||
4144 | 173 | */ | ||
4145 | 174 | gearman_server_job_st *job_peek(); | ||
4146 | 175 | |||
4147 | 176 | /** | ||
4148 | 177 | * Start running a job for the server worker connection. | ||
4149 | 178 | */ | ||
4150 | 179 | gearman_server_job_st *job_take(); | ||
4151 | 180 | |||
4152 | 181 | gearman_return_t _thread_packet_read(); | ||
4153 | 182 | |||
4154 | 183 | /** | ||
4155 | 184 | * Remove the first server packet structure from proc queue for a connection. | ||
4156 | 185 | */ | ||
4157 | 186 | |||
4158 | 187 | gearman_return_t _server_error_packet(const char *error_code, const char *error_string); | ||
4159 | 188 | |||
4160 | 189 | /** | ||
4161 | 190 | * Add a server packet structure to proc queue for a connection. | ||
4162 | 191 | */ | ||
4163 | 192 | void gearman_server_proc_packet_add(gearman_server_packet_st *packet); | ||
4164 | 63 | }; | 193 | }; |
4165 | 64 | 194 | ||
4166 | 65 | /** | ||
4167 | 66 | * Add a connection to a server thread. This goes into a list of connections | ||
4168 | 67 | * that is used later with server_thread_run, no socket I/O happens here. | ||
4169 | 68 | * @param thread Thread structure previously initialized with | ||
4170 | 69 | * gearman_server_thread_create. | ||
4171 | 70 | * @param fd File descriptor for a newly accepted connection. | ||
4172 | 71 | * @param data Application data pointer. | ||
4173 | 72 | * @return Gearman server connection pointer. | ||
4174 | 73 | */ | ||
4175 | 74 | GEARMAN_API | ||
4176 | 75 | gearman_server_con_st *gearman_server_con_add(gearman_server_thread_st *thread, | ||
4177 | 76 | int fd, void *data); | ||
4178 | 77 | |||
4179 | 78 | /** | ||
4180 | 79 | * Initialize a server connection structure. | ||
4181 | 80 | */ | ||
4182 | 81 | GEARMAN_API | ||
4183 | 82 | gearman_server_con_st * | ||
4184 | 83 | gearman_server_con_create(gearman_server_thread_st *thread); | ||
4185 | 84 | |||
4186 | 85 | /** | ||
4187 | 86 | * Free a server connection structure. | ||
4188 | 87 | */ | ||
4189 | 88 | GEARMAN_API | ||
4190 | 89 | void gearman_server_con_free(gearman_server_con_st *con); | ||
4191 | 90 | |||
4192 | 91 | /** | ||
4193 | 92 | * Get gearman connection pointer the server connection uses. | ||
4194 | 93 | */ | ||
4195 | 94 | GEARMAN_API | ||
4196 | 95 | gearman_connection_st *gearman_server_con_con(gearman_server_con_st *con); | ||
4197 | 96 | |||
4198 | 97 | /** | ||
4199 | 98 | * Get application data pointer. | ||
4200 | 99 | */ | ||
4201 | 100 | GEARMAN_API | ||
4202 | 101 | const void *gearman_server_con_data(const gearman_server_con_st *con); | ||
4203 | 102 | |||
4204 | 103 | /** | ||
4205 | 104 | * Set application data pointer. | ||
4206 | 105 | */ | ||
4207 | 106 | GEARMAN_API | ||
4208 | 107 | void gearman_server_con_set_data(gearman_server_con_st *con, void *data); | ||
4209 | 108 | |||
4210 | 109 | /** | ||
4211 | 110 | * Get client host. | ||
4212 | 111 | */ | ||
4213 | 112 | GEARMAN_API | ||
4214 | 113 | const char *gearman_server_con_host(gearman_server_con_st *con); | ||
4215 | 114 | |||
4216 | 115 | /** | ||
4217 | 116 | * Set client host. | ||
4218 | 117 | */ | ||
4219 | 118 | GEARMAN_API | ||
4220 | 119 | void gearman_server_con_set_host(gearman_server_con_st *con, const char *host); | ||
4221 | 120 | |||
4222 | 121 | /** | ||
4223 | 122 | * Get client port. | ||
4224 | 123 | */ | ||
4225 | 124 | GEARMAN_API | ||
4226 | 125 | const char *gearman_server_con_port(gearman_server_con_st *con); | ||
4227 | 126 | |||
4228 | 127 | /** | ||
4229 | 128 | * Set client port. | ||
4230 | 129 | */ | ||
4231 | 130 | GEARMAN_API | ||
4232 | 131 | void gearman_server_con_set_port(gearman_server_con_st *con, const char *port); | ||
4233 | 132 | |||
4234 | 133 | /** | ||
4235 | 134 | * Get client id. | ||
4236 | 135 | */ | ||
4237 | 136 | GEARMAN_API | ||
4238 | 137 | const char *gearman_server_con_id(gearman_server_con_st *con); | ||
4239 | 138 | |||
4240 | 139 | /** | ||
4241 | 140 | * Set client id. | ||
4242 | 141 | */ | ||
4243 | 142 | GEARMAN_API | ||
4244 | 143 | void gearman_server_con_set_id(gearman_server_con_st *con, char *id, | ||
4245 | 144 | size_t size); | ||
4246 | 145 | |||
4247 | 146 | /** | ||
4248 | 147 | * Free server worker struction with name for a server connection. | ||
4249 | 148 | */ | ||
4250 | 149 | GEARMAN_API | ||
4251 | 150 | void gearman_server_con_free_worker(gearman_server_con_st *con, | ||
4252 | 151 | char *function_name, | ||
4253 | 152 | size_t function_name_size); | ||
4254 | 153 | |||
4255 | 154 | /** | ||
4256 | 155 | * Free all server worker structures for a server connection. | ||
4257 | 156 | */ | ||
4258 | 157 | GEARMAN_API | ||
4259 | 158 | void gearman_server_con_free_workers(gearman_server_con_st *con); | ||
4260 | 159 | |||
4261 | 160 | /** | ||
4262 | 161 | * Add connection to the io thread list. | ||
4263 | 162 | */ | ||
4264 | 163 | GEARMAN_API | ||
4265 | 164 | void gearman_server_con_io_add(gearman_server_con_st *con); | ||
4266 | 165 | |||
4267 | 166 | /** | ||
4268 | 167 | * Remove connection from the io thread list. | ||
4269 | 168 | */ | ||
4270 | 169 | GEARMAN_API | ||
4271 | 170 | void gearman_server_con_io_remove(gearman_server_con_st *con); | ||
4272 | 171 | |||
4273 | 172 | /** | ||
4274 | 173 | * Get next connection from the io thread list. | ||
4275 | 174 | */ | ||
4276 | 175 | GEARMAN_API | ||
4277 | 176 | gearman_server_con_st * | ||
4278 | 177 | gearman_server_con_io_next(gearman_server_thread_st *thread); | ||
4279 | 178 | |||
4280 | 179 | /** | ||
4281 | 180 | * Add connection to the proc thread list. | ||
4282 | 181 | */ | ||
4283 | 182 | GEARMAN_API | ||
4284 | 183 | void gearman_server_con_proc_add(gearman_server_con_st *con); | ||
4285 | 184 | |||
4286 | 185 | /** | ||
4287 | 186 | * Remove connection from the proc thread list. | ||
4288 | 187 | */ | ||
4289 | 188 | GEARMAN_API | ||
4290 | 189 | void gearman_server_con_proc_remove(gearman_server_con_st *con); | ||
4291 | 190 | |||
4292 | 191 | /** | ||
4293 | 192 | * Get next connection from the proc thread list. | ||
4294 | 193 | */ | ||
4295 | 194 | GEARMAN_API | ||
4296 | 195 | gearman_server_con_st * | ||
4297 | 196 | gearman_server_con_proc_next(gearman_server_thread_st *thread); | ||
4298 | 197 | |||
4299 | 198 | /** @} */ | 195 | /** @} */ |
4300 | 199 | 196 | ||
4301 | 200 | #ifdef __cplusplus | ||
4302 | 201 | } | ||
4303 | 202 | #endif | ||
4304 | 203 | |||
4305 | 204 | #endif /* __GEARMAN_SERVER_CON_H__ */ | 197 | #endif /* __GEARMAN_SERVER_CON_H__ */ |
4306 | 205 | 198 | ||
4307 | === modified file 'libgearman-server/constants.h' | |||
4308 | --- libgearman-server/constants.h 2010-04-06 19:40:28 +0000 | |||
4309 | +++ libgearman-server/constants.h 2010-07-01 01:31:26 +0000 | |||
4310 | @@ -1,4 +1,5 @@ | |||
4311 | 1 | /* Gearman server and library | 1 | /* Gearman server and library |
4312 | 2 | * Copyright (C) 2010 Data Differential | ||
4313 | 2 | * Copyright (C) 2008 Brian Aker, Eric Day | 3 | * Copyright (C) 2008 Brian Aker, Eric Day |
4314 | 3 | * All rights reserved. | 4 | * All rights reserved. |
4315 | 4 | * | 5 | * |
4316 | @@ -14,10 +15,6 @@ | |||
4317 | 14 | #ifndef __GEARMAN_SERVER_CONSTANTS_H__ | 15 | #ifndef __GEARMAN_SERVER_CONSTANTS_H__ |
4318 | 15 | #define __GEARMAN_SERVER_CONSTANTS_H__ | 16 | #define __GEARMAN_SERVER_CONSTANTS_H__ |
4319 | 16 | 17 | ||
4320 | 17 | #ifdef __cplusplus | ||
4321 | 18 | extern "C" { | ||
4322 | 19 | #endif | ||
4323 | 20 | |||
4324 | 21 | /** | 18 | /** |
4325 | 22 | * @addtogroup gearman_server_constants Constants | 19 | * @addtogroup gearman_server_constants Constants |
4326 | 23 | * @ingroup gearman_server | 20 | * @ingroup gearman_server |
4327 | @@ -70,13 +67,13 @@ | |||
4328 | 70 | typedef struct gearman_server_client_st gearman_server_client_st; | 67 | typedef struct gearman_server_client_st gearman_server_client_st; |
4329 | 71 | typedef struct gearman_server_worker_st gearman_server_worker_st; | 68 | typedef struct gearman_server_worker_st gearman_server_worker_st; |
4330 | 72 | typedef struct gearman_server_job_st gearman_server_job_st; | 69 | typedef struct gearman_server_job_st gearman_server_job_st; |
4331 | 73 | typedef struct gearmand_st gearmand_st; | ||
4332 | 74 | typedef struct gearmand_port_st gearmand_port_st; | 70 | typedef struct gearmand_port_st gearmand_port_st; |
4333 | 75 | typedef struct gearmand_con_st gearmand_con_st; | 71 | typedef struct gearmand_con_st gearmand_con_st; |
4334 | 76 | typedef struct gearmand_thread_st gearmand_thread_st; | 72 | typedef struct gearmand_thread_st gearmand_thread_st; |
4335 | 77 | typedef struct gearman_conf_st gearman_conf_st; | 73 | typedef struct gearman_conf_st gearman_conf_st; |
4336 | 78 | typedef struct gearman_conf_option_st gearman_conf_option_st; | 74 | typedef struct gearman_conf_option_st gearman_conf_option_st; |
4337 | 79 | typedef struct gearman_conf_module_st gearman_conf_module_st; | 75 | typedef struct gearman_conf_module_st gearman_conf_module_st; |
4338 | 76 | struct gearmand_st; | ||
4339 | 80 | 77 | ||
4340 | 81 | /* Function types. */ | 78 | /* Function types. */ |
4341 | 82 | typedef void (gearman_server_thread_run_fn)(gearman_server_thread_st *thread, | 79 | typedef void (gearman_server_thread_run_fn)(gearman_server_thread_st *thread, |
4342 | @@ -91,35 +88,9 @@ | |||
4343 | 91 | const void *data, | 88 | const void *data, |
4344 | 92 | size_t data_size, | 89 | size_t data_size, |
4345 | 93 | gearman_job_priority_t priority); | 90 | gearman_job_priority_t priority); |
4346 | 94 | typedef gearman_return_t (gearman_queue_flush_fn)(gearman_server_st *server, | ||
4347 | 95 | void *context); | ||
4348 | 96 | typedef gearman_return_t (gearman_queue_done_fn)(gearman_server_st *server, | ||
4349 | 97 | void *context, | ||
4350 | 98 | const void *unique, | ||
4351 | 99 | size_t unique_size, | ||
4352 | 100 | const void *function_name, | ||
4353 | 101 | size_t function_name_size); | ||
4354 | 102 | typedef gearman_return_t (gearman_queue_replay_fn)(gearman_server_st *server, | ||
4355 | 103 | void *context, | ||
4356 | 104 | gearman_queue_add_fn *add_fn, | ||
4357 | 105 | void *add_context); | ||
4358 | 106 | 91 | ||
4359 | 107 | typedef gearman_return_t (gearman_connection_add_fn)(gearman_connection_st *con); | 92 | typedef gearman_return_t (gearman_connection_add_fn)(gearman_connection_st *con); |
4360 | 108 | 93 | ||
4361 | 109 | /** @} */ | 94 | /** @} */ |
4362 | 110 | 95 | ||
4363 | 111 | /** | ||
4364 | 112 | * @addtogroup gearman_server_protocol Protocol Plugins | ||
4365 | 113 | * @ingroup gearman_server | ||
4366 | 114 | */ | ||
4367 | 115 | |||
4368 | 116 | /** | ||
4369 | 117 | * @addtogroup gearman_server_queue Queue Plugins | ||
4370 | 118 | * @ingroup gearman_server | ||
4371 | 119 | */ | ||
4372 | 120 | |||
4373 | 121 | #ifdef __cplusplus | ||
4374 | 122 | } | ||
4375 | 123 | #endif | ||
4376 | 124 | |||
4377 | 125 | #endif /* __GEARMAN_SERVER_CONSTANTS_H__ */ | 96 | #endif /* __GEARMAN_SERVER_CONSTANTS_H__ */ |
4378 | 126 | 97 | ||
4379 | === renamed file 'libgearman-server/function.c' => 'libgearman-server/function.cc' | |||
4380 | --- libgearman-server/function.c 2010-04-06 21:41:46 +0000 | |||
4381 | +++ libgearman-server/function.cc 2010-07-01 01:31:26 +0000 | |||
4382 | @@ -1,4 +1,5 @@ | |||
4383 | 1 | /* Gearman server and library | 1 | /* Gearman server and library |
4384 | 2 | * Copyright (C) 2010 Data Differential | ||
4385 | 2 | * Copyright (C) 2008 Brian Aker, Eric Day | 3 | * Copyright (C) 2008 Brian Aker, Eric Day |
4386 | 3 | * All rights reserved. | 4 | * All rights reserved. |
4387 | 4 | * | 5 | * |
4388 | @@ -11,33 +12,55 @@ | |||
4389 | 11 | * @brief Server function definitions | 12 | * @brief Server function definitions |
4390 | 12 | */ | 13 | */ |
4391 | 13 | 14 | ||
4393 | 14 | #include "common.h" | 15 | #include "libgearman-server/common.h" |
4394 | 15 | 16 | ||
4395 | 16 | /* | 17 | /* |
4396 | 17 | * Public definitions | 18 | * Public definitions |
4397 | 18 | */ | 19 | */ |
4398 | 19 | 20 | ||
4399 | 21 | gearman_server_function_st::gearman_server_function_st(gearman_server_st *server_arg, | ||
4400 | 22 | const std::string &function_name_arg) : | ||
4401 | 23 | worker_count(0), | ||
4402 | 24 | job_count(0), | ||
4403 | 25 | job_total(0), | ||
4404 | 26 | job_running(0), | ||
4405 | 27 | max_queue_size(GEARMAN_DEFAULT_MAX_QUEUE_SIZE), | ||
4406 | 28 | server(server_arg), | ||
4407 | 29 | next(NULL), | ||
4408 | 30 | prev(NULL), | ||
4409 | 31 | function_name(function_name_arg), | ||
4410 | 32 | worker_list(NULL) | ||
4411 | 33 | { | ||
4412 | 34 | memset(job_list, 0, sizeof(gearman_server_job_st *) * GEARMAN_JOB_PRIORITY_MAX); | ||
4413 | 35 | memset(job_end, 0, sizeof(gearman_server_job_st *) * GEARMAN_JOB_PRIORITY_MAX); | ||
4414 | 36 | } | ||
4415 | 37 | |||
4416 | 38 | gearman_server_function_st::~gearman_server_function_st() | ||
4417 | 39 | { | ||
4418 | 40 | } | ||
4419 | 41 | |||
4420 | 20 | gearman_server_function_st * | 42 | gearman_server_function_st * |
4424 | 21 | gearman_server_function_get(gearman_server_st *server, | 43 | gearman_server_st::function_get(const std::string &function_name_arg) |
4422 | 22 | const char *function_name, | ||
4423 | 23 | size_t function_name_size) | ||
4425 | 24 | { | 44 | { |
4426 | 25 | gearman_server_function_st *function; | 45 | gearman_server_function_st *function; |
4427 | 26 | 46 | ||
4429 | 27 | for (function= server->function_list; function != NULL; | 47 | if (function_name_arg.empty()) |
4430 | 48 | return NULL; | ||
4431 | 49 | |||
4432 | 50 | for (function= function_list; function != NULL; | ||
4433 | 28 | function= function->next) | 51 | function= function->next) |
4434 | 29 | { | 52 | { |
4437 | 30 | if (function->function_name_size == function_name_size && | 53 | if (not function->function_name.compare(function_name_arg)) |
4436 | 31 | !memcmp(function->function_name, function_name, function_name_size)) | ||
4438 | 32 | { | 54 | { |
4439 | 33 | return function; | 55 | return function; |
4440 | 34 | } | 56 | } |
4441 | 35 | } | 57 | } |
4442 | 36 | 58 | ||
4444 | 37 | function= gearman_server_function_create(server, NULL); | 59 | function= gearman_server_function_create(this, function_name_arg); |
4445 | 38 | if (function == NULL) | 60 | if (function == NULL) |
4446 | 39 | return NULL; | 61 | return NULL; |
4447 | 40 | 62 | ||
4448 | 63 | <<<<<<< TREE | ||
4449 | 41 | function->function_name= (char *)malloc(function_name_size + 1); | 64 | function->function_name= (char *)malloc(function_name_size + 1); |
4450 | 42 | if (function->function_name == NULL) | 65 | if (function->function_name == NULL) |
4451 | 43 | { | 66 | { |
4452 | @@ -49,13 +72,15 @@ | |||
4453 | 49 | function->function_name[function_name_size]= 0; | 72 | function->function_name[function_name_size]= 0; |
4454 | 50 | function->function_name_size= function_name_size; | 73 | function->function_name_size= function_name_size; |
4455 | 51 | 74 | ||
4456 | 75 | ======= | ||
4457 | 76 | >>>>>>> MERGE-SOURCE | ||
4458 | 52 | return function; | 77 | return function; |
4459 | 53 | } | 78 | } |
4460 | 54 | 79 | ||
4464 | 55 | gearman_server_function_st * | 80 | gearman_server_function_st *gearman_server_function_create(gearman_server_st *server, |
4465 | 56 | gearman_server_function_create(gearman_server_st *server, | 81 | const std::string &function_name) |
4463 | 57 | gearman_server_function_st *function) | ||
4466 | 58 | { | 82 | { |
4467 | 83 | <<<<<<< TREE | ||
4468 | 59 | if (function == NULL) | 84 | if (function == NULL) |
4469 | 60 | { | 85 | { |
4470 | 61 | function= (gearman_server_function_st *)malloc(sizeof(gearman_server_function_st)); | 86 | function= (gearman_server_function_st *)malloc(sizeof(gearman_server_function_st)); |
4471 | @@ -76,24 +101,20 @@ | |||
4472 | 76 | function->max_queue_size= GEARMAN_DEFAULT_MAX_QUEUE_SIZE; | 101 | function->max_queue_size= GEARMAN_DEFAULT_MAX_QUEUE_SIZE; |
4473 | 77 | function->function_name_size= 0; | 102 | function->function_name_size= 0; |
4474 | 78 | function->server= server; | 103 | function->server= server; |
4475 | 104 | ======= | ||
4476 | 105 | gearman_server_function_st *function; | ||
4477 | 106 | |||
4478 | 107 | function= new gearman_server_function_st(server, function_name); | ||
4479 | 108 | |||
4480 | 109 | >>>>>>> MERGE-SOURCE | ||
4481 | 79 | GEARMAN_LIST_ADD(server->function, function,) | 110 | GEARMAN_LIST_ADD(server->function, function,) |
4482 | 80 | function->function_name= NULL; | ||
4483 | 81 | function->worker_list= NULL; | ||
4484 | 82 | memset(function->job_list, 0, | ||
4485 | 83 | sizeof(gearman_server_job_st *) * GEARMAN_JOB_PRIORITY_MAX); | ||
4486 | 84 | memset(function->job_end, 0, | ||
4487 | 85 | sizeof(gearman_server_job_st *) * GEARMAN_JOB_PRIORITY_MAX); | ||
4488 | 86 | 111 | ||
4489 | 87 | return function; | 112 | return function; |
4490 | 88 | } | 113 | } |
4491 | 89 | 114 | ||
4492 | 90 | void gearman_server_function_free(gearman_server_function_st *function) | 115 | void gearman_server_function_free(gearman_server_function_st *function) |
4493 | 91 | { | 116 | { |
4501 | 92 | if (function->function_name != NULL) | 117 | GEARMAN_LIST_DEL(function->server->function, function,); |
4502 | 93 | free(function->function_name); | 118 | |
4503 | 94 | 119 | delete function; | |
4497 | 95 | GEARMAN_LIST_DEL(function->server->function, function,) | ||
4498 | 96 | |||
4499 | 97 | if (function->options.allocated) | ||
4500 | 98 | free(function); | ||
4504 | 99 | } | 120 | } |
4505 | 100 | 121 | ||
4506 | === modified file 'libgearman-server/function.h' | |||
4507 | --- libgearman-server/function.h 2010-03-11 19:52:09 +0000 | |||
4508 | +++ libgearman-server/function.h 2010-07-01 01:31:26 +0000 | |||
4509 | @@ -1,4 +1,5 @@ | |||
4510 | 1 | /* Gearman server and library | 1 | /* Gearman server and library |
4511 | 2 | * Copyright (C) 2010 Data Differential | ||
4512 | 2 | * Copyright (C) 2008 Brian Aker, Eric Day | 3 | * Copyright (C) 2008 Brian Aker, Eric Day |
4513 | 3 | * All rights reserved. | 4 | * All rights reserved. |
4514 | 4 | * | 5 | * |
4515 | @@ -14,9 +15,7 @@ | |||
4516 | 14 | #ifndef __GEARMAN_SERVER_FUNCTION_H__ | 15 | #ifndef __GEARMAN_SERVER_FUNCTION_H__ |
4517 | 15 | #define __GEARMAN_SERVER_FUNCTION_H__ | 16 | #define __GEARMAN_SERVER_FUNCTION_H__ |
4518 | 16 | 17 | ||
4522 | 17 | #ifdef __cplusplus | 18 | #include <string> |
4520 | 18 | extern "C" { | ||
4521 | 19 | #endif | ||
4523 | 20 | 19 | ||
4524 | 21 | /** | 20 | /** |
4525 | 22 | * @addtogroup gearman_server_function Function Declarations | 21 | * @addtogroup gearman_server_function Function Declarations |
4526 | @@ -41,32 +40,24 @@ | |||
4527 | 41 | uint32_t job_total; | 40 | uint32_t job_total; |
4528 | 42 | uint32_t job_running; | 41 | uint32_t job_running; |
4529 | 43 | uint32_t max_queue_size; | 42 | uint32_t max_queue_size; |
4530 | 44 | size_t function_name_size; | ||
4531 | 45 | gearman_server_st *server; | 43 | gearman_server_st *server; |
4532 | 46 | gearman_server_function_st *next; | 44 | gearman_server_function_st *next; |
4533 | 47 | gearman_server_function_st *prev; | 45 | gearman_server_function_st *prev; |
4535 | 48 | char *function_name; | 46 | std::string function_name; |
4536 | 49 | gearman_server_worker_st *worker_list; | 47 | gearman_server_worker_st *worker_list; |
4537 | 50 | gearman_server_job_st *job_list[GEARMAN_JOB_PRIORITY_MAX]; | 48 | gearman_server_job_st *job_list[GEARMAN_JOB_PRIORITY_MAX]; |
4538 | 51 | gearman_server_job_st *job_end[GEARMAN_JOB_PRIORITY_MAX]; | 49 | gearman_server_job_st *job_end[GEARMAN_JOB_PRIORITY_MAX]; |
4539 | 50 | |||
4540 | 51 | gearman_server_function_st(gearman_server_st *server, const std::string &function_name_arg); | ||
4541 | 52 | ~gearman_server_function_st(); | ||
4542 | 52 | }; | 53 | }; |
4543 | 53 | 54 | ||
4544 | 54 | /** | 55 | /** |
4545 | 55 | * Add a new function to a server instance. | ||
4546 | 56 | */ | ||
4547 | 57 | GEARMAN_API | ||
4548 | 58 | gearman_server_function_st * | ||
4549 | 59 | gearman_server_function_get(gearman_server_st *server, | ||
4550 | 60 | const char *function_name, | ||
4551 | 61 | size_t function_name_size); | ||
4552 | 62 | |||
4553 | 63 | /** | ||
4554 | 64 | * Initialize a server function structure. | 56 | * Initialize a server function structure. |
4555 | 65 | */ | 57 | */ |
4556 | 66 | GEARMAN_API | 58 | GEARMAN_API |
4557 | 67 | gearman_server_function_st * | 59 | gearman_server_function_st * |
4560 | 68 | gearman_server_function_create(gearman_server_st *server, | 60 | gearman_server_function_create(gearman_server_st *server, const std::string &function_name_arg); |
4559 | 69 | gearman_server_function_st *function); | ||
4561 | 70 | 61 | ||
4562 | 71 | /** | 62 | /** |
4563 | 72 | * Free a server function structure. | 63 | * Free a server function structure. |
4564 | @@ -76,8 +67,4 @@ | |||
4565 | 76 | 67 | ||
4566 | 77 | /** @} */ | 68 | /** @} */ |
4567 | 78 | 69 | ||
4568 | 79 | #ifdef __cplusplus | ||
4569 | 80 | } | ||
4570 | 81 | #endif | ||
4571 | 82 | |||
4572 | 83 | #endif /* __GEARMAN_SERVER_FUNCTION_H__ */ | 70 | #endif /* __GEARMAN_SERVER_FUNCTION_H__ */ |
4573 | 84 | 71 | ||
4574 | === renamed file 'libgearman-server/gearmand.c' => 'libgearman-server/gearmand.cc' | |||
4575 | --- libgearman-server/gearmand.c 2010-04-06 21:41:46 +0000 | |||
4576 | +++ libgearman-server/gearmand.cc 2010-07-01 01:31:26 +0000 | |||
4577 | @@ -1,4 +1,5 @@ | |||
4578 | 1 | /* Gearman server and library | 1 | /* Gearman server and library |
4579 | 2 | * Copyright (C) 2010 Data Differential | ||
4580 | 2 | * Copyright (C) 2008 Brian Aker, Eric Day | 3 | * Copyright (C) 2008 Brian Aker, Eric Day |
4581 | 3 | * All rights reserved. | 4 | * All rights reserved. |
4582 | 4 | * | 5 | * |
4583 | @@ -11,43 +12,14 @@ | |||
4584 | 11 | * @brief Gearmand Definitions | 12 | * @brief Gearmand Definitions |
4585 | 12 | */ | 13 | */ |
4586 | 13 | 14 | ||
4588 | 14 | #include "common.h" | 15 | #include "libgearman-server/common.h" |
4589 | 15 | #include "gearmand.h" | 16 | #include "gearmand.h" |
4590 | 16 | 17 | ||
4591 | 17 | /* | 18 | /* |
4592 | 18 | * Private declarations | ||
4593 | 19 | */ | ||
4594 | 20 | |||
4595 | 21 | /** | ||
4596 | 22 | * @addtogroup gearmand_private Private Gearman Daemon Functions | ||
4597 | 23 | * @ingroup gearmand | ||
4598 | 24 | * @{ | ||
4599 | 25 | */ | ||
4600 | 26 | |||
4601 | 27 | static void _log(const char *line, gearman_verbose_t verbose, void *context); | ||
4602 | 28 | |||
4603 | 29 | static gearman_return_t _listen_init(gearmand_st *gearmand); | ||
4604 | 30 | static void _listen_close(gearmand_st *gearmand); | ||
4605 | 31 | static gearman_return_t _listen_watch(gearmand_st *gearmand); | ||
4606 | 32 | static void _listen_clear(gearmand_st *gearmand); | ||
4607 | 33 | static void _listen_event(int fd, short events, void *arg); | ||
4608 | 34 | |||
4609 | 35 | static gearman_return_t _wakeup_init(gearmand_st *gearmand); | ||
4610 | 36 | static void _wakeup_close(gearmand_st *gearmand); | ||
4611 | 37 | static gearman_return_t _wakeup_watch(gearmand_st *gearmand); | ||
4612 | 38 | static void _wakeup_clear(gearmand_st *gearmand); | ||
4613 | 39 | static void _wakeup_event(int fd, short events, void *arg); | ||
4614 | 40 | |||
4615 | 41 | static gearman_return_t _watch_events(gearmand_st *gearmand); | ||
4616 | 42 | static void _clear_events(gearmand_st *gearmand); | ||
4617 | 43 | static void _close_events(gearmand_st *gearmand); | ||
4618 | 44 | |||
4619 | 45 | /** @} */ | ||
4620 | 46 | |||
4621 | 47 | /* | ||
4622 | 48 | * Public definitions | 19 | * Public definitions |
4623 | 49 | */ | 20 | */ |
4624 | 50 | 21 | ||
4625 | 22 | <<<<<<< TREE | ||
4626 | 51 | gearmand_st *gearmand_create(const char *host, in_port_t port) | 23 | gearmand_st *gearmand_create(const char *host, in_port_t port) |
4627 | 52 | { | 24 | { |
4628 | 53 | gearmand_st *gearmand; | 25 | gearmand_st *gearmand; |
4629 | @@ -82,10 +54,33 @@ | |||
4630 | 82 | gearmand->thread_list= NULL; | 54 | gearmand->thread_list= NULL; |
4631 | 83 | gearmand->thread_add_next= NULL; | 55 | gearmand->thread_add_next= NULL; |
4632 | 84 | gearmand->free_dcon_list= NULL; | 56 | gearmand->free_dcon_list= NULL; |
4633 | 57 | ======= | ||
4634 | 58 | static in_port_t global_port= 0; | ||
4635 | 59 | |||
4636 | 60 | in_port_t libgearmand_server_port() | ||
4637 | 61 | { | ||
4638 | 62 | return global_port; | ||
4639 | 63 | } | ||
4640 | 64 | |||
4641 | 65 | gearmand_st::gearmand_st(const char *host_arg, | ||
4642 | 66 | in_port_t port, | ||
4643 | 67 | uint32_t threads_arg) : | ||
4644 | 68 | ret(GEARMAN_SUCCESS), | ||
4645 | 69 | backlog(0), | ||
4646 | 70 | is_listen_event(false), | ||
4647 | 71 | threads(threads_arg), | ||
4648 | 72 | host(0), | ||
4649 | 73 | base(0), | ||
4650 | 74 | port_list(0), | ||
4651 | 75 | thread_add_next(0) | ||
4652 | 76 | { | ||
4653 | 77 | host= host_arg; | ||
4654 | 78 | >>>>>>> MERGE-SOURCE | ||
4655 | 85 | 79 | ||
4656 | 86 | if (port == 0) | 80 | if (port == 0) |
4657 | 87 | port= GEARMAN_DEFAULT_TCP_PORT; | 81 | port= GEARMAN_DEFAULT_TCP_PORT; |
4658 | 88 | 82 | ||
4659 | 83 | <<<<<<< TREE | ||
4660 | 89 | if (gearmand_port_add(gearmand, port, NULL) != GEARMAN_SUCCESS) | 84 | if (gearmand_port_add(gearmand, port, NULL) != GEARMAN_SUCCESS) |
4661 | 90 | { | 85 | { |
4662 | 91 | gearmand_free(gearmand); | 86 | gearmand_free(gearmand); |
4663 | @@ -188,109 +183,137 @@ | |||
4664 | 188 | 183 | ||
4665 | 189 | gearmand->port_list= port_list; | 184 | gearmand->port_list= port_list; |
4666 | 190 | gearmand->port_count++; | 185 | gearmand->port_count++; |
4667 | 186 | ======= | ||
4668 | 187 | global_port= port; | ||
4669 | 188 | |||
4670 | 189 | port_add(port); | ||
4671 | 190 | } | ||
4672 | 191 | |||
4673 | 192 | gearmand_st::~gearmand_st() | ||
4674 | 193 | { | ||
4675 | 194 | _close_events(); | ||
4676 | 195 | |||
4677 | 196 | Log::Instance()->info("Stopping Services"); | ||
4678 | 197 | |||
4679 | 198 | Services::Instance()->stop(); | ||
4680 | 199 | |||
4681 | 200 | thread_add_next= thread_list.end(); | ||
4682 | 201 | |||
4683 | 202 | if (thread_list.size()) | ||
4684 | 203 | { | ||
4685 | 204 | Log::Instance()->info("Shutting down all threads"); | ||
4686 | 205 | } | ||
4687 | 206 | for (std::vector<ThreadPtr>::iterator iter= thread_list.begin(); | ||
4688 | 207 | iter != thread_list.end(); | ||
4689 | 208 | iter++) | ||
4690 | 209 | { | ||
4691 | 210 | delete *iter; | ||
4692 | 211 | } | ||
4693 | 212 | thread_list.clear(); | ||
4694 | 213 | |||
4695 | 214 | if (base != NULL) | ||
4696 | 215 | event_base_free(base); | ||
4697 | 216 | |||
4698 | 217 | port_list.clear(); | ||
4699 | 218 | |||
4700 | 219 | Log::Instance()->info("Shutdown complete"); | ||
4701 | 220 | } | ||
4702 | 221 | |||
4703 | 222 | gearman_return_t gearmand_st::port_add(in_port_t port, | ||
4704 | 223 | gearman_connection_add_fn *function, | ||
4705 | 224 | Protocol *protocol) | ||
4706 | 225 | { | ||
4707 | 226 | PortPtr new_port(new gearmand_port_st(this, port, function, protocol)); | ||
4708 | 227 | |||
4709 | 228 | port_list.push_back(new_port); | ||
4710 | 229 | >>>>>>> MERGE-SOURCE | ||
4711 | 191 | 230 | ||
4712 | 192 | return GEARMAN_SUCCESS; | 231 | return GEARMAN_SUCCESS; |
4713 | 193 | } | 232 | } |
4714 | 194 | 233 | ||
4716 | 195 | gearman_return_t gearmand_run(gearmand_st *gearmand) | 234 | gearman_return_t gearmand_st::run() |
4717 | 196 | { | 235 | { |
4718 | 197 | uint32_t x; | ||
4719 | 198 | 236 | ||
4720 | 199 | /* Initialize server components. */ | 237 | /* Initialize server components. */ |
4722 | 200 | if (gearmand->base == NULL) | 238 | if (base == NULL) |
4723 | 201 | { | 239 | { |
4725 | 202 | gearmand_log_info(gearmand, "Starting up"); | 240 | Log::Instance()->info("Starting up"); |
4726 | 203 | 241 | ||
4728 | 204 | if (gearmand->threads > 0) | 242 | if (threads > 0) |
4729 | 205 | { | 243 | { |
4730 | 206 | #ifndef HAVE_EVENT_BASE_NEW | 244 | #ifndef HAVE_EVENT_BASE_NEW |
4733 | 207 | gearmand_log_fatal(gearmand, "Multi-threaded gearmand requires libevent 1.4 or later, libevent 1.3 does not provided a " | 245 | Log::Instance()->fatal("Multi-threaded gearmand requires libevent 1.4 or later, libevent 1.3 does not provided a " |
4734 | 208 | "thread-safe interface."); | 246 | "thread-safe interface."); |
4735 | 209 | return GEARMAN_EVENT; | 247 | return GEARMAN_EVENT; |
4736 | 210 | #else | ||
4737 | 211 | /* Set the number of free connection structures each thread should keep | ||
4738 | 212 | around before the main thread is forced to take them. We compute this | ||
4739 | 213 | here so we don't need to on every new connection. */ | ||
4740 | 214 | gearmand->max_thread_free_dcon_count= ((GEARMAN_MAX_FREE_SERVER_CON / | ||
4741 | 215 | gearmand->threads) / 2); | ||
4742 | 216 | #endif | 248 | #endif |
4743 | 217 | } | 249 | } |
4744 | 218 | 250 | ||
4746 | 219 | gearmand_log_debug(gearmand, "Initializing libevent for main thread"); | 251 | Log::Instance()->debug("Initializing libevent for main thread"); |
4747 | 220 | 252 | ||
4750 | 221 | gearmand->base= event_base_new(); | 253 | base= event_base_new(); |
4751 | 222 | if (gearmand->base == NULL) | 254 | if (base == NULL) |
4752 | 223 | { | 255 | { |
4754 | 224 | gearmand_log_fatal(gearmand, "gearmand_run:event_base_new:NULL"); | 256 | Log::Instance()->fatal("gearmand_run:event_base_new:NULL"); |
4755 | 225 | return GEARMAN_EVENT; | 257 | return GEARMAN_EVENT; |
4756 | 226 | } | 258 | } |
4757 | 227 | 259 | ||
4770 | 228 | gearmand_log_debug(gearmand, "Method for libevent: %s", | 260 | Log::Instance()->debug("Method for libevent: %s", event_base_get_method(base)); |
4771 | 229 | event_base_get_method(gearmand->base)); | 261 | |
4772 | 230 | 262 | ret= _listen_init(); | |
4773 | 231 | gearmand->ret= _listen_init(gearmand); | 263 | if (ret != GEARMAN_SUCCESS) |
4774 | 232 | if (gearmand->ret != GEARMAN_SUCCESS) | 264 | return ret; |
4775 | 233 | return gearmand->ret; | 265 | |
4776 | 234 | 266 | ret= _wakeup_init(base); | |
4777 | 235 | gearmand->ret= _wakeup_init(gearmand); | 267 | if (ret != GEARMAN_SUCCESS) |
4778 | 236 | if (gearmand->ret != GEARMAN_SUCCESS) | 268 | return ret; |
4779 | 237 | return gearmand->ret; | 269 | |
4780 | 238 | 270 | Log::Instance()->debug("Creating %u threads", threads); | |
4769 | 239 | gearmand_log_debug(gearmand, "Creating %u threads", gearmand->threads); | ||
4781 | 240 | 271 | ||
4782 | 241 | /* If we have 0 threads we still need to create a fake one for context. */ | 272 | /* If we have 0 threads we still need to create a fake one for context. */ |
4784 | 242 | x= 0; | 273 | uint32_t x= 0; |
4785 | 243 | do | 274 | do |
4786 | 244 | { | 275 | { |
4790 | 245 | gearmand->ret= gearmand_thread_create(gearmand); | 276 | ThreadPtr thread(new gearmand_thread_st(this)); |
4791 | 246 | if (gearmand->ret != GEARMAN_SUCCESS) | 277 | thread_list.push_back(thread); |
4792 | 247 | return gearmand->ret; | 278 | |
4793 | 279 | if (ret != GEARMAN_SUCCESS) | ||
4794 | 280 | return ret; | ||
4795 | 248 | x++; | 281 | x++; |
4802 | 249 | } | 282 | } while (x < threads); |
4803 | 250 | while (x < gearmand->threads); | 283 | |
4804 | 251 | 284 | thread_add_next= thread_list.end(); | |
4805 | 252 | gearmand->ret= gearman_server_queue_replay(&(gearmand->server)); | 285 | |
4806 | 253 | if (gearmand->ret != GEARMAN_SUCCESS) | 286 | ret= server.queue_replay(); |
4807 | 254 | return gearmand->ret; | 287 | if (ret != GEARMAN_SUCCESS) |
4808 | 288 | return ret; | ||
4809 | 255 | } | 289 | } |
4810 | 256 | 290 | ||
4818 | 257 | gearmand->ret= _watch_events(gearmand); | 291 | ret= _watch_events(); |
4819 | 258 | if (gearmand->ret != GEARMAN_SUCCESS) | 292 | if (ret != GEARMAN_SUCCESS) |
4820 | 259 | return gearmand->ret; | 293 | return ret; |
4821 | 260 | 294 | ||
4822 | 261 | gearmand_log_info(gearmand, "Entering main event loop"); | 295 | Log::Instance()->info("Starting Services"); |
4823 | 262 | 296 | ||
4824 | 263 | if (event_base_loop(gearmand->base, 0) == -1) | 297 | Services::Instance()->start(); |
4825 | 298 | |||
4826 | 299 | Log::Instance()->info("Entering main event loop"); | ||
4827 | 300 | |||
4828 | 301 | if (event_base_loop(base, 0) == -1) | ||
4829 | 264 | { | 302 | { |
4831 | 265 | gearmand_log_fatal(gearmand, "gearmand_run:event_base_loop:-1"); | 303 | Log::Instance()->fatal("gearmand_run:event_base_loop:-1"); |
4832 | 266 | return GEARMAN_EVENT; | 304 | return GEARMAN_EVENT; |
4833 | 267 | } | 305 | } |
4834 | 268 | 306 | ||
4855 | 269 | gearmand_log_info(gearmand, "Exited main event loop"); | 307 | Log::Instance()->info("Exited main event loop"); |
4856 | 270 | 308 | ||
4857 | 271 | return gearmand->ret; | 309 | return ret; |
4858 | 272 | } | 310 | } |
4839 | 273 | |||
4840 | 274 | void gearmand_wakeup(gearmand_st *gearmand, gearmand_wakeup_t wakeup) | ||
4841 | 275 | { | ||
4842 | 276 | uint8_t buffer= wakeup; | ||
4843 | 277 | |||
4844 | 278 | /* If this fails, there is not much we can really do. This should never fail | ||
4845 | 279 | though if the main gearmand thread is still active. */ | ||
4846 | 280 | if (write(gearmand->wakeup_fd[1], &buffer, 1) != 1) | ||
4847 | 281 | gearmand_log_error(gearmand, "gearmand_wakeup:write:%d", errno); | ||
4848 | 282 | } | ||
4849 | 283 | |||
4850 | 284 | void gearmand_set_round_robin(gearmand_st *gearmand, bool round_robin) | ||
4851 | 285 | { | ||
4852 | 286 | gearmand->server.flags.round_robin= round_robin; | ||
4853 | 287 | } | ||
4854 | 288 | |||
4859 | 289 | 311 | ||
4860 | 290 | /* | 312 | /* |
4861 | 291 | * Private definitions | 313 | * Private definitions |
4862 | 292 | */ | 314 | */ |
4863 | 293 | 315 | ||
4864 | 316 | <<<<<<< TREE | ||
4865 | 294 | static void _log(const char *line, gearman_verbose_t verbose, void *context) | 317 | static void _log(const char *line, gearman_verbose_t verbose, void *context) |
4866 | 295 | { | 318 | { |
4867 | 296 | gearmand_st *gearmand= (gearmand_st *)context; | 319 | gearmand_st *gearmand= (gearmand_st *)context; |
4868 | @@ -623,21 +646,86 @@ | |||
4869 | 623 | void *arg) | 646 | void *arg) |
4870 | 624 | { | 647 | { |
4871 | 625 | gearmand_st *gearmand= (gearmand_st *)arg; | 648 | gearmand_st *gearmand= (gearmand_st *)arg; |
4872 | 649 | ======= | ||
4873 | 650 | gearman_return_t gearmand_st::_listen_init() | ||
4874 | 651 | { | ||
4875 | 652 | for (std::vector<PortPtr>::iterator iter= port_list.begin(); | ||
4876 | 653 | iter != port_list.end(); iter++) | ||
4877 | 654 | { | ||
4878 | 655 | gearman_return_t rc= (*iter)->_listen_init(host, base, backlog); | ||
4879 | 656 | |||
4880 | 657 | if (rc != GEARMAN_SUCCESS) | ||
4881 | 658 | return rc; | ||
4882 | 659 | } | ||
4883 | 660 | |||
4884 | 661 | return GEARMAN_SUCCESS; | ||
4885 | 662 | } | ||
4886 | 663 | |||
4887 | 664 | void gearmand_st::_listen_close() | ||
4888 | 665 | { | ||
4889 | 666 | _listen_clear(); | ||
4890 | 667 | } | ||
4891 | 668 | |||
4892 | 669 | gearman_return_t gearmand_st::_listen_watch() | ||
4893 | 670 | { | ||
4894 | 671 | if (is_listen_event) | ||
4895 | 672 | return GEARMAN_SUCCESS; | ||
4896 | 673 | |||
4897 | 674 | for (std::vector<PortPtr>::iterator iter= port_list.begin(); iter != port_list.end(); iter++) | ||
4898 | 675 | { | ||
4899 | 676 | |||
4900 | 677 | gearman_return_t rc= (*iter)->_listen_watch(); | ||
4901 | 678 | |||
4902 | 679 | if (rc == GEARMAN_EVENT) | ||
4903 | 680 | return GEARMAN_EVENT; | ||
4904 | 681 | } | ||
4905 | 682 | |||
4906 | 683 | is_listen_event= true; | ||
4907 | 684 | return GEARMAN_SUCCESS; | ||
4908 | 685 | } | ||
4909 | 686 | |||
4910 | 687 | void gearmand_st::_listen_clear() | ||
4911 | 688 | { | ||
4912 | 689 | if (! (is_listen_event)) | ||
4913 | 690 | return; | ||
4914 | 691 | |||
4915 | 692 | for (std::vector<PortPtr>::iterator iter= port_list.begin(); iter != port_list.end(); iter++) | ||
4916 | 693 | { | ||
4917 | 694 | (*iter)->_listen_clear(); | ||
4918 | 695 | } | ||
4919 | 696 | |||
4920 | 697 | is_listen_event= false; | ||
4921 | 698 | } | ||
4922 | 699 | |||
4923 | 700 | void gearmand_st::_wake_up_thread_for_shutdown() | ||
4924 | 701 | { | ||
4925 | 702 | for (std::vector<ThreadPtr>::iterator iter= thread_list.begin(); | ||
4926 | 703 | iter != thread_list.end(); | ||
4927 | 704 | iter++) | ||
4928 | 705 | { | ||
4929 | 706 | (*iter)->set_wakeup(GEARMAND_WAKEUP_SHUTDOWN_GRACEFUL); | ||
4930 | 707 | } | ||
4931 | 708 | } | ||
4932 | 709 | |||
4933 | 710 | void gearmand_st::_wakeup_event(int fd, short events __attribute__ ((unused))) | ||
4934 | 711 | { | ||
4935 | 712 | gearmand_st *gearmand= (gearmand_st *)this; | ||
4936 | 713 | >>>>>>> MERGE-SOURCE | ||
4937 | 626 | uint8_t buffer[GEARMAN_PIPE_BUFFER_SIZE]; | 714 | uint8_t buffer[GEARMAN_PIPE_BUFFER_SIZE]; |
4938 | 627 | ssize_t ret; | ||
4939 | 628 | gearmand_thread_st *thread; | ||
4940 | 629 | 715 | ||
4941 | 630 | while (1) | 716 | while (1) |
4942 | 631 | { | 717 | { |
4945 | 632 | ret= read(fd, buffer, GEARMAN_PIPE_BUFFER_SIZE); | 718 | ssize_t rc; |
4946 | 633 | if (ret == 0) | 719 | rc= read(fd, buffer, GEARMAN_PIPE_BUFFER_SIZE); |
4947 | 720 | if (rc == 0) | ||
4948 | 634 | { | 721 | { |
4951 | 635 | _clear_events(gearmand); | 722 | gearmand->_clear_events(); |
4952 | 636 | gearmand_log_fatal(gearmand, "_wakeup_event:read:EOF"); | 723 | Log::Instance()->fatal("_wakeup_event:read:EOF"); |
4953 | 637 | gearmand->ret= GEARMAN_PIPE_EOF; | 724 | gearmand->ret= GEARMAN_PIPE_EOF; |
4954 | 725 | |||
4955 | 638 | return; | 726 | return; |
4956 | 639 | } | 727 | } |
4958 | 640 | else if (ret == -1) | 728 | else if (rc == -1) |
4959 | 641 | { | 729 | { |
4960 | 642 | if (errno == EINTR) | 730 | if (errno == EINTR) |
4961 | 643 | continue; | 731 | continue; |
4962 | @@ -645,46 +733,42 @@ | |||
4963 | 645 | if (errno == EAGAIN) | 733 | if (errno == EAGAIN) |
4964 | 646 | break; | 734 | break; |
4965 | 647 | 735 | ||
4968 | 648 | _clear_events(gearmand); | 736 | gearmand->_clear_events(); |
4969 | 649 | gearmand_log_fatal(gearmand, "_wakeup_event:read:%d", errno); | 737 | Log::Instance()->fatal("_wakeup_event:read:%d", errno); |
4970 | 650 | gearmand->ret= GEARMAN_ERRNO; | 738 | gearmand->ret= GEARMAN_ERRNO; |
4971 | 651 | return; | 739 | return; |
4972 | 652 | } | 740 | } |
4973 | 653 | 741 | ||
4975 | 654 | for (ssize_t x= 0; x < ret; x++) | 742 | for (ssize_t x= 0; x < rc; x++) |
4976 | 655 | { | 743 | { |
4977 | 656 | switch ((gearmand_wakeup_t)buffer[x]) | 744 | switch ((gearmand_wakeup_t)buffer[x]) |
4978 | 657 | { | 745 | { |
4979 | 658 | case GEARMAND_WAKEUP_PAUSE: | 746 | case GEARMAND_WAKEUP_PAUSE: |
4982 | 659 | gearmand_log_info(gearmand, "Received PAUSE wakeup event"); | 747 | Log::Instance()->info("Received PAUSE wakeup event"); |
4983 | 660 | _clear_events(gearmand); | 748 | gearmand->_clear_events(); |
4984 | 661 | gearmand->ret= GEARMAN_PAUSE; | 749 | gearmand->ret= GEARMAN_PAUSE; |
4985 | 662 | break; | 750 | break; |
4986 | 663 | 751 | ||
4987 | 664 | case GEARMAND_WAKEUP_SHUTDOWN_GRACEFUL: | 752 | case GEARMAND_WAKEUP_SHUTDOWN_GRACEFUL: |
4990 | 665 | gearmand_log_info(gearmand, "Received SHUTDOWN_GRACEFUL wakeup event"); | 753 | Log::Instance()->info("Received SHUTDOWN_GRACEFUL wakeup event"); |
4989 | 666 | _listen_close(gearmand); | ||
4991 | 667 | 754 | ||
4997 | 668 | for (thread= gearmand->thread_list; thread != NULL; | 755 | gearmand->_listen_close(); |
4998 | 669 | thread= thread->next) | 756 | gearmand->_wake_up_thread_for_shutdown(); |
4994 | 670 | { | ||
4995 | 671 | gearmand_thread_wakeup(thread, GEARMAND_WAKEUP_SHUTDOWN_GRACEFUL); | ||
4996 | 672 | } | ||
4999 | 673 | 757 | ||
5000 | 674 | gearmand->ret= GEARMAN_SHUTDOWN_GRACEFUL; | 758 | gearmand->ret= GEARMAN_SHUTDOWN_GRACEFUL; |
The diff has been truncated for viewing.