Merge lp:~mordred/gearmand/fix-1.0-build into lp:gearmand/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
Reviewer Review Type Date Requested Status
Brian Aker Pending
Review via email: mp+28949@code.launchpad.net

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.
lp:~mordred/gearmand/fix-1.0-build updated
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
=== added file '.quickly'
--- .quickly 1970-01-01 00:00:00 +0000
+++ .quickly 2010-07-01 01:31:26 +0000
@@ -0,0 +1,5 @@
1project = gearmand
2version = 1.0
3template = pandora-build
4project-type = application
5pandora-version = 0.135
06
=== modified file 'ChangeLog'
--- ChangeLog 2010-06-30 20:04:51 +0000
+++ ChangeLog 2010-07-01 01:31:26 +0000
@@ -1,8 +1,22 @@
1<<<<<<< TREE
10.14 Wed Jun 30 13:04:39 PDT 201020.14 Wed Jun 30 13:04:39 PDT 2010
2 * Leak in SQLite resolved.3 * Leak in SQLite resolved.
3 * updated build configs4 * updated build configs
4 * Increased testting.5 * Increased testting.
56
7=======
81.00 Mon Jun 14 12:17:09 PDT 2010
9 * Server written in C++ now.
10 * Making use of boost command line arguments.
11 * New debugging can now be done with the server.
12 * New Logger functionality added so that you can either use syslog, or
13 use stderr.
14 * It is possible to have "workers" internally in the server that act
15 as internal services.
16
17
18
19>>>>>>> MERGE-SOURCE
60.13 Sun Apr 4 14:45:08 PDT 2010200.13 Sun Apr 4 14:45:08 PDT 2010
7 * Fix for bug #518512.21 * Fix for bug #518512.
8 * Use OR REPLACE syntax for inserting items into the sqlite.22 * Use OR REPLACE syntax for inserting items into the sqlite.
923
=== added file 'HACKING'
--- HACKING 1970-01-01 00:00:00 +0000
+++ HACKING 2010-07-01 01:31:26 +0000
@@ -0,0 +1,13 @@
1Hi!
2
3If you are working on the server here are some handy environmental variables
4you can set so that you can debug make test:
5
6GEARMAN_VALGRIND <- runs the server under valgrind.
7GEARMAN_MANUAL_GDB <-- runs the server under a remote version of GDB.
8GEARMAN_LOG <-- generates a log file for you with the output of the debug for the server
9
10GDB will pause the server while you do run the GDB command.
11
12Cheers,
13 -Brian
014
=== modified file 'Makefile.am'
--- Makefile.am 2010-06-30 15:21:36 +0000
+++ Makefile.am 2010-07-01 01:31:26 +0000
@@ -35,12 +35,13 @@
35TESTS += ${check_PROGRAMS}35TESTS += ${check_PROGRAMS}
3636
37EXTRA_DIST+= \37EXTRA_DIST+= \
38 docs/Doxyfile.api \38 HACKING \
39 docs/Doxyfile.dev \39 docs/Doxyfile.api \
40 docs/api_header.html \40 docs/Doxyfile.dev \
41 docs/dev_header.html \41 docs/api_header.html \
42 docs/doxygen.h \42 docs/dev_header.html \
43 scripts/README.solaris43 docs/doxygen.h \
44 scripts/README.solaris
4445
45docs: all46docs: all
46 ${DOXYGEN} docs/Doxyfile.api47 ${DOXYGEN} docs/Doxyfile.api
4748
=== modified file 'bin/gearman.c'
--- bin/gearman.c 2010-06-30 20:04:05 +0000
+++ bin/gearman.c 2010-07-01 01:31:26 +0000
@@ -588,9 +588,13 @@
588 {588 {
589 ret= gearman_worker_work(&worker);589 ret= gearman_worker_work(&worker);
590 if (ret != GEARMAN_SUCCESS)590 if (ret != GEARMAN_SUCCESS)
591<<<<<<< TREE
591 {592 {
592 GEARMAN_ERROR("gearman_worker_work:%s", gearman_worker_error(&worker));593 GEARMAN_ERROR("gearman_worker_work:%s", gearman_worker_error(&worker));
593 }594 }
595=======
596 GEARMAN_ERROR("gearman_worker_work:%s", gearman_worker_error(&worker));
597>>>>>>> MERGE-SOURCE
594598
595 if (args->count > 0)599 if (args->count > 0)
596 {600 {
597601
=== modified file 'config/autorun.sh'
--- config/autorun.sh 2009-12-18 18:02:39 +0000
+++ config/autorun.sh 2010-07-01 01:31:26 +0000
@@ -35,7 +35,7 @@
35LIBTOOLIZE_FLAGS=" --automake --copy --force"35LIBTOOLIZE_FLAGS=" --automake --copy --force"
36# --add-missing instructs automake to install missing auxiliary files36# --add-missing instructs automake to install missing auxiliary files
37# and --force to overwrite them if they already exist37# and --force to overwrite them if they already exist
38AUTOMAKE_FLAGS="--add-missing --copy --force"38AUTOMAKE_FLAGS="--add-missing --copy --force --foreign"
39ACLOCAL_FLAGS="-I m4"39ACLOCAL_FLAGS="-I m4"
4040
41ARGV0=$041ARGV0=$0
4242
=== added file 'config/pandora-plugin'
--- config/pandora-plugin 1970-01-01 00:00:00 +0000
+++ config/pandora-plugin 2010-07-01 01:31:26 +0000
@@ -0,0 +1,667 @@
1#!/usr/bin/python
2
3# Copyright (C) 2009 Sun Microsystems
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; version 2 of the License.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18pandora_plugin_file = 'config/pandora-plugin.ini'
19
20# Find plugins in the tree and add them to the build system
21
22import ConfigParser, os, sys
23import datetime, time
24import subprocess
25
26plugin_am_file=None
27plugin_ac_file=None
28
29class ChangeProtectedFile(object):
30
31 def __init__(self, fname):
32 self.bogus_file= False
33 self.real_fname= fname
34 self.new_fname= "%s.new" % fname
35 try:
36 self.new_file= open(self.new_fname,'w+')
37 except IOError:
38 self.bogus_file= True
39
40 def write(self, text):
41 if not self.bogus_file:
42 self.new_file.write(text)
43
44 # We've written all of this out into .new files, now we only copy them
45 # over the old ones if they are different, so that we don't cause
46 # unnecessary recompiles
47 def close(self):
48 """Return True if the file had changed."""
49 if self.bogus_file:
50 return
51 self.new_file.seek(0)
52 new_content = self.new_file.read()
53 self.new_file.close()
54 try:
55 old_file = file(self.real_fname, 'r')
56 old_content = old_file.read()
57 old_file.close()
58 except IOError:
59 old_content = None
60 if new_content != old_content:
61 if old_content != None:
62 os.unlink(self.real_fname)
63 os.rename(self.new_fname, self.real_fname)
64 return True
65 else:
66 try:
67 os.unlink(self.new_fname)
68 except:
69 pass
70
71
72def write_external_configure(plugin, plugin_file):
73 """Write the initial bits of the configure.ac file"""
74 if not os.path.exists('m4'):
75 os.mkdir('m4')
76 plugin_file.write("""
77AC_PREREQ(2.59)dnl Minimum Autoconf version required.
78AC_INIT([%(name)s],[%(version)s],[%(url)s])
79AC_CONFIG_SRCDIR([%(main_source)s])
80AC_CONFIG_AUX_DIR(config)
81
82PANDORA_CANONICAL_TARGET(less-warnings, warnings-always-on, require-cxx, force-gcc42,skip-visibility)
83
84PANDORA_REQUIRE_LIBPROTOBUF
85PANDORA_PROTOBUF_REQUIRE_VERSION([2.1.0])
86PANDORA_REQUIRE_PROTOC
87
88AC_LANG_PUSH(C++)
89PANDORA_REQUIRE_PTHREAD
90PANDORA_REQUIRE_LIBDL
91AC_LANG_POP
92
93PANDORA_USE_BETTER_MALLOC
94
95PANDORA_DRIZZLE_BUILD
96""" % plugin)
97
98 write_plugin_ac(plugin, plugin_file)
99
100 plugin_file.write("""
101AC_CONFIG_FILES(Makefile)
102
103AC_OUTPUT
104
105echo "---"
106echo "Configuration summary for $PACKAGE_NAME version $VERSION $PANDORA_RELEASE_COMMENT"
107echo ""
108echo " * Installation prefix: $prefix"
109echo " * System type: $host_vendor-$host_os"
110echo " * Host CPU: $host_cpu"
111echo " * C Compiler: $CC_VERSION"
112echo " * C++ Compiler: $CXX_VERSION"
113echo " * Debug enabled: $with_debug"
114echo " * Warnings as failure: $ac_cv_warnings_as_errors"
115echo " * C++ cstdint location: $ac_cv_cxx_cstdint"
116echo " * C++ hash_map location: $ac_cv_cxx_hash_map"
117echo " * C++ hash namespace: $ac_cv_cxx_hash_namespace"
118echo " * C++ shared_ptr namespace: $ac_cv_shared_ptr_namespace"
119echo ""
120echo "---"
121
122 """ % plugin)
123
124def write_external_makefile(plugin, plugin_file):
125
126 plugin_file.write("""
127ACLOCAL_AMFLAGS = -I m4 --force
128VERSION=$(PANDORA_RELEASE_VERSION)
129
130pkgplugindir=%(pkgplugindir)s
131EXTRA_DIST = plugin.ini
132
133""" % plugin)
134 if plugin['headers'] != "":
135 plugin_file.write("noinst_HEADERS = %(headers)s\n" % plugin)
136 if plugin['install_headers'] != "":
137 plugin_file.write("nobase_include_HEADERS += %(install_headers)s\n" % plugin)
138 if plugin['testsuite']:
139 if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
140 plugin_file.write("EXTRA_DIST += %(testsuitedir)s\n" % plugin)
141 plugin_file.write("""
142pkgplugin_LTLIBRARIES=%(libname)s.la
143%(libname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
144%(libname)s_la_LIBADD=%(libs)s
145%(libname)s_la_DEPENDENCIES=%(libs)s
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
147%(libname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
148%(libname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
149%(libname)s_la_SOURCES=%(sources)s
150check_PROGRAMS += %(tests)s
151""" % plugin)
152 plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
153 if os.path.exists(plugin_am_file):
154 plugin_file.write('include %s\n' % plugin_am_file)
155
156def write_external_plugin():
157 """Return True if the plugin had changed."""
158 plugin = read_plugin_ini('.')
159 expand_plugin_ini(plugin)
160 plugin_file = ChangeProtectedFile('configure.ac')
161 write_external_configure(plugin, plugin_file)
162 result = plugin_file.close()
163 plugin_file = ChangeProtectedFile('Makefile.am')
164 write_external_makefile(plugin, plugin_file)
165 # Write some stub configure.ac and Makefile.am files that include the above
166 result = plugin_file.close() or result
167 return result
168
169def write_plugin(plugin, plugin_ini_list):
170 # Since this function is recursive, make sure we're not already in it.
171 if plugin.has_key('writing_status'):
172 if plugin['writing_status'] == 'done':
173 return
174 else:
175 print "Dependency loop detected with %s" % plugin['name']
176 exit(1)
177
178 plugin['writing_status'] = 'dependencies'
179
180 # Write all dependencies first to get around annoying automake bug
181 for dependency in plugin['dependency_list']:
182 found = False
183 for find_plugin in plugin_ini_list:
184 if find_plugin['module_name'] == dependency:
185 found = True
186 write_plugin(find_plugin, plugin_ini_list)
187 break
188 if found is False:
189 print "Could not find dependency %s: %s" % (plugin['name'], dependency)
190 exit(1)
191
192 write_plugin_ac(plugin, plugin_ac_file)
193 write_plugin_am(plugin, plugin_am_file)
194 plugin['writing_status'] = 'done'
195
196def write_plugin_ac(plugin, plugin_ac):
197 #
198 # Write plugin config instructions into plugin.ac file.
199 #
200 plugin_ac_file=os.path.join(plugin['rel_path'],'plugin.ac')
201 plugin_m4_dir=os.path.join(plugin['rel_path'],'m4')
202 plugin_m4_files=[]
203 if os.path.exists(plugin_m4_dir) and os.path.isdir(plugin_m4_dir):
204 for m4_file in os.listdir(plugin_m4_dir):
205 if os.path.splitext(m4_file)[-1] == '.m4':
206 plugin_m4_files.append(os.path.join(plugin['rel_path'], m4_file))
207 plugin_ac.write("""
208dnl Config for %(title)s
209""" % plugin)
210 for m4_file in plugin_m4_files:
211 plugin_ac.write('m4_sinclude([%s])\n' % m4_file)
212 plugin['plugin_dep_libs']=" ".join(["\${top_builddir}/%s" % f for f in plugin['libs'].split()])
213
214 plugin_ac.write("""
215AC_ARG_WITH([%(name_with_dashes)s-plugin],[
216dnl indented wierd to make the help output correct
217AS_HELP_STRING([--with-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=%(enabled)s@:>@])
218AS_HELP_STRING([--without-%(name_with_dashes)s-plugin],[Disable building %(title)s])
219 ],[
220 with_%(name)s_plugin="$withval"
221 AS_IF([test "x$with_%(name)s_plugin" = "xyes"],[
222 requested_%(name)s_plugin="yes"
223 ],[
224 requested_%(name)s_plugin="no"
225 ])
226 ],[
227 with_%(name)s_plugin="%(enabled)s"
228 requested_%(name)s_plugin="no"
229 ])
230AC_ARG_ENABLE([%(name_with_dashes)s-plugin],[
231dnl indented wierd to make the help output correct
232AS_HELP_STRING([--enable-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=%(default_yesno)s@:>@])
233AS_HELP_STRING([--disable-%(name_with_dashes)s-plugin],[Disable building %(title)s])
234 ],
235 [enable_%(name)s_plugin="$enableval"],
236 [enable_%(name)s_plugin=%(default_yesno)s])
237
238""" % plugin)
239 if os.path.exists(plugin_ac_file):
240 plugin_ac.write('m4_sinclude([%s])\n' % plugin_ac_file)
241 # The plugin author has specified some check to make to determine
242 # if the plugin can be built. If the plugin is turned on and this
243 # check fails, then configure should error out. If the plugin is not
244 # turned on, then the normal conditional build stuff should just let
245 # it silently not build
246 if plugin['has_build_conditional']:
247 plugin_ac.write("""
248AS_IF([test %(build_conditional)s],
249 [], dnl build_conditional can only negate
250 [
251 AS_IF([test "x${requested_%(name)s_plugin}" = "xyes"],
252 [AC_MSG_ERROR([Plugin %(name)s was explicitly requested, yet failed build dependency checks. Aborting!])])
253 with_%(name)s_plugin=no
254 ])
255
256""" % plugin)
257 if not plugin['unconditional']:
258 plugin_ac.write("""
259AM_CONDITIONAL([%(build_conditional_tag)s],
260 [test %(build_conditional)s])
261 """ % plugin)
262
263 plugin_ac.write("""
264AS_IF([test "x$with_%(name)s_plugin" = "xyes"],
265 [
266""" % plugin)
267 if plugin['testsuite']:
268 plugin_ac.write("""
269 pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}"
270 """ % plugin)
271 if plugin['static']:
272 plugin_ac.write("""
273 AS_IF([test "x$enable_%(name)s_plugin" = "xyes"],[
274 pandora_builtin_list="%(module_name)s,${pandora_builtin_list}"
275 pandora_builtin_symbols_list="_drizzled_%(module_name)s_plugin_,${pandora_builtin_symbols_list}"
276 pandora_plugin_libs="${pandora_plugin_libs} \${top_builddir}/%(root_plugin_dir)s/%(libname)s.la"
277 PANDORA_PLUGIN_DEP_LIBS="${PANDORA_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s"
278 ])
279 """ % plugin)
280
281 else:
282 plugin_ac.write("""
283 AS_IF([test "x$enable_%(name)s_plugin" = "xyes"],[
284 pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
285 ])
286 """ % plugin)
287 plugin_ac.write(" ])\n")
288
289def fix_file_paths(plugin, files):
290 # TODO: determine path to plugin dir relative to top_srcdir... append it to
291 # source files if they don't already have it
292 new_files=""
293 if plugin['plugin_dir'] != ".":
294 for file in files.split():
295 if not file.startswith(plugin['rel_path']):
296 file= os.path.join(plugin['rel_path'], file)
297 new_files= "%s %s" % (new_files, file)
298 else:
299 new_files= " ".join(plugin['sources'].split())
300 if new_files != "":
301 return new_files
302 return files
303
304def expand_plugin_ini(plugin):
305 if plugin['name'] == "**OUT-OF-TREE**":
306 print "Out of tree plugins require the name field to be specified in plugin.ini"
307 sys.exit(1)
308
309 if plugin['plugin_dir'] == ".":
310 plugin['rel_path']= plugin['plugin_dir']
311 plugin['unconditional']=True
312 else:
313 plugin['rel_path']= plugin['plugin_dir'][len(config['top_srcdir'])+len(os.path.sep):]
314 plugin['unconditional']=False
315
316 plugin['sources']= fix_file_paths(plugin, plugin['sources'])
317 plugin['main_source']= plugin['sources'].split()[0]
318 plugin['headers']= fix_file_paths(plugin, plugin['headers'])
319 plugin['install_headers']= fix_file_paths(plugin, plugin['install_headers'])
320 plugin['tests']= fix_file_paths(plugin, plugin['tests'])
321
322 # Make a yes/no version for autoconf help messages
323 if plugin['load_by_default'] or plugin['static']:
324 plugin['default_yesno']="yes"
325 else:
326 plugin['default_yesno']="no"
327
328
329 plugin['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper()
330 plugin['name_with_dashes']= plugin['name'].replace('_','-')
331 if plugin.has_key('build_conditional'):
332 plugin['has_build_conditional']=True
333 plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes" -a %(build_conditional)s' % plugin
334 else:
335 plugin['has_build_conditional']=False
336 plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin
337
338 if plugin['install']:
339 plugin['library_type']= 'pkgplugin'
340 else:
341 plugin['library_type']= 'noinst'
342
343def find_testsuite(plugin_dir):
344 for testdir in ['drizzle-tests','tests']:
345 if os.path.isdir(os.path.join(plugin_dir,testdir)):
346 return testdir
347 if os.path.isdir(os.path.join('tests','suite',os.path.basename(plugin_dir))):
348 return ""
349 return None
350
351def read_plugin_ini(plugin_dir):
352 if plugin_dir == ".":
353 plugin_name="**OUT-OF-TREE**"
354 else:
355 short_name=os.path.basename(plugin_dir)
356 plugin_name = plugin_dir[plugin_dir.index(config['root_plugin_dir']) + len(config['root_plugin_dir']) + 1:]
357 module_name = plugin_name.replace("/", config['module_name_separator']).replace("\\", config['module_name_separator'])
358 plugin_name = plugin_name.replace("/", config['plugin_name_separator']).replace("\\", config['plugin_name_separator'])
359
360
361 plugin_file= os.path.join(plugin_dir,config['plugin_ini_fname'])
362 plugin_defaults= dict(sources="%s.cc" % short_name,
363 headers="",
364 install_headers="",
365 cflags="",
366 cppflags="",
367 cxxflags="",
368 libs="",
369 ldflags="",
370 author="",
371 title="",
372 description="",
373 license="PLUGIN_LICENSE_GPL",
374 name=plugin_name,
375 module_name=module_name,
376 load_by_default=config['default_load_by_default'],
377 disabled="False",
378 static="False",
379 dependencies="",
380 dependency_aliases="",
381 tests="",
382 install=config['default_install'])
383 parser=ConfigParser.ConfigParser(defaults= plugin_defaults)
384 parser.read(plugin_file)
385 plugin=dict(parser.items('plugin'))
386 plugin['plugin_dir'] = plugin_dir
387 if plugin_dir == '.':
388 if not plugin.has_key('url'):
389 print "External Plugins are required to specifiy a url"
390 plugin['url']= 'http://launchpad.net/%(name)s' % plugin
391 sys.exit(1)
392 if plugin_dir == '.' and not plugin.has_key('version'):
393 print "External Plugins are required to specifiy a version"
394 sys.exit(1)
395 if not plugin.has_key('version'):
396 plugin['version'] = config['default_plugin_version']
397
398 if plugin.has_key('load_by_default'):
399 plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
400 if plugin.has_key('disabled'):
401 plugin['disabled']=parser.getboolean('plugin','disabled')
402 if plugin['disabled']:
403 plugin['enabled']="no"
404 else:
405 plugin['enabled']="yes"
406 if plugin.has_key('static'):
407 plugin['static']= parser.getboolean('plugin','static')
408 if plugin.has_key('install'):
409 plugin['install']= parser.getboolean('plugin','install')
410 if plugin.has_key('testsuite'):
411 if plugin['testsuite'] == 'disable':
412 plugin['testsuite']= False
413 else:
414 plugin_testsuite= find_testsuite(plugin_dir)
415 plugin['testsuitedir']=plugin_testsuite
416 if plugin_testsuite is not None:
417 plugin['testsuite']=True
418 else:
419 plugin['testsuite']=False
420
421 plugin['cflags']+= ' ' + config['extra_cflags']
422 plugin['cppflags']+= ' ' + config['extra_cppflags']
423 plugin['cxxflags']+= ' ' + config['extra_cxxflags']
424
425 plugin['libname']= "lib%s%s%s" % (config['plugin_prefix'],
426 plugin['name'],
427 config['plugin_suffix'])
428 if config['force_lowercase_libname']:
429 plugin['libname']= plugin['libname'].lower()
430
431 plugin['root_plugin_dir']= config['root_plugin_dir']
432 plugin['plugin_prefix']= config['plugin_prefix']
433 plugin['plugin_suffix']= config['plugin_suffix']
434 plugin['pkgplugindir']= config['pkgplugindir']
435
436 # Dependencies must have a module but dependency aliases are simply added
437 # to the variable passed during compile.
438 plugin['dependency_list'] = plugin['dependencies'].split()
439 dependency_aliases = plugin['dependency_aliases'].split()
440 plugin['dependencies'] = ','.join(plugin['dependency_list'] +
441 plugin['dependency_aliases'].split())
442 dependency_libs = ["%s/lib%s%s.la" % (config['root_plugin_dir'],
443 dependency.lower().replace('::', '_'),
444 config['plugin_suffix'])
445 for dependency in plugin['dependency_list']]
446 plugin['libs'] = " ".join(plugin['libs'].split() + dependency_libs);
447
448# Libtool is going to expand:
449# -DPANDORA_MODULE_AUTHOR='"Padraig O'"'"'Sullivan"'
450# to:
451# "-DPANDORA_MODULE_AUTHOR=\"Padraig O'Sullivan\""
452# So we have to replace internal ''s to '"'"'
453 for key in ('author','title','description','version'):
454 plugin[key]=plugin[key].replace('"','\\"')
455 plugin[key]=plugin[key].replace("'","'\"'\"'")
456 return plugin
457
458
459def write_plugin_am(plugin, plugin_am):
460 """Write an automake fragment for this plugin.
461
462 :param plugin: The plugin dict.
463 :param plugin_am: The file to write to.
464 """
465 # The .plugin.ini.stamp avoids changing the datestamp on plugin.ini which can
466 # confuse VCS systems.
467 plugin_am.write("""
468EXTRA_DIST += %(rel_path)s/plugin.ini
469
470# Prevent errors when a plugin dir is removed
471%(rel_path)s/plugin.ini:
472
473""" % plugin)
474 if plugin['headers'] != "":
475 plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin)
476 if plugin['install_headers'] != "":
477 plugin_am.write("nobase_include_HEADERS += %(install_headers)s\n" % plugin)
478 if plugin['testsuite']:
479 if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
480 plugin_am.write("EXTRA_DIST += %(rel_path)s/%(testsuitedir)s\n" % plugin)
481 if plugin['static']:
482 plugin_am.write("""
483%(root_plugin_dir)s_%(plugin_prefix)s%(name)s_dir=${top_srcdir}/%(rel_path)s
484EXTRA_DIST += %(rel_path)s/plugin.ini
485if %(build_conditional_tag)s
486 noinst_LTLIBRARIES+=%(root_plugin_dir)s/%(libname)s.la
487 %(root_plugin_dir)s_%(libname)s_la_LIBADD=%(libs)s
488 %(root_plugin_dir)s_%(libname)s_la_DEPENDENCIES=%(libs)s
489 %(root_plugin_dir)s_%(libname)s_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
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
491 %(root_plugin_dir)s_%(libname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
492 %(root_plugin_dir)s_%(libname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
493 %(root_plugin_dir)s_%(libname)s_la_SOURCES=%(sources)s
494 check_PROGRAMS += %(tests)s
495 PANDORA_DYNAMIC_LDADDS+=${top_builddir}/%(root_plugin_dir)s/%(libname)s.la
496endif
497""" % plugin)
498 else:
499 plugin_am.write("""
500%(root_plugin_dir)s_%(plugin_prefix)s%(name)s_dir=${top_srcdir}/%(rel_path)s
501EXTRA_DIST += %(rel_path)s/plugin.ini
502if %(build_conditional_tag)s
503 %(library_type)s_LTLIBRARIES+=%(root_plugin_dir)s/%(libname)s.la
504 %(root_plugin_dir)s_%(libname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
505 %(root_plugin_dir)s_%(libname)s_la_LIBADD=%(libs)s
506 %(root_plugin_dir)s_%(libname)s_la_DEPENDENCIES=%(libs)s
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
508 %(root_plugin_dir)s_%(libname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
509 %(root_plugin_dir)s_%(libname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
510 %(root_plugin_dir)s_%(libname)s_la_SOURCES=%(sources)s
511 check_PROGRAMS += %(tests)s
512endif
513""" % plugin)
514 plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
515 if os.path.exists(plugin_am_file):
516 plugin_am.write('include %s\n' % plugin_am_file)
517
518#
519# MAIN STARTS HERE:
520#
521
522# Parse the pandora-plugin config file
523
524config_defaults= dict(
525 top_srcdir='.',
526 top_builddir='.',
527 plugin_ini_fname='plugin.ini',
528 plugin_prefix='',
529 plugin_suffix='',
530 extra_cflags='',
531 extra_cppflags='',
532 extra_cxxflags='',
533 root_plugin_dir='',
534 pkgplugindir='',
535 default_install='True',
536 default_plugin_version='',
537 default_load_by_default='False',
538 force_lowercase_libname='True',
539 plugin_name_separator='_',
540 module_name_separator='::'
541)
542
543config_parser = ConfigParser.ConfigParser(defaults=config_defaults)
544config_parser.read(pandora_plugin_file)
545config = dict(config_parser.items('pandora-plugin'))
546config['force_lowercase_libname']=config_parser.getboolean('pandora-plugin','force_lowercase_libname')
547
548# I'm 3 seconds away from writing a comprehensive build solution
549if not os.path.exists('config/pandora_vc_revinfo'):
550 if os.path.exists('.bzr'):
551 bzr_revno= subprocess.Popen(["bzr", "revno"], stdout=subprocess.PIPE).communicate()[0].strip()
552 rev_date= datetime.date.fromtimestamp(time.time())
553 config['default_plugin_version'] = "%d.%02d.%s" % (rev_date.year, rev_date.month, bzr_revno)
554 else:
555 config['default_plugin_version']=datetime.date.fromtimestamp(time.time()).isoformat()
556else:
557 # need to read config/pandora_vc_revno
558 pandora_vc_revno=open('config/pandora_vc_revinfo','r').read().split()
559 rev_date=""
560 bzr_revno=""
561 for revno_line in pandora_vc_revno:
562 (revno_key,revno_val)= revno_line.split("=")
563 if revno_key == 'PANDORA_VC_REVNO':
564 bzr_revno=revno_val.strip()
565 elif revno_key == 'PANDORA_RELEASE_DATE':
566 rev_date=revno_val.strip()
567
568 config['default_plugin_version'] = "%s.%s" % (rev_date, bzr_revno)
569
570actions=[]
571for arg in sys.argv:
572 if arg.startswith('--top_srcdir='):
573 config['top_srcdir']=arg[12:]
574 elif arg.startswith('--top_builddir='):
575 config['top_builddir']=arg[14:]
576 elif arg == "--force-all":
577 actions=['plugin-list','pandora-plugin.am','write']
578 break
579 else:
580 actions.append(arg)
581if len(actions) == 0:
582 actions.append('write')
583
584plugin_list=[]
585
586def accumulate_plugins(arg, dirname, fnames):
587 # plugin_ini_fname is a name in dirname indicating dirname is a plugin.
588 if config['plugin_ini_fname'] in fnames:
589 arg.append(dirname)
590
591os.path.walk(os.path.join(config['top_srcdir'],
592 config['root_plugin_dir']),
593 accumulate_plugins,
594 plugin_list)
595
596
597if not os.path.exists("config/pandora-plugin.am") or "write" in actions:
598 plugin_am_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.am'))
599 plugin_am_file.write("""
600# always the current list, generated every build so keep this lean.
601# pandora-plugin.list: datestamp preserved list
602${srcdir}/config/pandora-plugin.list: .plugin.scan
603.plugin.scan:
604 @cd ${top_srcdir} && python config/pandora-plugin plugin-list
605
606# Plugins affect configure; so to prevent configure running twice in a tarball
607# build (once up front, once with the right list of plugins, we ship the
608# generated list of plugins and the housekeeping material for that list so it
609# is likewise not updated.
610EXTRA_DIST += \
611 config/pandora-plugin.am \
612 config/pandora-plugin.ac \
613 config/pandora-plugin \
614 config/pandora-plugin.ini
615
616
617# Seed the list of plugin LDADDS which plugins may extend.
618PANDORA_DYNAMIC_LDADDS=
619
620# plugin.stamp: graph dominator for creating all per pandora-plugin.ac/am
621# files. This is invoked when the code to generate such files has altered.""")
622
623if not os.path.exists("config/pandora-plugin.ac") or "write" in actions:
624 plugin_ac_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.ac'))
625 plugin_ac_file.write("dnl Generated file, run make to rebuild\n")
626
627
628if os.path.exists('plugin.ini'):
629 # Are we in a plugin dir which wants to have a self-sufficient build system?
630 plugin_list=['.']
631
632 write_external_plugin()
633else:
634 plugin_list_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.list'))
635 for p in plugin_list:
636 plugin_list_file.write(p)
637 plugin_list_file.write("\n")
638 plugin_list.sort()
639 plugin_list_file.close()
640
641if not os.path.exists("config/pandora-plugin.am") or 'write' in actions:
642 plugin_am_file.write("\n${top_srcdir}/config/pandora-plugin.am: ${top_srcdir}/config/pandora-plugin.list ${top_srcdir}/config/pandora-plugin ")
643 for plugin_dir in plugin_list:
644 plugin_am_file.write("\\\n\t%s/plugin.ini " % plugin_dir)
645 plugin_am_file.write("\n\tcd ${top_srcdir} && python config/pandora-plugin write\n")
646 plugin_ini_list=[]
647
648 # Load all plugin.ini files first so we can do dependency tracking.
649 for plugin_dir in plugin_list:
650 plugin = read_plugin_ini(plugin_dir)
651 expand_plugin_ini(plugin)
652 plugin_ini_list.append(plugin)
653
654 # Check for duplicates
655 plugin_name_list = [plugin['libname'] for plugin in plugin_ini_list]
656 for plugin in plugin_ini_list:
657 if plugin_name_list.count(plugin['libname']) != 1:
658 print "Duplicate module name %s" % plugin['libname']
659 exit(1)
660
661 for plugin in plugin_ini_list:
662 write_plugin(plugin, plugin_ini_list)
663
664if plugin_am_file is not None:
665 plugin_am_file.close()
666if plugin_ac_file is not None:
667 plugin_ac_file.close()
0668
=== added file 'config/uncrustify.cfg'
--- config/uncrustify.cfg 1970-01-01 00:00:00 +0000
+++ config/uncrustify.cfg 2010-07-01 01:31:26 +0000
@@ -0,0 +1,1112 @@
1#
2# Uncrustify options (with comments) for Pandora Projects
3#
4
5nl_after_brace_close = TRUE
6
7# The type of line endings
8newlines = lf # auto/lf/crlf/cr
9
10# The original size of tabs in the input
11input_tab_size = 8 # number
12
13# The size of tabs in the output (only used if align_with_tabs=true)
14output_tab_size = 3 # number
15
16# The ascii value of the string escape char, usually 92 (\) or 94 (^). (Pawn)
17string_escape_char = 92 # number
18
19# Alternate string escape char for Pawn. Only works right before the quote char.
20string_escape_char2 = 0 # number
21
22#
23# Indenting
24#
25
26# The number of columns to indent per level.
27# Usually 2, 3, 4, or 8.
28indent_columns = 2 # number
29
30# How to use tabs when indenting code
31# 0=spaces only
32# 1=indent with tabs, align with spaces
33# 2=indent and align with tabs
34indent_with_tabs = 0 # number
35
36# Whether to indent strings broken by '\' so that they line up
37indent_align_string = true # false/true
38
39# The number of spaces to indent multi-line XML strings.
40# Requires indent_align_string=True
41indent_xml_string = 0 # number
42
43# Spaces to indent '{' from level
44indent_brace = 0 # number
45
46# Whether braces are indented to the body level
47indent_braces = false # false/true
48
49# Disabled indenting function braces if indent_braces is true
50indent_braces_no_func = false # false/true
51
52# Indent based on the size of the brace parent, ie 'if' => 3 spaces, 'for' => 4 spaces, etc.
53indent_brace_parent = false # false/true
54
55# Whether the 'namespace' body is indented
56indent_namespace = false # false/true
57
58# Whether the 'extern "C"' body is indented
59indent_extern = false # false/true
60
61# Whether the 'class' body is indented
62indent_class = true # false/true
63
64# Whether to indent the stuff after a leading class colon
65indent_class_colon = true # false/true
66
67# False=treat 'else\nif' as 'else if' for indenting purposes
68# True=indent the 'if' one level
69indent_else_if = false # false/true
70
71# True: indent continued function call parameters one indent level
72# False: align parameters under the open paren
73indent_func_call_param = false # false/true
74
75# Same as indent_func_call_param, but for function defs
76indent_func_def_param = false # false/true
77
78# Same as indent_func_call_param, but for function protos
79indent_func_proto_param = false # false/true
80
81# Same as indent_func_call_param, but for class declarations
82indent_func_class_param = false # false/true
83
84# Same as indent_func_call_param, but for class variable constructors
85indent_func_ctor_var_param = false # false/true
86
87# Same as indent_func_call_param, but for templates
88indent_template_param = false # false/true
89
90# Double the indent for indent_func_xxx_param options
91indent_func_param_double = false # false/true
92
93# Indentation column for standalone 'const' function decl/proto qualifier
94indent_func_const = 0 # number
95
96# Indentation column for standalone 'throw' function decl/proto qualifier
97indent_func_throw = 0 # number
98
99# The number of spaces to indent a continued '->' or '.'
100# Usually set to 0, 1, or indent_columns.
101indent_member = 3 # number
102
103# Spaces to indent single line ('//') comments on lines before code
104indent_sing_line_comments = 0 # number
105
106# If set, will indent trailing single line ('//') comments relative
107# to the code instead of trying to keep the same absolute column
108indent_relative_single_line_comments = false # false/true
109
110# Spaces to indent 'case' from 'switch'
111# Usually 0 or indent_columns.
112indent_switch_case = 0 # number
113
114# Spaces to shift the 'case' line, without affecting any other lines
115# Usually 0.
116indent_case_shift = 0 # number
117
118# Spaces to indent '{' from 'case'.
119# By default, the brace will appear under the 'c' in case.
120# Usually set to 0 or indent_columns.
121indent_case_brace = 0 # number
122
123# Whether to indent comments found in first column
124indent_col1_comment = false # false/true
125
126# How to indent goto labels
127# >0 : absolute column where 1 is the leftmost column
128# <=0 : subtract from brace indent
129indent_label = 1 # number
130
131# Same as indent_label, but for access specifiers that are followed by a colon
132indent_access_spec = 1 # number
133
134# Indent the code after an access specifier by one level.
135# If set, this option forces 'indent_access_spec=0'
136indent_access_spec_body = false # false/true
137
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)
139indent_paren_nl = false # false/true
140
141# Controls the indent of a close paren after a newline.
142# 0: Indent to body level
143# 1: Align under the open paren
144# 2: Indent to the brace level
145indent_paren_close = 0 # number
146
147# Controls the indent of a comma when inside a paren.If TRUE, aligns under the open paren
148indent_comma_paren = false # false/true
149
150# Controls the indent of a BOOL operator when inside a paren.If TRUE, aligns under the open paren
151indent_bool_paren = false # false/true
152
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)
154indent_square_nl = false # false/true
155
156# Don't change the relative indent of ESQL/C 'EXEC SQL' bodies
157indent_preserve_sql = false # false/true
158
159#
160# Spacing options
161#
162
163# Add or remove space around arithmetic operator '+', '-', '/', '*', etc
164sp_arith = force # ignore/add/remove/force
165
166# Add or remove space before assignment operator '=', '+=', etc
167sp_before_assign = remove # ignore/add/remove/force
168
169# Add or remove space after assignment operator '=', '+=', etc
170sp_after_assign = force # ignore/add/remove/force
171
172# Add or remove space around assignment '=' in enum
173sp_enum_assign = ignore # ignore/add/remove/force
174
175# Add or remove space around boolean operators '&&' and '||'
176sp_bool = force # ignore/add/remove/force
177
178# Add or remove space around compare operator '<', '>', '==', etc
179sp_compare = force # ignore/add/remove/force
180
181# Add or remove space inside '(' and ')'
182sp_inside_paren = remove # ignore/add/remove/force
183
184# Add or remove space between nested parens
185sp_paren_paren = remove # ignore/add/remove/force
186
187# Whether to balance spaces inside nested parens
188sp_balance_nested_parens = false # false/true
189
190# Add or remove space between ')' and '{'
191sp_paren_brace = ignore # ignore/add/remove/force
192
193# Add or remove space before pointer star '*'
194sp_before_ptr_star = force # ignore/add/remove/force
195
196# Add or remove space before pointer star '*' that isn't followed by a variable name
197# If set to 'ignore', sp_before_ptr_star is used instead.
198sp_before_unnamed_ptr_star = ignore # ignore/add/remove/force
199
200# Add or remove space between pointer stars '*'
201sp_between_ptr_star = remove # ignore/add/remove/force
202
203# Add or remove space after pointer star '*', if followed by a word.
204sp_after_ptr_star = remove # ignore/add/remove/force
205
206# Add or remove space after a pointer star '*', if followed by a func proto/def.
207sp_after_ptr_star_func = ignore # ignore/add/remove/force
208
209# Add or remove space before a pointer star '*', if followed by a func proto/def.
210sp_before_ptr_star_func = ignore # ignore/add/remove/force
211
212# Add or remove space before a reference sign '&'
213sp_before_byref = remove # ignore/add/remove/force
214
215# Add or remove space before a reference sign '&' that isn't followed by a variable name
216# If set to 'ignore', sp_before_byref is used instead.
217sp_before_unnamed_byref = ignore # ignore/add/remove/force
218
219# Add or remove space after reference sign '&', if followed by a word.
220sp_after_byref = force # ignore/add/remove/force
221
222# Add or remove space after a reference sign '&', if followed by a func proto/def.
223sp_after_byref_func = ignore # ignore/add/remove/force
224
225# Add or remove space before a reference sign '&', if followed by a func proto/def.
226sp_before_byref_func = ignore # ignore/add/remove/force
227
228# Add or remove space between type and word
229sp_after_type = force # ignore/add/remove/force
230
231# Add or remove space in 'template <' vs 'template<'.
232# If set to ignore, sp_before_angle is used.
233sp_template_angle = ignore # ignore/add/remove/force
234
235# Add or remove space before '<>'
236sp_before_angle = remove # ignore/add/remove/force
237
238# Add or remove space inside '<' and '>'
239sp_inside_angle = remove # ignore/add/remove/force
240
241# Add or remove space after '<>'
242sp_after_angle = force # ignore/add/remove/force
243
244# Add or remove space between '<>' and '(' as found in 'new List<byte>();'
245sp_angle_paren = ignore # ignore/add/remove/force
246
247# Add or remove space between '<>' and a word as in 'List<byte> m;'
248sp_angle_word = ignore # ignore/add/remove/force
249
250# Add or remove space before '(' of 'if', 'for', 'switch', and 'while'
251sp_before_sparen = force # ignore/add/remove/force
252
253# Add or remove space inside if-condition '(' and ')'
254sp_inside_sparen = remove # ignore/add/remove/force
255
256# Add or remove space after ')' of 'if', 'for', 'switch', and 'while'
257sp_after_sparen = force # ignore/add/remove/force
258
259# Add or remove space between ')' and '{' of 'if', 'for', 'switch', and 'while'
260sp_sparen_brace = add # ignore/add/remove/force
261
262# Add or remove space before empty statement ';' on 'if', 'for' and 'while'
263sp_special_semi = ignore # ignore/add/remove/force
264
265# Add or remove space before ';'
266sp_before_semi = remove # ignore/add/remove/force
267
268# Add or remove space before ';' in non-empty 'for' statements
269sp_before_semi_for = ignore # ignore/add/remove/force
270
271# Add or remove space before a semicolon of an empty part of a for statment.
272sp_before_semi_for_empty = force # ignore/add/remove/force
273
274# Add or remove space after the final semicolon of an empty part of a for statment: for ( ; ; <here> ).
275sp_after_semi_for_empty = ignore # ignore/add/remove/force
276
277# Add or remove space before '[' (except '[]')
278sp_before_square = ignore # ignore/add/remove/force
279
280# Add or remove space before '[]'
281sp_before_squares = ignore # ignore/add/remove/force
282
283# Add or remove space inside '[' and ']'
284sp_inside_square = remove # ignore/add/remove/force
285
286# Add or remove space after ','
287sp_after_comma = force # ignore/add/remove/force
288
289# Add or remove space before ','
290sp_before_comma = remove # ignore/add/remove/force
291
292# Add or remove space after class ':'
293sp_after_class_colon = ignore # ignore/add/remove/force
294
295# Add or remove space before class ':'
296sp_before_class_colon = ignore # ignore/add/remove/force
297
298# Add or remove space between 'operator' and operator sign
299sp_after_operator = ignore # ignore/add/remove/force
300
301# Add or remove space between the operator symbol and the open paren, as in 'operator ++('
302sp_after_operator_sym = ignore # ignore/add/remove/force
303
304# Add or remove space after C/D cast, ie 'cast(int)a' vs 'cast(int) a' or '(int)a' vs '(int) a'
305sp_after_cast = remove # ignore/add/remove/force
306
307# Add or remove spaces inside cast parens
308sp_inside_paren_cast = remove # ignore/add/remove/force
309
310# Add or remove space between the type and open paren in a C++ cast, ie 'int(exp)' vs 'int (exp)'
311sp_cpp_cast_paren = remove # ignore/add/remove/force
312
313# Add or remove space between 'sizeof' and '('
314sp_sizeof_paren = remove # ignore/add/remove/force
315
316# Add or remove space after the tag keyword (Pawn)
317sp_after_tag = ignore # ignore/add/remove/force
318
319# Add or remove space inside enum '{' and '}'
320sp_inside_braces_enum = force # ignore/add/remove/force
321
322# Add or remove space inside struct/union '{' and '}'
323sp_inside_braces_struct = force # ignore/add/remove/force
324
325# Add or remove space inside '{' and '}'
326sp_inside_braces = force # ignore/add/remove/force
327
328# Add or remove space inside '{}'
329sp_inside_braces_empty = ignore # ignore/add/remove/force
330
331# Add or remove space between return type and function name
332# A minimum of 1 is forced except for pointer return types.
333sp_type_func = force # ignore/add/remove/force
334
335# Add or remove space between function name and '(' on function declaration
336sp_func_proto_paren = remove # ignore/add/remove/force
337
338# Add or remove space between function name and '(' on function definition
339sp_func_def_paren = remove # ignore/add/remove/force
340
341# Add or remove space inside empty function '()'
342sp_inside_fparens = ignore # ignore/add/remove/force
343
344# Add or remove space inside function '(' and ')'
345sp_inside_fparen = remove # ignore/add/remove/force
346
347# Add or remove space between ']' and '(' when part of a function call.
348sp_square_fparen = ignore # ignore/add/remove/force
349
350# Add or remove space between ')' and '{' of function
351sp_fparen_brace = add # ignore/add/remove/force
352
353# Add or remove space between function name and '(' on function calls
354sp_func_call_paren = remove # ignore/add/remove/force
355
356# Add or remove space between the user function name and '(' on function calls
357# You need to set a keyword to be a user function, like this: 'set func_call_user _' in the config file.
358sp_func_call_user_paren = ignore # ignore/add/remove/force
359
360# Add or remove space between a constructor/destructor and the open paren
361sp_func_class_paren = remove # ignore/add/remove/force
362
363# Add or remove space between 'return' and '('
364sp_return_paren = remove # ignore/add/remove/force
365
366# Add or remove space between '__attribute__' and '('
367sp_attribute_paren = remove # ignore/add/remove/force
368
369# Add or remove space between 'defined' and '(' in '#if defined (FOO)'
370sp_defined_paren = remove # ignore/add/remove/force
371
372# Add or remove space between 'throw' and '(' in 'throw (something)'
373sp_throw_paren = ignore # ignore/add/remove/force
374
375# Add or remove space between macro and value
376sp_macro = ignore # ignore/add/remove/force
377
378# Add or remove space between macro function ')' and value
379sp_macro_func = ignore # ignore/add/remove/force
380
381# Add or remove space between 'else' and '{' if on the same line
382sp_else_brace = ignore # ignore/add/remove/force
383
384# Add or remove space between '}' and 'else' if on the same line
385sp_brace_else = ignore # ignore/add/remove/force
386
387# Add or remove space between '}' and the name of a typedef on the same line
388sp_brace_typedef = force # ignore/add/remove/force
389
390# Add or remove space between 'catch' and '{' if on the same line
391sp_catch_brace = ignore # ignore/add/remove/force
392
393# Add or remove space between '}' and 'catch' if on the same line
394sp_brace_catch = ignore # ignore/add/remove/force
395
396# Add or remove space between 'finally' and '{' if on the same line
397sp_finally_brace = ignore # ignore/add/remove/force
398
399# Add or remove space between '}' and 'finally' if on the same line
400sp_brace_finally = ignore # ignore/add/remove/force
401
402# Add or remove space between 'try' and '{' if on the same line
403sp_try_brace = ignore # ignore/add/remove/force
404
405# Add or remove space between get/set and '{' if on the same line
406sp_getset_brace = ignore # ignore/add/remove/force
407
408# Add or remove space before the '::' operator
409sp_before_dc = remove # ignore/add/remove/force
410
411# Add or remove space after the '::' operator
412sp_after_dc = remove # ignore/add/remove/force
413
414# Add or remove around the D named array initializer ':' operator
415sp_d_array_colon = ignore # ignore/add/remove/force
416
417# Add or remove space after the '!' (not) operator.
418sp_not = force # ignore/add/remove/force
419
420# Add or remove space after the '~' (invert) operator.
421sp_inv = remove # ignore/add/remove/force
422
423# Add or remove space after the '&' (address-of) operator.
424# This does not affect the spacing after a '&' that is part of a type.
425sp_addr = remove # ignore/add/remove/force
426
427# Add or remove space around the '.' or '->' operators
428sp_member = remove # ignore/add/remove/force
429
430# Add or remove space after the '*' (dereference) operator.
431# This does not affect the spacing after a '*' that is part of a type.
432sp_deref = remove # ignore/add/remove/force
433
434# Add or remove space after '+' or '-', as in 'x = -5' or 'y = +7'
435sp_sign = remove # ignore/add/remove/force
436
437# Add or remove space before or after '++' and '--', as in '(--x)' or 'y++;'
438sp_incdec = remove # ignore/add/remove/force
439
440# Add or remove space before a backslash-newline at the end of a line
441sp_before_nl_cont = add # ignore/add/remove/force
442
443# Add or remove space after the scope '+' or '-', as in '-(void) foo;' or '+(int) bar;'
444sp_after_oc_scope = ignore # ignore/add/remove/force
445
446# Add or remove space after the colon in message specs
447# '-(int) f:(int) x;' vs '-(int) f: (int) x;'
448sp_after_oc_colon = ignore # ignore/add/remove/force
449
450# Add or remove space before the colon in message specs
451# '-(int) f: (int) x;' vs '-(int) f : (int) x;'
452sp_before_oc_colon = ignore # ignore/add/remove/force
453
454# Add or remove space after the colon in message specs
455# '[object setValue:1];' vs '[object setValue: 1];'
456sp_after_send_oc_colon = ignore # ignore/add/remove/force
457
458# Add or remove space before the colon in message specs
459# '[object setValue:1];' vs '[object setValue :1];'
460sp_before_send_oc_colon = ignore # ignore/add/remove/force
461
462# Add or remove space after the (type) in message specs
463# '-(int) f: (int) x;' vs '-(int) f: (int)x;'
464sp_after_oc_type = ignore # ignore/add/remove/force
465
466# Add or remove space around the ':' in 'b ? t : f'
467sp_cond_colon = ignore # ignore/add/remove/force
468
469# Add or remove space around the '?' in 'b ? t : f'
470sp_cond_question = ignore # ignore/add/remove/force
471
472# Fix the spacing between 'case' and the label. Only 'ignore' and 'force' make sense here.
473sp_case_label = remove # ignore/add/remove/force
474
475#
476# Code alignment (not left column spaces/tabs)
477#
478
479# Whether to keep non-indenting tabs
480align_keep_tabs = false # false/true
481
482# Whether to use tabs for alinging
483align_with_tabs = false # false/true
484
485# Whether to bump out to the next tab when aligning
486align_on_tabstop = false # false/true
487
488# Whether to left-align numbers
489align_number_left = false # false/true
490
491# Align variable definitions in prototypes and functions
492align_func_params = false # false/true
493
494# Align parameters in single-line functions that have the same name.
495# The function names must already be aligned with each other.
496align_same_func_call_params = false # false/true
497
498# The span for aligning variable definitions (0=don't align)
499align_var_def_span = 1 # number
500
501# How to align the star in variable definitions.
502# 0=Part of the type 'void * foo;'
503# 1=Part of the variable 'void *foo;'
504# 2=Dangling 'void *foo;'
505align_var_def_star_style = 1 # number
506
507# How to align the '&' in variable definitions.
508# 0=Part of the type
509# 1=Part of the variable
510# 2=Dangling
511align_var_def_amp_style = 0 # number
512
513# The threshold for aligning variable definitions (0=no limit)
514align_var_def_thresh = 1 # number
515
516# The gap for aligning variable definitions
517align_var_def_gap = 0 # number
518
519# Whether to align the colon in struct bit fields
520align_var_def_colon = false # false/true
521
522# Whether to align inline struct/enum/union variable definitions
523align_var_def_inline = false # false/true
524
525# The span for aligning on '=' in assignments (0=don't align)
526align_assign_span = 0 # number
527
528# The threshold for aligning on '=' in assignments (0=no limit)
529align_assign_thresh = 12 # number
530
531# The span for aligning on '=' in enums (0=don't align)
532align_enum_equ_span = 0 # number
533
534# The threshold for aligning on '=' in enums (0=no limit)
535align_enum_equ_thresh = 0 # number
536
537# The span for aligning struct/union (0=don't align)
538align_var_struct_span = 0 # number
539
540# The threshold for aligning struct/union member definitions (0=no limit)
541align_var_struct_thresh = 0 # number
542
543# The gap for aligning struct/union member definitions
544align_var_struct_gap = 0 # number
545
546# The span for aligning struct initializer values (0=don't align)
547align_struct_init_span = 3 # number
548
549# The minimum space between the type and the synonym of a typedef
550align_typedef_gap = 3 # number
551
552# The span for aligning single-line typedefs (0=don't align)
553align_typedef_span = 5 # number
554
555# How to align typedef'd functions with other typedefs
556# 0: Don't mix them at all
557# 1: align the open paren with the types
558# 2: align the function type name with the other type names
559align_typedef_func = 0 # number
560
561# Controls the positioning of the '*' in typedefs. Just try it.
562# 0: Align on typdef type, ignore '*'
563# 1: The '*' is part of type name: typedef int *pint;
564# 2: The '*' is part of the type, but dangling: typedef int *pint;
565align_typedef_star_style = 0 # number
566
567# Controls the positioning of the '&' in typedefs. Just try it.
568# 0: Align on typdef type, ignore '&'
569# 1: The '&' is part of type name: typedef int &pint;
570# 2: The '&' is part of the type, but dangling: typedef int &pint;
571align_typedef_amp_style = 0 # number
572
573# The span for aligning comments that end lines (0=don't align)
574align_right_cmt_span = 3 # number
575
576# If aligning comments, mix with comments after '}' and #endif with less than 3 spaces before the comment
577align_right_cmt_mix = false # false/true
578
579# If a trailing comment is more than this number of columns away from the text it follows,
580# it will qualify for being aligned.
581align_right_cmt_gap = 0 # number
582
583# The span for aligning function prototypes (0=don't align)
584align_func_proto_span = 0 # number
585
586# Minimum gap between the return type and the function name.
587align_func_proto_gap = 0 # number
588
589# Whether to mix aligning prototype and variable declarations.
590# If true, align_var_def_XXX options are used instead of align_func_proto_XXX options.
591align_mix_var_proto = false # false/true
592
593# Align single-line functions with function prototypes, uses align_func_proto_span
594align_single_line_func = false # false/true
595
596# Aligning the open brace of single-line functions.
597# Requires align_single_line_func=true, uses align_func_proto_span
598align_single_line_brace = false # false/true
599
600# Gap for align_single_line_brace.
601align_single_line_brace_gap = 0 # number
602
603# The span for aligning ObjC msg spec (0=don't align)
604align_oc_msg_spec_span = 0 # number
605
606# Whether to align macros wrapped with a backslash and a newline.
607# This will not work right if the macro contains a multi-line comment.
608align_nl_cont = true # false/true
609
610# The minimum space between label and value of a preprocessor define
611align_pp_define_gap = 4 # number
612
613# The span for aligning on '#define' bodies (0=don't align)
614align_pp_define_span = 3 # number
615
616# Align lines that start with '<<' with previous '<<'. Default=true
617align_left_shift = true # false/true
618
619#
620# Newline adding and removing options
621#
622
623# Whether to collapse empty blocks between '{' and '}'
624nl_collapse_empty_body = true # false/true
625
626# Don't split one-line braced assignments - 'foo_t f = { 1, 2 };'
627nl_assign_leave_one_liners = false # false/true
628
629# Don't split one-line braced statements inside a class xx { } body
630nl_class_leave_one_liners = false # false/true
631
632# Don't split one-line enums: 'enum foo { BAR = 15 };'
633nl_enum_leave_one_liners = false # false/true
634
635# Don't split one-line get or set functions
636nl_getset_leave_one_liners = false # false/true
637
638# Don't split one-line function definitions - 'int foo() { return 0; }'
639nl_func_leave_one_liners = false # false/true
640
641# Don't split one-line if/else statements - 'if(a) b++;'
642nl_if_leave_one_liners = false # false/true
643
644# Add or remove newlines at the start of the file
645nl_start_of_file = remove # ignore/add/remove/force
646
647# The number of newlines at the start of the file (only used if nl_start_of_file is 'add' or 'force'
648nl_start_of_file_min = 0 # number
649
650# Add or remove newline at the end of the file
651nl_end_of_file = force # ignore/add/remove/force
652
653# The number of newlines at the end of the file (only used if nl_end_of_file is 'add' or 'force')
654nl_end_of_file_min = 1 # number
655
656# Add or remove newline between '=' and '{'
657nl_assign_brace = force # ignore/add/remove/force
658
659# Add or remove newline between '=' and '[' (D only)
660nl_assign_square = force # ignore/add/remove/force
661
662# Add or remove newline after '= [' (D only). Will also affect the newline before the ']'
663nl_after_square_assign = force # ignore/add/remove/force
664
665# The number of newlines after a block of variable definitions
666nl_func_var_def_blk = 1 # number
667
668# Add or remove newline between a function call's ')' and '{', as in:
669# list_for_each(item, &list) { }
670nl_fcall_brace = force # ignore/add/remove/force
671
672# Add or remove newline between 'enum' and '{'
673nl_enum_brace = force # ignore/add/remove/force
674
675# Add or remove newline between 'struct and '{'
676nl_struct_brace = force # ignore/add/remove/force
677
678# Add or remove newline between 'union' and '{'
679nl_union_brace = force # ignore/add/remove/force
680
681# Add or remove newline between 'if' and '{'
682nl_if_brace = force # ignore/add/remove/force
683
684# Add or remove newline between '}' and 'else'
685nl_brace_else = force # ignore/add/remove/force
686
687# Add or remove newline between 'else if' and '{'
688# If set to ignore, nl_if_brace is used instead
689nl_elseif_brace = force # ignore/add/remove/force
690
691# Add or remove newline between 'else' and '{'
692nl_else_brace = force # ignore/add/remove/force
693
694# Add or remove newline between 'else' and 'if'
695nl_else_if = remove # ignore/add/remove/force
696
697# Add or remove newline between '}' and 'finally'
698nl_brace_finally = force # ignore/add/remove/force
699
700# Add or remove newline between 'finally' and '{'
701nl_finally_brace = force # ignore/add/remove/force
702
703# Add or remove newline between 'try' and '{'
704nl_try_brace = force # ignore/add/remove/force
705
706# Add or remove newline between get/set and '{'
707nl_getset_brace = force # ignore/add/remove/force
708
709# Add or remove newline between 'for' and '{'
710nl_for_brace = force # ignore/add/remove/force
711
712# Add or remove newline between 'catch' and '{'
713nl_catch_brace = force # ignore/add/remove/force
714
715# Add or remove newline between '}' and 'catch'
716nl_brace_catch = force # ignore/add/remove/force
717
718# Add or remove newline between 'while' and '{'
719nl_while_brace = force # ignore/add/remove/force
720
721# Add or remove newline between 'do' and '{'
722nl_do_brace = force # ignore/add/remove/force
723
724# Add or remove newline between '}' and 'while' of 'do' statement
725nl_brace_while = force # ignore/add/remove/force
726
727# Add or remove newline between 'switch' and '{'
728nl_switch_brace = force # ignore/add/remove/force
729
730# Add or remove newline when condition spans two or more lines
731nl_multi_line_cond = false # false/true
732
733# Force a newline in a define after the macro name for multi-line defines.
734nl_multi_line_define = true # false/true
735
736# Whether to put a newline before 'case' statement
737nl_before_case = true # false/true
738
739# Add or remove newline between ')' and 'throw'
740nl_before_throw = ignore # ignore/add/remove/force
741
742# Whether to put a newline after 'case' statement
743nl_after_case = true # false/true
744
745# Newline between namespace and {
746nl_namespace_brace = add # ignore/add/remove/force
747
748# Add or remove newline between 'template<>' and whatever follows.
749nl_template_class = add # ignore/add/remove/force
750
751# Add or remove newline between 'class' and '{'
752nl_class_brace = add # ignore/add/remove/force
753
754# Add or remove newline after each ',' in the constructor member initialization
755nl_class_init_args = force # ignore/add/remove/force
756
757# Add or remove newline between return type and function name in definition
758nl_func_type_name = ignore # ignore/add/remove/force
759
760# Add or remove newline between return type and function name in a prototype
761nl_func_proto_type_name = remove # ignore/add/remove/force
762
763# Add or remove newline between a function name and the opening '('
764nl_func_paren = remove # ignore/add/remove/force
765
766# Add or remove newline after '(' in a function declaration
767nl_func_decl_start = remove # ignore/add/remove/force
768
769# Add or remove newline after each ',' in a function declaration
770nl_func_decl_args = remove # ignore/add/remove/force
771
772# Add or remove newline before the ')' in a function declaration
773nl_func_decl_end = remove # ignore/add/remove/force
774
775# Add or remove newline between function signature and '{'
776nl_fdef_brace = add # ignore/add/remove/force
777
778# Whether to put a newline after 'return' statement
779nl_after_return = true # false/true
780
781# Add or remove a newline between the return keyword and return expression.
782nl_return_expr = remove # ignore/add/remove/force
783
784# Whether to put a newline after semicolons, except in 'for' statements
785nl_after_semicolon = true # false/true
786
787# Whether to put a newline after brace open.
788# This also adds a newline before the matching brace close.
789nl_after_brace_open = true # false/true
790
791# If nl_after_brace_open and nl_after_brace_open_cmt are true, a newline is
792# placed between the open brace and a trailing single-line comment.
793nl_after_brace_open_cmt = false # false/true
794
795# Whether to put a newline after a virtual brace open.
796# These occur in un-braced if/while/do/for statement bodies.
797nl_after_vbrace_open = true # false/true
798
799# Whether to alter newlines in '#define' macros
800nl_define_macro = true # false/true
801
802# Whether to not put blanks after '#ifxx', '#elxx', or before '#endif'
803nl_squeeze_ifdef = false # false/true
804
805# Add or remove newline before 'if'
806nl_before_if = ignore # ignore/add/remove/force
807
808# Add or remove newline after 'if'
809nl_after_if = ignore # ignore/add/remove/force
810
811# Add or remove newline before 'for'
812nl_before_for = ignore # ignore/add/remove/force
813
814# Add or remove newline after 'for'
815nl_after_for = ignore # ignore/add/remove/force
816
817# Add or remove newline before 'while'
818nl_before_while = ignore # ignore/add/remove/force
819
820# Add or remove newline after 'while'
821nl_after_while = ignore # ignore/add/remove/force
822
823# Add or remove newline before 'switch'
824nl_before_switch = force # ignore/add/remove/force
825
826# Add or remove newline after 'switch'
827nl_after_switch = force # ignore/add/remove/force
828
829# Add or remove newline before 'do'
830nl_before_do = ignore # ignore/add/remove/force
831
832# Add or remove newline after 'do'
833nl_after_do = ignore # ignore/add/remove/force
834
835# Whether to double-space commented-entries in struct/enum
836nl_ds_struct_enum_cmt = false # false/true
837
838# Whether to double-space before the close brace of a struct/union/enum
839nl_ds_struct_enum_close_brace = false # false/true
840
841# Add or remove a newline around a class colon.
842# Related to pos_class_colon, nl_class_init_args, and pos_comma.
843nl_class_colon = ignore # ignore/add/remove/force
844
845# Change simple unbraced if statements into a one-liner
846# 'if(b)\n i++;' => 'if(b) i++;'
847nl_create_if_one_liner = false # false/true
848
849# Change simple unbraced for statements into a one-liner
850# 'for (i=0;i<5;i++)\n foo(i);' => 'for (i=0;i<5;i++) foo(i);'
851nl_create_for_one_liner = false # false/true
852
853# Change simple unbraced while statements into a one-liner
854# 'while (i<5)\n foo(i++);' => 'while (i<5) foo(i++);'
855nl_create_while_one_liner = false # false/true
856
857#
858# Positioning options
859#
860
861# The position of arithmetic operators in wrapped expressions
862pos_arith = lead # ignore/lead/trail
863
864# The position of assignment in wrapped expressions
865pos_assign = trail # ignore/lead/trail
866
867# The position of boolean operators in wrapped expressions
868pos_bool = lead # ignore/lead/trail
869
870# The position of the comma in wrapped expressions
871pos_comma = trail # ignore/lead/trail
872
873# The position of the comma in the constructor initialization list
874pos_class_comma = trail # ignore/lead/trail
875
876# The position of colons between constructor and member initialization
877pos_class_colon = lead # ignore/lead/trail
878
879#
880# Line Splitting options
881#
882
883# Try to limit code width to N number of columns
884code_width = 76 # number
885
886# Whether to fully split long 'for' statements at semi-colons
887ls_for_split_full = true # false/true
888
889# Whether to fully split long function protos/calls at commas
890ls_func_split_full = true # false/true
891
892#
893# Blank line options
894#
895
896# The maximum consecutive newlines
897nl_max = 4 # number
898
899# The number of newlines after a function prototype, if followed by another function prototype
900nl_after_func_proto = 0 # number
901
902# The number of newlines after a function prototype, if not followed by another function prototype
903nl_after_func_proto_group = 3 # number
904
905# The number of newlines after '}' of a multi-line function body
906nl_after_func_body = 3 # number
907
908# The number of newlines after '}' of a single line function body
909nl_after_func_body_one_liner = 1 # number
910
911# The minimum number of newlines before a multi-line comment.
912# Doesn't apply if after a brace open or another multi-line comment.
913nl_before_block_comment = 2 # number
914
915# The minimum number of newlines before a single-line C comment.
916# Doesn't apply if after a brace open or other single-line C comments.
917nl_before_c_comment = 1 # number
918
919# The minimum number of newlines before a CPP comment.
920# Doesn't apply if after a brace open or other CPP comments.
921nl_before_cpp_comment = 0 # number
922
923# Whether to force a newline after a mulit-line comment.
924nl_after_multiline_comment = false # false/true
925
926# The number of newlines before a 'private:', 'public:', 'protected:', 'signals:', or 'slots:' label.
927# Will not change the newline count if after a brace open.
928# 0 = No change.
929nl_before_access_spec = 1 # number
930
931# The number of newlines after a 'private:', 'public:', 'protected:', 'signals:', or 'slots:' label.
932# 0 = No change.
933nl_after_access_spec = 1 # number
934
935# The number of newlines between a function def and the function comment.
936# 0 = No change.
937nl_comment_func_def = 0 # number
938
939# Whether to remove blank lines after '{'
940eat_blanks_after_open_brace = true # false/true
941
942# Whether to remove blank lines before '}'
943eat_blanks_before_close_brace = true # false/true
944
945#
946# Code modifying options (non-whitespace)
947#
948
949# Add or remove braces on single-line 'do' statement
950mod_full_brace_do = add # ignore/add/remove/force
951
952# Add or remove braces on single-line 'for' statement
953mod_full_brace_for = add # ignore/add/remove/force
954
955# Add or remove braces on single-line function defintions. (Pawn)
956mod_full_brace_function = ignore # ignore/add/remove/force
957
958# Add or remove braces on single-line 'if' statement. Will not remove the braces if they contain an 'else'.
959mod_full_brace_if = ignore # ignore/add/remove/force
960
961# Don't remove braces around statements that span N newlines
962mod_full_brace_nl = 0 # number
963
964# Add or remove braces on single-line 'while' statement
965mod_full_brace_while = add # ignore/add/remove/force
966
967# Add or remove unnecessary paren on 'return' statement
968mod_paren_on_return = remove # ignore/add/remove/force
969
970# Whether to change optional semicolons to real semicolons
971mod_pawn_semicolon = false # false/true
972
973# Add parens on 'while' and 'if' statement around bools
974mod_full_paren_if_bool = true # false/true
975
976# Whether to remove superfluous semicolons
977mod_remove_extra_semicolon = true # false/true
978
979# If a function body exceeds the specified number of newlines and doesn't have a comment after
980# the close brace, a comment will be added.
981mod_add_long_function_closebrace_comment = 5 # number
982
983# If a switch body exceeds the specified number of newlines and doesn't have a comment after
984# the close brace, a comment will be added.
985mod_add_long_switch_closebrace_comment = 5 # number
986
987# If TRUE, will sort consecutive single-line 'import' statements [Java, D]
988mod_sort_import = false # false/true
989
990# If TRUE, will sort consecutive single-line 'using' statements [C#]
991mod_sort_using = false # false/true
992
993# If TRUE, will sort consecutive single-line '#include' statements [C/C++] and '#import' statements [Obj-C]
994# This is generally a bad idea, as it may break your code.
995mod_sort_include = false # false/true
996
997# If TRUE, it will move a 'break' that appears after a fully braced 'case' before the close brace.
998mod_move_case_break = false # false/true
999
1000# If TRUE, it will remove a void 'return;' that appears as the last statement in a function.
1001mod_remove_empty_return = true # false/true
1002
1003#
1004# Comment modifications
1005#
1006
1007# Try to wrap comments at cmt_width columns
1008cmt_width = 0 # number
1009
1010# If false, disable all multi-line comment changes, including cmt_width and leading chars.
1011# Default is true.
1012cmt_indent_multi = true # false/true
1013
1014# Whether to group c-comments that look like they are in a block
1015cmt_c_group = false # false/true
1016
1017# Whether to put an empty '/*' on the first line of the combined c-comment
1018cmt_c_nl_start = false # false/true
1019
1020# Whether to put a newline before the closing '*/' of the combined c-comment
1021cmt_c_nl_end = false # false/true
1022
1023# Whether to group cpp-comments that look like they are in a block
1024cmt_cpp_group = false # false/true
1025
1026# Whether to put an empty '/*' on the first line of the combined cpp-comment
1027cmt_cpp_nl_start = false # false/true
1028
1029# Whether to put a newline before the closing '*/' of the combined cpp-comment
1030cmt_cpp_nl_end = false # false/true
1031
1032# Whether to change cpp-comments into c-comments
1033cmt_cpp_to_c = false # false/true
1034
1035# Whether to put a star on subsequent comment lines
1036cmt_star_cont = true # false/true
1037
1038# The number of spaces to insert at the start of subsequent comment lines
1039cmt_sp_before_star_cont = 0 # number
1040
1041# The number of spaces to insert after the star on subsequent comment lines
1042cmt_sp_after_star_cont = 1 # number
1043
1044# For multi-line comments with a '*' lead, remove leading spaces if the first and last lines of
1045# the comment are the same length. Default=True
1046cmt_multi_check_last = true # false/true
1047
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.
1049# Will substitue $(filename) with the current file's name.
1050cmt_insert_file_header = "" # string
1051
1052# The filename that contains text to insert before a function implementation if the function isn't preceeded with a C/C++ comment.
1053# Will substitue $(function) with the function name and $(javaparam) with the javadoc @param and @return stuff.
1054# Will also substitute $(fclass) with the class name: void CFoo::Bar() { ... }
1055cmt_insert_func_header = "" # string
1056
1057# The filename that contains text to insert before a class if the class isn't preceeded with a C/C++ comment.
1058# Will substitue $(class) with the class name.
1059cmt_insert_class_header = "" # string
1060
1061# If a preprocessor is encountered when stepping backwards from a function name, then
1062# this option decides whether the comment should be inserted.
1063# Affects cmt_insert_func_header and cmt_insert_class_header.
1064cmt_insert_before_preproc = false # false/true
1065
1066#
1067# Preprocessor options
1068#
1069
1070# Control indent of preprocessors inside #if blocks at brace level 0
1071pp_indent = remove # ignore/add/remove/force
1072
1073# Whether to indent #if/#else/#endif at the brace level (true) or from column 1 (false)
1074pp_indent_at_level = false # false/true
1075
1076# If pp_indent_at_level=false, specifies the number of columns to indent per level. Default=1.
1077pp_indent_count = 1 # number
1078
1079# Add or remove space after # based on pp_level of #if blocks
1080pp_space = add # ignore/add/remove/force
1081
1082# Sets the number of spaces added with pp_space
1083pp_space_count = 1 # number
1084
1085# The indent for #region and #endregion in C# and '#pragma region' in C/C++
1086pp_indent_region = 0 # number
1087
1088# Whether to indent the code between #region and #endregion
1089pp_region_indent_code = false # false/true
1090
1091# If pp_indent_at_level=true, sets the indent for #if, #else, and #endif when not at file-level
1092pp_indent_if = 0 # number
1093
1094# Control whether to indent the code between #if, #else and #endif when not at file-level
1095pp_if_indent_code = false # false/true
1096
1097# Whether to indent '#define' at the brace level (true) or from column 1 (false)
1098pp_define_at_level = false # false/true
1099
1100# You can force a token to be a type with the 'type' option.
1101# Example:
1102# type myfoo1 myfoo2
1103#
1104# You can create custom macro-based indentation using macro-open,
1105# macro-else and macro-close.
1106# Example:
1107# macro-open BEGIN_TEMPLATE_MESSAGE_MAP
1108# macro-open BEGIN_MESSAGE_MAP
1109# macro-close END_MESSAGE_MAP
1110#
1111# You can assign any keyword to any type with the set option.
1112# set func_call_user _ N_
01113
=== modified file 'configure.ac'
--- configure.ac 2010-06-30 18:41:07 +0000
+++ configure.ac 2010-07-01 01:31:26 +0000
@@ -6,11 +6,15 @@
6# the COPYING file in this directory for full text.6# the COPYING file in this directory for full text.
77
8AC_PREREQ(2.59)8AC_PREREQ(2.59)
9<<<<<<< TREE
9AC_INIT([gearmand],[0.14],[https://launchpad.net/gearmand])10AC_INIT([gearmand],[0.14],[https://launchpad.net/gearmand])
11=======
12AC_INIT([gearmand],[1.00],[https://launchpad.net/gearmand])
13>>>>>>> MERGE-SOURCE
10AC_CONFIG_SRCDIR(libgearman/gearman.c)14AC_CONFIG_SRCDIR(libgearman/gearman.c)
11AC_CONFIG_AUX_DIR(config)15AC_CONFIG_AUX_DIR(config)
1216
13PANDORA_CANONICAL_TARGET(require-cxx)17PANDORA_CANONICAL_TARGET(require-cxx, less-warnings)
1418
15GEARMAN_LIBRARY_VERSION=4:0:019GEARMAN_LIBRARY_VERSION=4:0:0
16# | | |20# | | |
@@ -27,6 +31,9 @@
27AC_SUBST(GEARMAN_LIBRARY_VERSION)31AC_SUBST(GEARMAN_LIBRARY_VERSION)
2832
2933
34PANDORA_REQUIRE_BOOST
35PANDORA_REQUIRE_BOOST_PROGRAM_OPTIONS
36PANDORA_REQUIRE_BOOST_THREAD
30PANDORA_REQUIRE_PTHREAD37PANDORA_REQUIRE_PTHREAD
31PANDORA_REQUIRE_LIBEVENT38PANDORA_REQUIRE_LIBEVENT
32PANDORA_REQUIRE_LIBUUID39PANDORA_REQUIRE_LIBUUID
3340
=== renamed file 'gearmand/gearmand.c' => 'gearmand/gearmand.cc'
--- gearmand/gearmand.c 2010-02-02 00:43:22 +0000
+++ gearmand/gearmand.cc 2010-07-01 01:31:26 +0000
@@ -8,6 +8,9 @@
88
9#include "config.h"9#include "config.h"
1010
11#define __STDC_LIMIT_MACROS
12#define __STDC_FORMAT_MACROS
13
11#ifdef HAVE_ERRNO_H14#ifdef HAVE_ERRNO_H
12#include <errno.h>15#include <errno.h>
13#endif16#endif
@@ -53,428 +56,316 @@
53# endif56# endif
54#endif57#endif
5558
59#include <boost/program_options/options_description.hpp>
60#include <boost/program_options/parsers.hpp>
61#include <boost/program_options/variables_map.hpp>
62#include <boost/tokenizer.hpp>
63#include <boost/token_functions.hpp>
64using namespace boost;
65using namespace boost::program_options;
66
56#include <libgearman-server/gearmand.h>67#include <libgearman-server/gearmand.h>
5768
58#ifdef HAVE_LIBDRIZZLE69
59#include <libgearman-server/queue_libdrizzle.h>70#include <iostream>
60#endif71#include <fstream>
6172using namespace std;
62#ifdef HAVE_LIBMEMCACHED73
63#include <libgearman-server/queue_libmemcached.h>74#include <string>
64#endif75
6576using std::string;
66#ifdef HAVE_LIBSQLITE3
67#include <libgearman-server/queue_libsqlite3.h>
68#endif
69
70#ifdef HAVE_LIBPQ
71#include <libgearman-server/queue_libpq.h>
72#endif
73
74#ifdef HAVE_LIBTOKYOCABINET
75#include <libgearman-server/queue_libtokyocabinet.h>
76#endif
77
78#include <libgearman-server/protocol_http.h>
7977
80#define GEARMAND_LOG_REOPEN_TIME 6078#define GEARMAND_LOG_REOPEN_TIME 60
81#define GEARMAND_LISTEN_BACKLOG 3279#define GEARMAND_LISTEN_BACKLOG 32
8280
83typedef struct81struct gearmand_log_info_st
84{82{
85 const char *file;83 string file;
86 int fd;84 int fd;
87 time_t reopen;85 time_t reopen;
88} gearmand_log_info_st;86
87 gearmand_log_info_st() :
88 fd(-1),
89 reopen(0)
90 {}
91
92 ~gearmand_log_info_st() {}
93
94};
8995
90static gearmand_st *_gearmand;96static gearmand_st *_gearmand;
9197
92static bool _set_fdlimit(rlim_t fds);98static bool _set_fdlimit(rlim_t fds);
93static bool _pid_write(const char *pid_file);99static bool _pid_write(const char *pid_file);
94static void _pid_delete(const char *pid_file);100static void _pid_delete(const char *pid_file);
95static bool _switch_user(const char *user);101static bool _switch_user(const string user);
96static bool _set_signals(void);102static bool _set_signals(void);
97static void _shutdown_handler(int signal_arg);103static void _shutdown_handler(int signal_arg);
98static void _log(const char *line, gearman_verbose_t verbose, void *context);104
99105
100int main(int argc, char *argv[])106int main(int argc, char *argv[])
101{107{
102 gearman_conf_st conf;108 options_description general("General options");
103 gearman_conf_module_st module;109
104 const char *name;
105 const char *value;
106 int backlog= GEARMAND_LISTEN_BACKLOG;110 int backlog= GEARMAND_LISTEN_BACKLOG;
107 rlim_t fds= 0;111 rlim_t fds= 0;
112 string pid_file;
108 uint8_t job_retries= 0;113 uint8_t job_retries= 0;
109 uint8_t worker_wakeup= 0;114 uint8_t worker_wakeup= 0;
110 in_port_t port= 0;115 in_port_t port;
111 const char *host= NULL;116 string host;
112 const char *pid_file= NULL;117 string queue_type;
113 const char *queue_type= NULL;118 uint32_t threads;
114 uint32_t threads= 0;119 string user;
115 const char *user= NULL;120 gearman_verbose_t verbose;
116 uint8_t verbose= 0;121 string verbose_string;
117 gearman_return_t ret;122 gearman_return_t ret;
118 gearmand_log_info_st log_info;123 gearmand_log_info_st log_info;
119 bool close_stdio= false;124 bool close_stdio= false;
120 int fd;125 string protocol;
121 bool round_robin= false;126 bool round_robin;
122127
123 log_info.file= NULL;
124 log_info.fd= -1;128 log_info.fd= -1;
125 log_info.reopen= 0;129 log_info.reopen= 0;
126130
127 if (gearman_conf_create(&conf) == NULL)131 general.add_options()
128 {132 ("backlog,b", value(&backlog)->default_value(GEARMAND_LISTEN_BACKLOG), "Number of backlog connections for listen.")
129 fprintf(stderr, "gearmand: gearman_conf_create: NULL\n");133 ("daemon,d", "Daemon, detach and run in the background.")
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.")
131 }135 ("help,h", "Print this help menu.")
132136 ("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.")
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.")
134 {138 ("port,p", value(&port)->default_value(GEARMAN_DEFAULT_TCP_PORT), "Port the server should listen on.")
135 fprintf(stderr, "gearmand: gearman_conf_module_create: NULL\n");139 ("pid-file,P", value(&pid_file), "File to write process ID out to.")
136 return 1;140 ("protocol,r", value(&protocol), "Load protocol module.")
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.")
138142 ("queue-type,q", value(&queue_type), "Persistent queue type to use.")
139 /* Add all main configuration options. */143 ("threads,t", value(&threads)->default_value(0), "Number of I/O threads to use. Default=4.")
140#define MCO(__name, __short, __value, __help) \144 ("user,u", value(&user), "Switch to given user after startup.")
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.")
142146 ("version,V", "Display the version of gearmand and exit.")
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.")
144 MCO("daemon", 'd', NULL, "Daemon, detach and run in the background.")148 ;
145 MCO("file-descriptors", 'f', "FDS",149 options_description all("Allowed options");
146 "Number of file descriptors to allow for the process (total connections "150 all.add(general);
147 "will be slightly less). Default is max allowed for user.")151
148 MCO("help", 'h', NULL, "Print this help menu.");152 // Add in all of the options found for our logging modules
149 MCO("job-retries", 'j', "RETRIES",153 all.add(Log::Instance()->options());
150 "Number of attempts to run the job before the job server removes it. This"
151 "is helpful to ensure a bad job does not crash all available workers. "
152 "Default is no limit.")
153 MCO("log-file", 'l', "FILE",
154 "Log file to write errors and information to. Turning this option on "
155 "also forces the first verbose level to be enabled.")
156 MCO("listen", 'L', "ADDRESS",
157 "Address the server should listen on. Default is INADDR_ANY.")
158 MCO("port", 'p', "PORT", "Port the server should listen on.")
159 MCO("pid-file", 'P', "FILE", "File to write process ID out to.")
160 MCO("protocol", 'r', "PROTOCOL", "Load protocol module.")
161 MCO("round-robin", 'R', NULL, "Assign work in round-robin order per worker"
162 "connection. The default is to assign work in the order of functions "
163 "added by the worker.")
164 MCO("queue-type", 'q', "QUEUE", "Persistent queue type to use.")
165 MCO("threads", 't', "THREADS", "Number of I/O threads to use. Default=0.")
166 MCO("user", 'u', "USER", "Switch to given user after startup.")
167 MCO("verbose", 'v', NULL, "Increase verbosity level by one.")
168 MCO("version", 'V', NULL, "Display the version of gearmand and exit.")
169 MCO("worker-wakeup", 'w', "WORKERS",
170 "Number of workers to wakeup for each job received. The default is to "
171 "wakeup all available workers.")
172
173 /* Make sure none of the gearman_conf_module_add_option calls failed. */
174 if (gearman_conf_return(&conf) != GEARMAN_SUCCESS)
175 {
176 fprintf(stderr, "gearmand: gearman_conf_module_add_option: %s\n",
177 gearman_conf_error(&conf));
178 return 1;
179 }
180154
181 /* Add queue configuration options. */155 /* Add queue configuration options. */
156#ifdef HAVE_LIBSQLITE3
157 SqliteQueue libsqlite;
158 all.add(libsqlite.options());
159#endif
182160
183#ifdef HAVE_LIBDRIZZLE161#ifdef HAVE_LIBDRIZZLE
184 if (gearman_server_queue_libdrizzle_conf(&conf) != GEARMAN_SUCCESS)162 LibDrizzleQueue libdrizzle;
185 {163 all.add(libdrizzle.options());
186 fprintf(stderr, "gearmand: gearman_queue_libdrizzle_conf: %s\n",164#endif
187 gearman_conf_error(&conf));165
188 return 1;166#ifdef HAVE_LIBTOKYOCABINET
189 }167 TokyoCabinetQueue libtokyocabinet;
168 all.add(libtokyocabinet.options());
190#endif169#endif
191170
192#ifdef HAVE_LIBMEMCACHED171#ifdef HAVE_LIBMEMCACHED
193 if (gearman_server_queue_libmemcached_conf(&conf) != GEARMAN_SUCCESS)172 LibmemcachedQueue libmemcached;
194 {173 all.add(libmemcached.options());
195 fprintf(stderr, "gearmand: gearman_queue_libmemcached_conf: %s\n",
196 gearman_conf_error(&conf));
197 return 1;
198 }
199#endif
200#ifdef HAVE_LIBTOKYOCABINET
201 if (gearman_server_queue_libtokyocabinet_conf(&conf) != GEARMAN_SUCCESS)
202 {
203 fprintf(stderr, "gearmand: gearman_queue_libtokyocabinet_conf: %s\n",
204 gearman_conf_error(&conf));
205 return 1;
206 }
207#endif
208
209#ifdef HAVE_LIBSQLITE3
210 if (gearman_server_queue_libsqlite3_conf(&conf) != GEARMAN_SUCCESS)
211 {
212 fprintf(stderr, "gearmand: gearman_queue_libsqlite3_conf: %s\n",
213 gearman_conf_error(&conf));
214 return 1;
215 }
216#endif174#endif
217175
218#ifdef HAVE_LIBPQ176#ifdef HAVE_LIBPQ
219 if (gearman_server_queue_libpq_conf(&conf) != GEARMAN_SUCCESS)177 LibPqQueue postgres;
220 {178 all.add(postgres.options());
221 fprintf(stderr, "gearmand: gearman_queue_libpq_conf: %s\n",
222 gearman_conf_error(&conf));
223 return 1;
224 }
225#endif179#endif
226180
227 if (gearmand_protocol_http_conf(&conf) != GEARMAN_SUCCESS)181 GearmanHTTP http;
228 {182 all.add(http.options());
229 fprintf(stderr, "gearmand: gearman_protocol_http_conf: %s\n",183
230 gearman_conf_error(&conf));184 variables_map vm;
231 return 1;185
232 }186 try {
233187 store(parse_command_line(argc, argv, all), vm);
234 /* Let gearman conf parse the command line arguments. */188 notify(vm);
235 if (gearman_conf_parse_args(&conf, argc, argv) != GEARMAN_SUCCESS)189 }
236 {190
237 printf("\n%s\n\n", gearman_conf_error(&conf));191 catch(std::exception &e)
238 printf("gearmand %s - %s\n\n", gearman_version(), gearman_bugreport());192 {
239 printf("usage: %s [OPTIONS]\n", argv[0]);193 cout << e.what() << "\n";
240 gearman_conf_usage(&conf);194 return 1;
241 return 1;195 }
242 }196
243197 if (vm.count("help"))
244 /* Check for option values that were given. */198 {
245 while (gearman_conf_module_value(&module, &name, &value))199 cout << all << "\n";
246 {200 return 1;
247 if (!strcmp(name, "backlog"))201 }
248 backlog= atoi(value);202
249 else if (!strcmp(name, "daemon"))203 if (vm.count("version"))
250 {204 {
251 switch (fork())205 cout << "\ngearmand " << gearman_version() << " - " << gearman_bugreport() << "\n";
252 {206 return 1;
253 case -1:207 }
254 fprintf(stderr, "gearmand: fork:%d\n", errno);208
255 return 1;209 verbose= static_cast<gearman_verbose_t>(verbose_string.length());
256210
257 case 0:211 /*
258 break;212 @note Logging begins from this point on.
259213 */
260 default:214 Log::Instance()->start(verbose);
261 return 0;215
262 }216 if (vm.count("daemon"))
263217 {
264 if (setsid() == -1)218 switch (fork())
265 {219 {
266 fprintf(stderr, "gearmand: setsid:%d\n", errno);220 case -1:
267 return 1;221 Log::Instance()->fatal("gearmand: fork:%d\n", errno);
268 }222 return 1;
269223
270 close_stdio= true;224 case 0:
271 }225 break;
272 else if (!strcmp(name, "file-descriptors"))226
273 fds= (rlim_t)atoi(value);227 default:
274 else if (!strcmp(name, "help"))228 return 0;
275 {229 }
276 printf("\ngearmand %s - %s\n\n", gearman_version(), gearman_bugreport());230
277 printf("usage: %s [OPTIONS]\n", argv[0]);231 if (setsid() == -1)
278 gearman_conf_usage(&conf);232 {
279 return 1;233 Log::Instance()->fatal("gearmand: setsid:%d\n", errno);
280 }234 return 1;
281 else if (!strcmp(name, "job-retries"))235 }
282 job_retries= (uint8_t)atoi(value);236
283 else if (!strcmp(name, "log-file"))237 close_stdio= true;
284 log_info.file= value;
285 else if (!strcmp(name, "listen"))
286 host= value;
287 else if (!strcmp(name, "port"))
288 port= (in_port_t)atoi(value);
289 else if (!strcmp(name, "pid-file"))
290 pid_file= value;
291 else if (!strcmp(name, "protocol"))
292 continue;
293 else if (!strcmp(name, "queue-type"))
294 queue_type= value;
295 else if (!strcmp(name, "threads"))
296 threads= (uint32_t)atoi(value);
297 else if (!strcmp(name, "user"))
298 user= value;
299 else if (!strcmp(name, "verbose"))
300 verbose++;
301 else if (!strcmp(name, "round-robin"))
302 round_robin++;
303 else if (!strcmp(name, "version"))
304 printf("\ngearmand %s - %s\n", gearman_version(), gearman_bugreport());
305 else if (!strcmp(name, "worker-wakeup"))
306 worker_wakeup= (uint8_t)atoi(value);
307 else
308 {
309 fprintf(stderr, "gearmand: Unknown option:%s\n", name);
310 return 1;
311 }
312 }238 }
313239
314 if (verbose == 0 && close_stdio)240 if (verbose == 0 && close_stdio)
315 {241 {
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. */
317 fd = open("/dev/null", O_RDWR, 0);243 int fd= open("/dev/null", O_RDWR, 0);
244
318 if (fd != -1)245 if (fd != -1)
319 {246 {
320 if (dup2(fd, STDIN_FILENO) == -1)247 if (dup2(fd, STDIN_FILENO) == -1)
321 {248 {
322 fprintf(stderr, "gearmand: dup2:%d\n", errno);249 Log::Instance()->fatal("gearmand: dup2:%d\n", errno);
323 return 1;250 return 1;
324 }251 }
325252
326 if (dup2(fd, STDOUT_FILENO) == -1)253 if (dup2(fd, STDOUT_FILENO) == -1)
327 {254 {
328 fprintf(stderr, "gearmand: dup2:%d\n", errno);255 Log::Instance()->fatal("gearmand: dup2:%d\n", errno);
329 return 1;256 return 1;
330 }257 }
331258
332 if (dup2(fd, STDERR_FILENO) == -1)259 if (dup2(fd, STDERR_FILENO) == -1)
333 {260 {
334 fprintf(stderr, "gearmand: dup2:%d\n", errno);261 Log::Instance()->fatal("gearmand: dup2:%d\n", errno);
335 return 1;262 return 1;
336 }263 }
337264
338 close(fd);265 close(fd);
339 }266 }
340 }267 }
341
342 if ((fds > 0 && _set_fdlimit(fds)) || _switch_user(user) || _set_signals())268 if ((fds > 0 && _set_fdlimit(fds)) || _switch_user(user) || _set_signals())
343 return 1;269 return -1;
344270
345 if (pid_file != NULL && _pid_write(pid_file))271 if (not pid_file.empty() && _pid_write(pid_file.c_str()))
346 return 1;272 return -1;
347273
348 _gearmand= gearmand_create(host, port);274 _gearmand= new gearmand_st(host.empty() ? NULL : host.c_str(),
275 port,
276 threads);
349 if (_gearmand == NULL)277 if (_gearmand == NULL)
350 {278 {
351 fprintf(stderr, "gearmand: Could not create gearmand library instance\n");279 Log::Instance()->fatal("gearmand: Could not create gearmand library instance\n");
352 return 1;280 return -1;
353 }281 }
354282
355 gearmand_set_backlog(_gearmand, backlog);283 _gearmand->set_backlog(backlog);
356 gearmand_set_threads(_gearmand, threads);284 _gearmand->set_server_job_retries(job_retries);
357 gearmand_set_job_retries(_gearmand, job_retries);285 _gearmand->set_worker_wakeup(worker_wakeup);
358 gearmand_set_worker_wakeup(_gearmand, worker_wakeup);286 _gearmand->set_round_robin(round_robin);
359 gearmand_set_log_fn(_gearmand, _log, &log_info, verbose);
360 gearmand_set_round_robin(_gearmand, round_robin);
361287
362 if (queue_type != NULL)288 if (not queue_type.empty())
363 {289 {
290#ifdef HAVE_LIBSQLITE3
291 if (not queue_type.compare("libsqlite3"))
292 {
293 ret= libsqlite.start();
294 if (ret != GEARMAN_SUCCESS)
295 return 1;
296 _gearmand->server.queue= &libsqlite;
297 //_gearmand->server.queue= static_cast<GQueue *>(libsqlite);
298 }
299 else
300#endif
364#ifdef HAVE_LIBDRIZZLE301#ifdef HAVE_LIBDRIZZLE
365 if (!strcmp(queue_type, "libdrizzle"))302 if (not queue_type.compare("libdrizzle"))
366 {303 {
367 ret= gearmand_queue_libdrizzle_init(_gearmand, &conf);304 ret= libdrizzle.start();
368 if (ret != GEARMAN_SUCCESS)305 if (ret != GEARMAN_SUCCESS)
369 return 1;306 return 1;
307 _gearmand->server.queue= &libdrizzle;
370 }308 }
371 else309 else
372#endif310#endif
373#ifdef HAVE_LIBMEMCACHED311#ifdef HAVE_LIBMEMCACHED
374 if (!strcmp(queue_type, "libmemcached"))312 if (not queue_type.compare("libmemcached"))
375 {313 {
376 ret= gearmand_queue_libmemcached_init(_gearmand, &conf);314 ret= libmemcached.start();
377 if (ret != GEARMAN_SUCCESS)315 if (ret != GEARMAN_SUCCESS)
378 return 1;316 return 1;
379 }317 _gearmand->server.queue= &libmemcached;
380 else
381#endif
382#ifdef HAVE_LIBSQLITE3
383 if (!strcmp(queue_type, "libsqlite3"))
384 {
385 ret= gearmand_queue_libsqlite3_init(_gearmand, &conf);
386 if (ret != GEARMAN_SUCCESS)
387 return 1;
388 }318 }
389 else319 else
390#endif320#endif
391#ifdef HAVE_LIBPQ321#ifdef HAVE_LIBPQ
392 if (!strcmp(queue_type, "libpq"))322 if (not queue_type.compare("libpq"))
393 {323 {
394 ret= gearmand_queue_libpq_init(_gearmand, &conf);324 ret= postgres.start();
395 if (ret != GEARMAN_SUCCESS)325 if (ret != GEARMAN_SUCCESS)
396 return 1;326 return 1;
327 _gearmand->server.queue= &postgres;
397 }328 }
398 else329 else
399#endif330#endif
400#ifdef HAVE_LIBTOKYOCABINET331#ifdef HAVE_LIBTOKYOCABINET
401 if (!strcmp(queue_type, "libtokyocabinet"))332 if (not queue_type.compare("libtokyocabinet"))
402 {333 {
403 ret= gearmand_queue_libtokyocabinet_init(_gearmand, &conf);334 ret= libtokyocabinet.start();
404 if (ret != GEARMAN_SUCCESS)335 if (ret != GEARMAN_SUCCESS)
405 return 1;336 return 1;
337 _gearmand->server.queue= &libtokyocabinet;
406 }338 }
407 else339 else
408#endif 340#endif
409 {341 {
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());
411 return 1;343 return 1;
412 }344 }
413 }345 }
414346
415 while (gearman_conf_module_value(&module, &name, &value))347 if (not protocol.compare("http"))
416 {348 {
417 if (strcmp(name, "protocol"))349 ret= http.start(_gearmand);
418 continue;350 if (ret != GEARMAN_SUCCESS)
419351 return 1;
420 if (!strcmp(value, "http"))352 }
421 {353 else if (not protocol.empty())
422 ret= gearmand_protocol_http_init(_gearmand, &conf);354 {
423 if (ret != GEARMAN_SUCCESS)355 Log::Instance()->fatal("gearmand: Unknown protocol module: %s\n", protocol.c_str());
424 return 1;356 return 1;
425 }357 }
426 else358
427 {359 ret= _gearmand->run();
428 fprintf(stderr, "gearmand: Unknown protocol module: %s\n", value);360
429 return 1;361 delete _gearmand;
430 }362
431 }363 if (not pid_file.empty())
432364 _pid_delete(pid_file.c_str());
433 ret= gearmand_run(_gearmand);
434
435 if (queue_type != NULL)
436 {
437#ifdef HAVE_LIBDRIZZLE
438 if (!strcmp(queue_type, "libdrizzle"))
439 gearmand_queue_libdrizzle_deinit(_gearmand);
440#endif
441#ifdef HAVE_LIBMEMCACHED
442 if (!strcmp(queue_type, "libmemcached"))
443 gearmand_queue_libmemcached_deinit(_gearmand);
444#endif
445#ifdef HAVE_LIBSQLITE3
446 if (!strcmp(queue_type, "libsqlite3"))
447 gearmand_queue_libsqlite3_deinit(_gearmand);
448#endif
449#ifdef HAVE_LIBPQ
450 if (!strcmp(queue_type, "libpq"))
451 gearmand_queue_libpq_deinit(_gearmand);
452#endif
453#ifdef HAVE_LIBTOKYOCABINET
454 if (!strcmp(queue_type, "libtokyocabinet"))
455 gearmand_queue_libtokyocabinet_deinit(_gearmand);
456#endif
457 }
458
459 while (gearman_conf_module_value(&module, &name, &value))
460 {
461 if (strcmp(name, "protocol"))
462 continue;
463
464 if (!strcmp(value, "http"))
465 gearmand_protocol_http_deinit(_gearmand);
466 }
467
468 gearmand_free(_gearmand);
469
470 if (pid_file != NULL)
471 _pid_delete(pid_file);
472365
473 if (log_info.fd != -1)366 if (log_info.fd != -1)
474 (void) close(log_info.fd);367 (void) close(log_info.fd);
475368
476 gearman_conf_free(&conf);
477
478 return (ret == GEARMAN_SUCCESS || ret == GEARMAN_SHUTDOWN) ? 0 : 1;369 return (ret == GEARMAN_SUCCESS || ret == GEARMAN_SHUTDOWN) ? 0 : 1;
479}370}
480371
@@ -484,8 +375,7 @@
484375
485 if (getrlimit(RLIMIT_NOFILE, &rl) == -1)376 if (getrlimit(RLIMIT_NOFILE, &rl) == -1)
486 {377 {
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);
488 errno);
489 return true;379 return true;
490 }380 }
491381
@@ -495,10 +385,10 @@
495385
496 if (setrlimit(RLIMIT_NOFILE, &rl) == -1)386 if (setrlimit(RLIMIT_NOFILE, &rl) == -1)
497 {387 {
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 "
499 "descriptors (%d). Try running as root or giving a "389 "descriptors (%d). Try running as root or giving a "
500 "smaller value to -f.\n",390 "smaller value to -f.\n",
501 errno);391 errno);
502 return true;392 return true;
503 }393 }
504394
@@ -512,8 +402,8 @@
512 f= fopen(pid_file, "w");402 f= fopen(pid_file, "w");
513 if (f == NULL)403 if (f == NULL)
514 {404 {
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",
516 pid_file, errno);406 pid_file, errno);
517 return true;407 return true;
518 }408 }
519409
@@ -521,8 +411,8 @@
521411
522 if (fclose(f) == -1)412 if (fclose(f) == -1)
523 {413 {
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",
525 pid_file, errno);415 pid_file, errno);
526 return true;416 return true;
527 }417 }
528418
@@ -533,40 +423,39 @@
533{423{
534 if (unlink(pid_file) == -1)424 if (unlink(pid_file) == -1)
535 {425 {
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",
537 pid_file, errno);427 pid_file, errno);
538 }428 }
539}429}
540430
541static bool _switch_user(const char *user)431static bool _switch_user(const string user)
542{432{
543 struct passwd *pw;433 struct passwd *pw;
544434
545 if (getuid() == 0 || geteuid() == 0)435 if (getuid() == 0 || geteuid() == 0)
546 {436 {
547 if (user == NULL || user[0] == 0)437 if (user.empty())
548 {438 {
549 fprintf(stderr,439 Log::Instance()->fatal("gearmand: Must specify '-u root' if you want to run as root\n");
550 "gearmand: Must specify '-u root' if you want to run as root\n");
551 return true;440 return true;
552 }441 }
553442
554 pw= getpwnam(user);443 pw= getpwnam(user.c_str());
555 if (pw == NULL)444 if (pw == NULL)
556 {445 {
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());
558 return 1;447 return true;
559 }448 }
560449
561 if (setgid(pw->pw_gid) == -1 || setuid(pw->pw_uid) == -1)450 if (setgid(pw->pw_gid) == -1 || setuid(pw->pw_uid) == -1)
562 {451 {
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());
564 return 1;453 return 1;
565 }454 }
566 }455 }
567 else if (user != NULL)456 else if (not user.empty())
568 {457 {
569 fprintf(stderr, "gearmand: Must be root to switch users\n");458 Log::Instance()->fatal("gearmand: Must be root to switch users\n");
570 return true;459 return true;
571 }460 }
572461
@@ -583,26 +472,26 @@
583 if (sigemptyset(&sa.sa_mask) == -1 ||472 if (sigemptyset(&sa.sa_mask) == -1 ||
584 sigaction(SIGPIPE, &sa, 0) == -1)473 sigaction(SIGPIPE, &sa, 0) == -1)
585 {474 {
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);
587 return true;476 return true;
588 }477 }
589478
590 sa.sa_handler= _shutdown_handler;479 sa.sa_handler= _shutdown_handler;
591 if (sigaction(SIGTERM, &sa, 0) == -1)480 if (sigaction(SIGTERM, &sa, 0) == -1)
592 {481 {
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);
594 return true;483 return true;
595 }484 }
596485
597 if (sigaction(SIGINT, &sa, 0) == -1)486 if (sigaction(SIGINT, &sa, 0) == -1)
598 {487 {
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);
600 return true;489 return true;
601 }490 }
602491
603 if (sigaction(SIGUSR1, &sa, 0) == -1)492 if (sigaction(SIGUSR1, &sa, 0) == -1)
604 {493 {
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);
606 return true;495 return true;
607 }496 }
608497
@@ -612,48 +501,11 @@
612static void _shutdown_handler(int signal_arg)501static void _shutdown_handler(int signal_arg)
613{502{
614 if (signal_arg == SIGUSR1)503 if (signal_arg == SIGUSR1)
615 gearmand_wakeup(_gearmand, GEARMAND_WAKEUP_SHUTDOWN_GRACEFUL);504 {
616 else505 _gearmand->set_wakeup(GEARMAND_WAKEUP_SHUTDOWN_GRACEFUL);
617 gearmand_wakeup(_gearmand, GEARMAND_WAKEUP_SHUTDOWN);506 }
618}507 else
619508 {
620static void _log(const char *line, gearman_verbose_t verbose, void *context)509 _gearmand->set_wakeup(GEARMAND_WAKEUP_SHUTDOWN);
621{510 }
622 gearmand_log_info_st *log_info= (gearmand_log_info_st *)context;
623 int fd;
624 time_t t;
625 char buffer[GEARMAN_MAX_ERROR_SIZE];
626
627 if (log_info->file == NULL)
628 fd= 1;
629 else
630 {
631 t= time(NULL);
632
633 if (log_info->fd != -1 && log_info->reopen < t)
634 {
635 (void) close(log_info->fd);
636 log_info->fd= -1;
637 }
638
639 if (log_info->fd == -1)
640 {
641 log_info->fd= open(log_info->file, O_CREAT | O_WRONLY | O_APPEND, 0644);
642 if (log_info->fd == -1)
643 {
644 fprintf(stderr, "gearmand: Could not open log file for writing (%d)\n",
645 errno);
646 return;
647 }
648
649 log_info->reopen= t + GEARMAND_LOG_REOPEN_TIME;
650 }
651
652 fd= log_info->fd;
653 }
654
655 snprintf(buffer, GEARMAN_MAX_ERROR_SIZE, "%5s %s\n",
656 gearman_verbose_name(verbose), line);
657 if (write(fd, buffer, strlen(buffer)) == -1)
658 fprintf(stderr, "gearmand: Could not write to log file: %d\n", errno);
659}511}
660512
=== modified file 'gearmand/include.am'
--- gearmand/include.am 2009-12-18 18:19:29 +0000
+++ gearmand/include.am 2010-07-01 01:31:26 +0000
@@ -13,10 +13,11 @@
13sbin_PROGRAMS+= gearmand/gearmand13sbin_PROGRAMS+= gearmand/gearmand
1414
15gearmand_gearmand_LDADD= \15gearmand_gearmand_LDADD= \
16 libgearman-server/libgearman-server.la \16 ${BOOST_LIBS} \
17 ${BETTER_MALLOC_LIBS}17 libgearman-server/libgearman-server.la \
18 ${BETTER_MALLOC_LIBS}
1819
19gearmand_gearmand_SOURCES= gearmand/gearmand.c20gearmand_gearmand_SOURCES= gearmand/gearmand.cc
2021
21gearmand-valgrind: gearmand/gearmand22gearmand-valgrind: gearmand/gearmand
22 $(LIBTOOL) --mode=execute valgrind --leak-check=yes --show-reachable=yes gearmand/gearmand23 $(LIBTOOL) --mode=execute valgrind --leak-check=yes --show-reachable=yes gearmand/gearmand
2324
=== renamed file 'libgearman-server/client.c' => 'libgearman-server/client.cc'
--- libgearman-server/client.c 2010-04-06 21:41:46 +0000
+++ libgearman-server/client.cc 2010-07-01 01:31:26 +0000
@@ -1,4 +1,5 @@
1/* Gearman server and library1/* Gearman server and library
2 * Copyright (C) 2010 Data Differential
2 * Copyright (C) 2008 Brian Aker, Eric Day3 * Copyright (C) 2008 Brian Aker, Eric Day
3 * All rights reserved.4 * All rights reserved.
4 *5 *
@@ -11,12 +12,13 @@
11 * @brief Server client definitions12 * @brief Server client definitions
12 */13 */
1314
14#include "common.h"15#include "libgearman-server/common.h"
1516
16/*17/*
17 * Public definitions18 * Public definitions
18 */19 */
1920
21<<<<<<< TREE
20gearman_server_client_st *22gearman_server_client_st *
21gearman_server_client_add(gearman_server_con_st *con)23gearman_server_client_add(gearman_server_con_st *con)
22{24{
@@ -93,4 +95,15 @@
93 else95 else
94 free(client);96 free(client);
95 }97 }
98=======
99gearman_server_client_st::gearman_server_client_st() :
100 job(NULL),
101 job_next(NULL),
102 job_prev(NULL)
103{
104}
105
106gearman_server_client_st::~gearman_server_client_st()
107{
108>>>>>>> MERGE-SOURCE
96}109}
97110
=== modified file 'libgearman-server/client.h'
--- libgearman-server/client.h 2010-03-11 19:58:32 +0000
+++ libgearman-server/client.h 2010-07-01 01:31:26 +0000
@@ -1,4 +1,5 @@
1/* Gearman server and library1/* Gearman server and library
2 * Copyright (C) 2010 Data Differential
2 * Copyright (C) 2008 Brian Aker, Eric Day3 * Copyright (C) 2008 Brian Aker, Eric Day
3 * All rights reserved.4 * All rights reserved.
4 *5 *
@@ -14,61 +15,20 @@
14#ifndef __GEARMAN_SERVER_CLIENT_H__15#ifndef __GEARMAN_SERVER_CLIENT_H__
15#define __GEARMAN_SERVER_CLIENT_H__16#define __GEARMAN_SERVER_CLIENT_H__
1617
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/**18/**
22 * @ingroup gearman_server_client19 * @ingroup gearman_server_client
23 */20 */
24struct gearman_server_client_st21struct gearman_server_client_st
25{22{
26 struct {
27 bool allocated;
28 } options;
29 gearman_server_con_st *con;23 gearman_server_con_st *con;
30 gearman_server_client_st *con_next;24 gearman_server_client_st *con_next;
31 gearman_server_client_st *con_prev;25 gearman_server_client_st *con_prev;
32 gearman_server_job_st *job;26 gearman_server_job_st *job;
33 gearman_server_client_st *job_next;27 gearman_server_client_st *job_next;
34 gearman_server_client_st *job_prev;28 gearman_server_client_st *job_prev;
29
30 gearman_server_client_st();
31 ~gearman_server_client_st();
35};32};
3633
37/**
38 * @addtogroup gearman_server_client Client Declarations
39 * @ingroup gearman_server
40 *
41 * This is a low level interface for gearman server clients. This is used
42 * internally by the server interface, so you probably want to look there first.
43 *
44 * @{
45 */
46
47/**
48 * Add a new client to a server instance.
49 */
50GEARMAN_API
51gearman_server_client_st *
52gearman_server_client_add(gearman_server_con_st *con);
53
54/**
55 * Initialize a server client structure.
56 */
57GEARMAN_API
58gearman_server_client_st *
59gearman_server_client_create(gearman_server_con_st *con,
60 gearman_server_client_st *client);
61
62/**
63 * Free a server client structure.
64 */
65GEARMAN_API
66void gearman_server_client_free(gearman_server_client_st *client);
67
68/** @} */
69
70#ifdef __cplusplus
71}
72#endif
73
74#endif /* __GEARMAN_SERVER_CLIENT_H__ */34#endif /* __GEARMAN_SERVER_CLIENT_H__ */
7535
=== modified file 'libgearman-server/common.h'
--- libgearman-server/common.h 2010-04-02 02:04:04 +0000
+++ libgearman-server/common.h 2010-07-01 01:31:26 +0000
@@ -1,4 +1,5 @@
1/* Gearman server and library1/* Gearman server and library
2 * Copyright (C) 2010 Data Differential
2 * Copyright (C) 2008 Brian Aker, Eric Day3 * Copyright (C) 2008 Brian Aker, Eric Day
3 * All rights reserved.4 * All rights reserved.
4 *5 *
@@ -16,8 +17,13 @@
1617
17#include "config.h"18#include "config.h"
1819
20#define __STDC_LIMIT_MACROS
21#define __STDC_FORMAT_MACROS
22
23#include <cstdarg>
24
19#define GEARMAN_CORE25#define GEARMAN_CORE
20#include "gearmand.h"26#include "libgearman-server/gearmand.h"
2127
22#ifdef HAVE_ASSERT_H28#ifdef HAVE_ASSERT_H
23#include <assert.h>29#include <assert.h>
@@ -34,9 +40,6 @@
34#ifdef HAVE_PTHREAD40#ifdef HAVE_PTHREAD
35#include <pthread.h>41#include <pthread.h>
36#endif42#endif
37#ifdef HAVE_STDARG_H
38#include <stdarg.h>
39#endif
40#ifdef HAVE_STDDEF_H43#ifdef HAVE_STDDEF_H
41#include <stddef.h>44#include <stddef.h>
42#endif45#endif
@@ -116,30 +119,6 @@
116}119}
117120
118/**121/**
119 * Add an object to a fifo list.
120 * @ingroup gearman_constants
121 */
122#define GEARMAN_FIFO_ADD(__list, __obj, __prefix) { \
123 if (__list ## _end == NULL) \
124 __list ## _list= __obj; \
125 else \
126 __list ## _end->__prefix ## next= __obj; \
127 __list ## _end= __obj; \
128 __list ## _count++; \
129}
130
131/**
132 * Delete an object from a fifo list.
133 * @ingroup gearman_constants
134 */
135#define GEARMAN_FIFO_DEL(__list, __obj, __prefix) { \
136 __list ## _list= __obj->__prefix ## next; \
137 if (__list ## _list == NULL) \
138 __list ## _end= NULL; \
139 __list ## _count--; \
140}
141
142/**
143 * Add an object to a hash.122 * Add an object to a hash.
144 * @ingroup gearman_constants123 * @ingroup gearman_constants
145 */124 */
@@ -184,4 +163,18 @@
184}163}
185#endif164#endif
186165
166#include <boost/bind.hpp>
167#include <boost/foreach.hpp>
168#include <boost/program_options/options_description.hpp>
169#include <boost/program_options/parsers.hpp>
170#include <boost/program_options/variables_map.hpp>
171#include <boost/shared_ptr.hpp>
172#include <boost/smart_ptr/shared_ptr.hpp>
173#include <boost/thread/condition.hpp>
174#include <boost/thread/mutex.hpp>
175#include <boost/thread/thread.hpp>
176#include <boost/token_functions.hpp>
177#include <boost/tokenizer.hpp>
178#include <boost/unordered_map.hpp>
179
187#endif /* __GEARMAN_SERVER_COMMON_H__ */180#endif /* __GEARMAN_SERVER_COMMON_H__ */
188181
=== renamed file 'libgearman-server/conf.c' => 'libgearman-server/conf.c.THIS'
=== removed file 'libgearman-server/conf.h'
--- libgearman-server/conf.h 2010-03-11 20:33:13 +0000
+++ libgearman-server/conf.h 1970-01-01 00:00:00 +0000
@@ -1,103 +0,0 @@
1/* Gearman server and library
2 * Copyright (C) 2009 Eric Day
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 */
8
9/**
10 * @file
11 * @brief Configuration Declarations
12 */
13
14#ifndef __GEARMAN_SERVER_CONF_H__
15#define __GEARMAN_SERVER_CONF_H__
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/**
22 * @addtogroup gearman_conf Configuration Declarations
23 * @ingroup gearman_server
24 * @{
25 */
26
27struct gearman_conf_option_st
28{
29 size_t value_count;
30 gearman_conf_module_st *module;
31 const char *name;
32 const char *value_name;
33 const char *help;
34 char **value_list;
35};
36
37struct gearman_conf_st
38{
39 struct {
40 bool allocated;
41 } options;
42 gearman_return_t last_return;
43 int last_errno;
44 size_t module_count;
45 size_t option_count;
46 size_t short_count;
47 gearman_conf_module_st **module_list;
48 gearman_conf_option_st *option_list;
49 struct option *option_getopt;
50 char option_short[GEARMAN_CONF_MAX_OPTION_SHORT];
51 char last_error[GEARMAN_MAX_ERROR_SIZE];
52};
53
54/**
55 * Initialize a gearman conf structure.
56 */
57GEARMAN_API
58gearman_conf_st *gearman_conf_create(gearman_conf_st *conf);
59
60/**
61 * Free a gearman conf structure.
62 */
63GEARMAN_API
64void gearman_conf_free(gearman_conf_st *conf);
65
66/**
67 * Return an return code for the last library error encountered.
68 */
69GEARMAN_API
70gearman_return_t gearman_conf_return(gearman_conf_st *conf);
71
72/**
73 * Return an error string for last library error encountered.
74 */
75GEARMAN_API
76const char *gearman_conf_error(gearman_conf_st *conf);
77
78/**
79 * Value of errno in the case of a GEARMAN_ERRNO return value.
80 */
81GEARMAN_API
82int gearman_conf_errno(gearman_conf_st *conf);
83
84/**
85 * Parse command line arguments.
86 */
87GEARMAN_API
88gearman_return_t gearman_conf_parse_args(gearman_conf_st *conf, int argc,
89 char *argv[]);
90
91/**
92 * Print usage information to stdout.
93 */
94GEARMAN_API
95void gearman_conf_usage(gearman_conf_st *conf);
96
97/** @} */
98
99#ifdef __cplusplus
100}
101#endif
102
103#endif /* __GEARMAN_SERVER_CONF_H__ */
1040
=== renamed file 'libgearman-server/conf_module.c' => 'libgearman-server/conf_module.c.THIS'
=== removed file 'libgearman-server/conf_module.h'
--- libgearman-server/conf_module.h 2010-03-11 22:45:34 +0000
+++ libgearman-server/conf_module.h 1970-01-01 00:00:00 +0000
@@ -1,80 +0,0 @@
1/* Module configuration library
2 * Copyright (C) 2009 Eric Day
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 */
8
9/**
10 * @file
11 * @brief Configuration Module Declarations
12 */
13
14#ifndef __GEARMAN_SERVER_CONF_MODULE_H__
15#define __GEARMAN_SERVER_CONF_MODULE_H__
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/**
22 * @addtogroup gearman_conf_module Configuration Module Declarations
23 * @ingroup gearman_server
24 * @{
25 */
26
27struct gearman_conf_module_st
28{
29 struct {
30 bool allocated;
31 } options;
32 size_t current_option;
33 size_t current_value;
34 gearman_conf_st *conf;
35 const char *name;
36};
37
38/**
39 * Initialize a gearman conf module structure.
40 */
41GEARMAN_API
42gearman_conf_module_st *gearman_conf_module_create(gearman_conf_st *conf,
43 gearman_conf_module_st *module,
44 const char *name);
45
46/**
47 * Free a gearman conf module structure.
48 */
49GEARMAN_API
50void gearman_conf_module_free(gearman_conf_module_st *module);
51
52/**
53 * Find a gearman conf module structure by name.
54 */
55GEARMAN_API
56gearman_conf_module_st *gearman_conf_module_find(gearman_conf_st *conf,
57 const char *name);
58
59/**
60 * Add option for a module.
61 */
62GEARMAN_API
63void gearman_conf_module_add_option(gearman_conf_module_st *module,
64 const char *name, int short_name,
65 const char *value_name, const char *help);
66
67/**
68 * Loop through all values that were given for a set of module options.
69 */
70GEARMAN_API
71bool gearman_conf_module_value(gearman_conf_module_st *module,
72 const char **name, const char **value);
73
74/** @} */
75
76#ifdef __cplusplus
77}
78#endif
79
80#endif /* __GEARMAN_SERVER_CONF_MODULE_H__ */
810
=== renamed file 'libgearman-server/connection.c' => 'libgearman-server/connection.cc'
--- libgearman-server/connection.c 2010-04-06 21:41:46 +0000
+++ libgearman-server/connection.cc 2010-07-01 01:31:26 +0000
@@ -1,4 +1,5 @@
1/* Gearman server and library1/* Gearman server and library
2 * Copyright (C) 2010 Data Differential
2 * Copyright (C) 2008 Brian Aker, Eric Day3 * Copyright (C) 2008 Brian Aker, Eric Day
3 * All rights reserved.4 * All rights reserved.
4 *5 *
@@ -11,12 +12,13 @@
11 * @brief Server connection definitions12 * @brief Server connection definitions
12 */13 */
1314
14#include "common.h"15#include "libgearman-server/common.h"
1516
16/*17/*
17 * Public definitions18 * Public definitions
18 */19 */
1920
21<<<<<<< TREE
20gearman_server_con_st *gearman_server_con_add(gearman_server_thread_st *thread,22gearman_server_con_st *gearman_server_con_add(gearman_server_thread_st *thread,
21 int fd, void *data)23 int fd, void *data)
22{24{
@@ -115,128 +117,150 @@
115117
116 con->host= NULL;118 con->host= NULL;
117 con->port= NULL;119 con->port= NULL;
120=======
121gearman_server_con_st::gearman_server_con_st(gearman_server_thread_st *thread_arg) :
122 is_sleeping(false),
123 is_exceptions(false),
124 is_dead(false),
125 is_noop_sent(false),
126 ret(GEARMAN_SUCCESS),
127 io_list(false),
128 proc_list(false),
129 proc_removed(false),
130 worker_count(0),
131 client_count(0),
132 thread(thread_arg),
133 packet(NULL),
134 io_next(NULL),
135 io_prev(NULL),
136 proc_next(NULL),
137 proc_prev(NULL),
138 worker_list(NULL),
139 client_list(NULL),
140 _host(NULL),
141 _port(NULL)
142{
143 strcpy(_id, "-");
144
145 gearman_connection_options_t _options[] = { GEARMAN_CON_IGNORE_LOST_CONNECTION, GEARMAN_CON_MAX };
146 if (gearman_connection_create(&thread_arg->gearman, con(), _options) == NULL)
147 {
148 abort(); // Should be impossible
149 }
150}
151
152gearman_server_con_st::~gearman_server_con_st()
153{
154 _host= NULL;
155 _port= NULL;
156
157 {
158 boost::mutex::scoped_lock l(thread->lock);
159 thread->con_list.erase(this);
160 }
161>>>>>>> MERGE-SOURCE
118162
119 if (thread->server->flags.threaded &&163 if (thread->server->flags.threaded &&
120 !(con->proc_removed) && !(thread->server->proc_shutdown))164 !(proc_removed) && !(thread->server->proc_shutdown))
121 {165 {
122 con->is_dead= true;166 is_dead= true;
123 con->is_sleeping= false;167 is_sleeping= false;
124 con->is_exceptions= false;168 is_exceptions= false;
125 con->is_noop_sent= false;169 is_noop_sent= false;
126 gearman_server_con_proc_add(con);170 proc_add();
127 return;171 return;
128 }172 }
129173
130 gearman_connection_free(&(con->con));174 if (proc_list)
131175 proc_remove();
132 if (con->proc_list)176
133 gearman_server_con_proc_remove(con);177 if (io_list)
134178 io_remove();
135 if (con->io_list)179
136 gearman_server_con_io_remove(con);180 if (packet != NULL)
137181 {
138 if (con->packet != NULL)182 if (&packet->packet != con()->recv_packet)
139 {183 { }
140 if (&(con->packet->packet) != con->con.recv_packet)184 else
141 gearman_packet_free(&(con->packet->packet));185 {
142 gearman_server_packet_free(con->packet, con->thread, true);186 packet->release_packet= false;
143 }187 }
144188 delete packet;
145 while (con->io_packet_list != NULL)189 }
146 gearman_server_io_packet_remove(con);190
147191 assert(con()->options.allocated == false);
148 while (con->proc_packet_list != NULL)192 gearman_connection_free(con());
149 {193
150 packet= gearman_server_proc_packet_remove(con);194 while (io_packet_list.size())
151 gearman_packet_free(&(packet->packet));195 {
152 gearman_server_packet_free(packet, con->thread, true);196 io_packet_remove();
153 }197 }
154198
155 gearman_server_con_free_workers(con);199 while (proc_packet_list.size())
156200 {
157 while (con->client_list != NULL)201 gearman_server_packet_st *packet_ptr;
158 gearman_server_client_free(con->client_list);202
159203 packet_ptr= proc_packet_remove();
160 (void) pthread_mutex_lock(&thread->lock);204 delete packet_ptr;
161 GEARMAN_LIST_DEL(con->thread->con, con,)205 }
162 (void) pthread_mutex_unlock(&thread->lock);206
163207 while (worker_list != NULL)
164 if (thread->free_con_count < GEARMAN_MAX_FREE_SERVER_CON)208 {
165 GEARMAN_LIST_ADD(thread->free_con, con,)209 delete worker_list;
166 else210 }
167 free(con);211
168}212 while (client_list != NULL)
169213 {
170gearman_connection_st *gearman_server_con_con(gearman_server_con_st *con)214 client_list->con->thread->server->client_free(client_list);
171{215 }
172 return &con->con;216}
173}217
174218const void *gearman_server_con_st::data()
175const void *gearman_server_con_data(const gearman_server_con_st *con)219{
176{220 return gearman_connection_context(con());
177 return gearman_connection_context(&(con->con));221}
178}222
179223void gearman_server_con_st::set_host(const char *host_arg)
180void gearman_server_con_set_data(gearman_server_con_st *con, void *data)224{
181{225 _host= host_arg;
182 gearman_connection_set_context(&(con->con), data);226}
183}227
184228void gearman_server_con_st::set_port(const char *port_arg)
185const char *gearman_server_con_host(gearman_server_con_st *con)229{
186{230 _port= port_arg;
187 return con->host;231}
188}232
189233void gearman_server_con_st::set_id(char *id_arg, size_t size)
190void gearman_server_con_set_host(gearman_server_con_st *con, const char *host)
191{
192 con->host= host;
193}
194
195const char *gearman_server_con_port(gearman_server_con_st *con)
196{
197 return con->port;
198}
199
200void gearman_server_con_set_port(gearman_server_con_st *con, const char *port)
201{
202 con->port= port;
203}
204
205const char *gearman_server_con_id(gearman_server_con_st *con)
206{
207 return con->id;
208}
209
210void gearman_server_con_set_id(gearman_server_con_st *con, char *id,
211 size_t size)
212{234{
213 if (size >= GEARMAN_SERVER_CON_ID_SIZE)235 if (size >= GEARMAN_SERVER_CON_ID_SIZE)
214 size= GEARMAN_SERVER_CON_ID_SIZE - 1;236 size= GEARMAN_SERVER_CON_ID_SIZE - 1;
215237
216 memcpy(con->id, id, size);238 memcpy(_id, id_arg, size);
217 con->id[size]= 0;239 _id[size]= 0;
218}240}
219241
220void gearman_server_con_free_worker(gearman_server_con_st *con,242void gearman_server_con_st::free_worker(const char *function_name_arg,
221 char *function_name,243 size_t function_name_size_arg)
222 size_t function_name_size)
223{244{
224 gearman_server_worker_st *worker= con->worker_list;245 gearman_server_worker_st *worker= worker_list;
225 gearman_server_worker_st *prev_worker= NULL;246 gearman_server_worker_st *prev_worker= NULL;
226247
227 while (worker != NULL)248 while (worker != NULL)
228 {249 {
229 if (worker->function->function_name_size == function_name_size &&250 if (worker->function->function_name.length() == function_name_size_arg &&
230 !memcmp(worker->function->function_name, function_name,251 !memcmp(worker->function->function_name.c_str(), function_name_arg, function_name_size_arg))
231 function_name_size))
232 {252 {
233 gearman_server_worker_free(worker);253 delete worker;
234254
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. */
236 if (prev_worker == NULL)256 if (prev_worker == NULL)
237 worker= con->worker_list;257 {
258 worker= worker_list;
259 }
238 else260 else
261 {
239 worker= prev_worker;262 worker= prev_worker;
263 }
240 }264 }
241 else265 else
242 {266 {
@@ -247,111 +271,424 @@
247 }271 }
248}272}
249273
250void gearman_server_con_free_workers(gearman_server_con_st *con)274void gearman_server_con_st::free_workers()
251{275{
252 while (con->worker_list != NULL)276 while (worker_list != NULL)
253 gearman_server_worker_free(con->worker_list);277 {
278 delete worker_list;
279 }
254}280}
255281
256void gearman_server_con_io_add(gearman_server_con_st *con)282void gearman_server_con_st::io_add()
257{283{
258 if (con->io_list)284 if (io_list)
259 return;285 return;
260286
261 (void) pthread_mutex_lock(&con->thread->lock);287 thread->lock.lock();
262288
263 GEARMAN_LIST_ADD(con->thread->io, con, io_)289 GEARMAN_LIST_ADD(thread->io, this, io_)
264 con->io_list= true;290 io_list= true;
265291
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. */
267 if (con->thread->io_count == 1 && con->thread->run_fn)293 if (thread->io_count == 1 && thread->run_fn)
268 {294 {
269 (void) pthread_mutex_unlock(&con->thread->lock);295 thread->lock.unlock();
270 (*con->thread->run_fn)(con->thread, con->thread->run_fn_arg);296 (*thread->run_fn)(thread, thread->run_fn_arg);
271 }297 }
272 else298 else
273 {299 {
274 (void) pthread_mutex_unlock(&con->thread->lock);300 thread->lock.unlock();
275 }301 }
276}302}
277303
278void gearman_server_con_io_remove(gearman_server_con_st *con)304void gearman_server_con_st::io_remove()
279{305{
280 (void) pthread_mutex_lock(&con->thread->lock);306 boost::mutex::scoped_lock l(thread->lock);
281 if (con->io_list)307 if (io_list)
282 {308 {
283 GEARMAN_LIST_DEL(con->thread->io, con, io_)309 GEARMAN_LIST_DEL(thread->io, this, io_)
284 con->io_list= false;310 io_list= false;
285 }311 }
286 (void) pthread_mutex_unlock(&con->thread->lock);312}
287}313
288314void gearman_server_con_st::proc_add()
289gearman_server_con_st *315{
290gearman_server_con_io_next(gearman_server_thread_st *thread)316 if (proc_list)
291{
292 gearman_server_con_st *con= thread->io_list;
293
294 if (con == NULL)
295 return NULL;
296
297 gearman_server_con_io_remove(con);
298
299 return con;
300}
301
302void gearman_server_con_proc_add(gearman_server_con_st *con)
303{
304 if (con->proc_list)
305 return;317 return;
306318
307 (void) pthread_mutex_lock(&con->thread->lock);319 {
308 GEARMAN_LIST_ADD(con->thread->proc, con, proc_)320 boost::mutex::scoped_lock l(thread->lock);
309 con->proc_list= true;321 GEARMAN_LIST_ADD(thread->proc, this, proc_);
310 (void) pthread_mutex_unlock(&con->thread->lock);322 proc_list= true;
311323 }
312 if (! (con->thread->server->proc_shutdown) &&324
313 !(con->thread->server->proc_wakeup))325 if (! (thread->server->proc_shutdown) &&
314 {326 !(thread->server->proc_wakeup))
315 (void) pthread_mutex_lock(&(con->thread->server->proc_lock));327 {
316 con->thread->server->proc_wakeup= true;328
317 (void) pthread_cond_signal(&(con->thread->server->proc_cond));329 // Rethink this (copied from straight pthread)
318 (void) pthread_mutex_unlock(&(con->thread->server->proc_lock));330 boost::mutex::scoped_lock l(thread->server->proc_lock);
319 }331 thread->server->proc_wakeup= true;
320}332 thread->server->proc_cond.notify_all();
321333 }
322void gearman_server_con_proc_remove(gearman_server_con_st *con)334}
323{335
324 (void) pthread_mutex_lock(&con->thread->lock);336void gearman_server_con_st::proc_remove()
325337{
326 if (con->proc_list)338 boost::mutex::scoped_lock l(thread->lock);
327 {339
328 GEARMAN_LIST_DEL(con->thread->proc, con, proc_)340 if (proc_list)
329 con->proc_list= false;341 {
330 }342 GEARMAN_LIST_DEL(thread->proc, this, proc_)
331 (void) pthread_mutex_unlock(&con->thread->lock);343 proc_list= false;
332}344 }
333345}
334gearman_server_con_st *346
335gearman_server_con_proc_next(gearman_server_thread_st *thread)347gearman_server_client_st *gearman_server_con_st::client_create()
336{348{
337 gearman_server_con_st *con;349 gearman_server_client_st *client;
338350
339 if (thread->proc_list == NULL)351 {
340 return NULL;352 client= new gearman_server_client_st;
341353 if (client == NULL)
342 (void) pthread_mutex_lock(&thread->lock);354 {
343355 Log::Instance()->error("gearman_server_client_create: new()");
344 con= thread->proc_list;356
345 while (con != NULL)357 return NULL;
346 {358 }
347 GEARMAN_LIST_DEL(thread->proc, con, proc_)359 }
348 con->proc_list= false;360
349 if (!(con->proc_removed))361 client->con= this;
350 break;362 GEARMAN_LIST_ADD(client, client, con_)
351 con= thread->proc_list;363
352 }364 return client;
353365}
354 (void) pthread_mutex_unlock(&thread->lock);366
355367gearman_server_client_st *gearman_server_con_st::client_add()
356 return con;368{
369 gearman_server_client_st *client;
370
371 client= client_create();
372 if (client == NULL)
373 return NULL;
374
375 return client;
376}
377
378
379gearman_server_worker_st *
380gearman_server_con_st::worker_create(gearman_server_function_st *function)
381{
382 gearman_server_worker_st *worker= NULL;
383
384 worker= new gearman_server_worker_st(this, function);
385
386 GEARMAN_LIST_ADD(worker, worker, con_);
387
388 Log::Instance()->event(Logger::WORKER_CREATED, NULL);
389
390 /* Add worker to the function list, which is a double-linked circular list. */
391 if (function->worker_list == NULL)
392 {
393 function->worker_list= worker;
394 worker->function_next= worker;
395 worker->function_prev= worker;
396 }
397 else
398 {
399 worker->function_next= function->worker_list;
400 worker->function_prev= function->worker_list->function_prev;
401 worker->function_next->function_prev= worker;
402 worker->function_prev->function_next= worker;
403 }
404 function->worker_count++;
405
406 return worker;
407}
408
409gearman_server_worker_st *
410gearman_server_con_st::worker_add(const char *function_name_arg, size_t length, uint32_t timeout)
411{
412 std::string function_name(function_name_arg, length);
413 gearman_server_worker_st *worker;
414 gearman_server_function_st *function;
415
416 if (function_name.empty())
417 return NULL;
418
419 function= thread->server->function_get(function_name);
420
421 if (function == NULL)
422 return NULL;
423
424 worker= worker_create(function);
425 if (worker == NULL)
426 return NULL;
427
428 worker->set_timeout(timeout);
429
430 return worker;
431}
432
433
434gearman_server_job_st *gearman_server_con_st::job_peek()
435{
436 gearman_server_worker_st *server_worker;
437
438 for (server_worker= worker_list; server_worker != NULL;
439 server_worker= server_worker->con_next)
440 {
441 if (server_worker->function->job_count != 0)
442 {
443 for (uint32_t priority= GEARMAN_JOB_PRIORITY_HIGH;
444 priority != GEARMAN_JOB_PRIORITY_MAX; priority++)
445 {
446 if (server_worker->function->job_list[priority] != NULL)
447 {
448 if (server_worker->function->job_list[priority]->ignore_job())
449 {
450 /* This is only happens when a client disconnects from a foreground
451 job. We do this because we don't want to run the job anymore. */
452 server_worker->function->job_list[priority]->set_ignore_job(false);
453
454 delete job_take();
455
456 return job_peek();
457 }
458 return server_worker->function->job_list[priority];
459 }
460 }
461 }
462 }
463
464 return NULL;
465}
466
467/**
468 * Appends a worker onto the end of a list of workers.
469 */
470static inline void _server_con_worker_list_append(gearman_server_worker_st *list,
471 gearman_server_worker_st *worker)
472{
473 worker->con_prev= NULL;
474 worker->con_next= list;
475 while (worker->con_next != NULL)
476 {
477 worker->con_prev= worker->con_next;
478 worker->con_next= worker->con_next->con_next;
479 }
480 if (worker->con_prev)
481 worker->con_prev->con_next= worker;
482}
483
484
485gearman_server_job_st *gearman_server_con_st::job_take()
486{
487 gearman_server_worker_st *server_worker;
488 gearman_server_job_st *server_job;
489 gearman_job_priority_t priority;
490
491 for (server_worker= worker_list; server_worker != NULL;
492 server_worker= server_worker->con_next)
493 {
494 if (server_worker->function->job_count != 0)
495 break;
496 }
497
498 if (server_worker == NULL)
499 return NULL;
500
501 if (thread->server->flags.round_robin)
502 {
503 GEARMAN_LIST_DEL(worker, server_worker, con_)
504 _server_con_worker_list_append(worker_list, server_worker);
505 ++worker_count;
506 if (worker_list == NULL)
507 {
508 worker_list= server_worker;
509 }
510 }
511
512 uint32_t x;
513 for (x= (uint32_t)GEARMAN_JOB_PRIORITY_HIGH; x != GEARMAN_JOB_PRIORITY_MAX; x++)
514 {
515 if (server_worker->function->job_list[x] != NULL)
516 break;
517 }
518 priority= (gearman_job_priority_t)x;
519
520 server_job= server_worker->function->job_list[priority];
521 server_job->function->job_list[priority]= server_job->function_next;
522 if (server_job->function->job_end[priority] == server_job)
523 server_job->function->job_end[priority]= NULL;
524 server_job->function->job_count--;
525
526 server_job->worker= server_worker;
527 server_worker->add_job(server_job);
528 server_job->function->job_running++;
529
530 if (server_job->ignore_job())
531 {
532 delete server_job;
533 return job_take();
534 }
535
536 return server_job;
537}
538
539gearman_return_t gearman_server_con_st::_server_error_packet(const char *error_code, const char *error_string)
540{
541 return io_packet_add(false, GEARMAN_MAGIC_RESPONSE,
542 GEARMAN_COMMAND_ERROR, error_code,
543 (size_t)(strlen(error_code) + 1),
544 error_string,
545 (size_t)strlen(error_string), NULL);
546}
547
548
549gearman_return_t gearman_server_con_st::_thread_packet_read()
550{
551 gearman_return_t rc;
552 gearman_server_con_st *con_this= this;
553
554 while (1)
555 {
556 if (con_this->packet == NULL)
557 {
558 con_this->packet= new gearman_server_packet_st;
559 if (con_this->packet == NULL)
560 return GEARMAN_MEMORY_ALLOCATION_FAILURE;
561 }
562
563 (void)gearman_connection_recv(con_this->con(), &(con_this->packet->packet), &rc, true);
564 if (rc != GEARMAN_SUCCESS)
565 {
566 if (rc == GEARMAN_IO_WAIT)
567 break;
568
569 delete con_this->packet;
570 con_this->packet= NULL;
571 return rc;
572 }
573
574 Log::Instance()->debug("%15s:%5s Received %s",
575 con_this->_host == NULL ? "-" : con_this->_host,
576 con_this->_port == NULL ? "-" : con_this->_port,
577 gearman_command_info_list[con_this->packet->packet.command].name);
578
579 /* We read a complete packet. */
580 if (con_this->thread->server->flags.threaded)
581 {
582 /* Multi-threaded, queue for the processing thread to run. */
583 con_this->gearman_server_proc_packet_add(con_this->packet);
584 con_this->packet= NULL;
585 }
586 else
587 {
588 /* Single threaded, run the command here. */
589 rc= gearman_server_run_command(con_this, &(con_this->packet->packet));
590 delete con_this->packet;
591 con_this->packet= NULL;
592 if (rc != GEARMAN_SUCCESS)
593 return rc;
594 }
595 }
596
597 return GEARMAN_SUCCESS;
598}
599
600gearman_return_t gearman_server_con_st::io_packet_add(bool take_data,
601 enum gearman_magic_t magic,
602 gearman_command_t command,
603 const void *arg, ...)
604{
605 gearman_server_packet_st *server_packet;
606 va_list ap;
607 size_t arg_size;
608 gearman_return_t rc;
609
610 server_packet= new gearman_server_packet_st(thread->gearman, magic, command);
611 if (server_packet == NULL)
612 return GEARMAN_MEMORY_ALLOCATION_FAILURE;
613
614 va_start(ap, arg);
615
616 while (arg != NULL)
617 {
618 arg_size = va_arg(ap, size_t);
619
620 rc= gearman_packet_create_arg(&(server_packet->packet), arg, arg_size);
621 if (rc != GEARMAN_SUCCESS)
622 {
623 va_end(ap);
624 delete server_packet;
625
626 return rc;
627 }
628
629 arg = va_arg(ap, void *);
630 }
631
632 va_end(ap);
633
634 rc= gearman_packet_pack_header(&(server_packet->packet));
635 if (rc != GEARMAN_SUCCESS)
636 {
637 delete server_packet;
638
639 return rc;
640 }
641
642 if (take_data)
643 {
644 server_packet->packet.options.free_data= true;
645 }
646
647 {
648 boost::mutex::scoped_lock l(thread->lock);
649 io_packet_list.push(server_packet);
650 }
651
652 io_add();
653
654 return GEARMAN_SUCCESS;
655}
656
657void gearman_server_con_st::io_packet_remove()
658{
659 gearman_server_packet_st *server_packet;
660 {
661 boost::mutex::scoped_lock l(thread->lock);
662 server_packet= io_packet_list.front();
663 io_packet_list.pop();
664 assert(server_packet);
665 }
666
667 delete server_packet;
668}
669
670void gearman_server_con_st::gearman_server_proc_packet_add(gearman_server_packet_st *arg)
671{
672 {
673 boost::mutex::scoped_lock l(thread->lock);
674 proc_packet_list.push(arg);
675 }
676
677 proc_add();
678}
679
680gearman_server_packet_st *gearman_server_con_st::proc_packet_remove()
681{
682 if (proc_packet_list.size() == 0)
683 return NULL;
684
685 gearman_server_packet_st *server_packet;
686 {
687 boost::mutex::scoped_lock l(thread->lock);
688 server_packet= proc_packet_list.front();
689 proc_packet_list.pop();
690 assert(server_packet);
691 }
692
693 return server_packet;
357}694}
358695
=== modified file 'libgearman-server/connection.h'
--- libgearman-server/connection.h 2010-04-06 16:34:30 +0000
+++ libgearman-server/connection.h 2010-07-01 01:31:26 +0000
@@ -1,4 +1,5 @@
1/* Gearman server and library1/* Gearman server and library
2 * Copyright (C) 2010 Data Differential
2 * Copyright (C) 2008 Brian Aker, Eric Day3 * Copyright (C) 2008 Brian Aker, Eric Day
3 * All rights reserved.4 * All rights reserved.
4 *5 *
@@ -14,9 +15,7 @@
14#ifndef __GEARMAN_SERVER_CON_H__15#ifndef __GEARMAN_SERVER_CON_H__
15#define __GEARMAN_SERVER_CON_H__16#define __GEARMAN_SERVER_CON_H__
1617
17#ifdef __cplusplus18#include <queue>
18extern "C" {
19#endif
2019
21/**20/**
22 * @addtogroup gearman_server_con Connection Declarations21 * @addtogroup gearman_server_con Connection Declarations
@@ -28,9 +27,11 @@
28 * @{27 * @{
29 */28 */
3029
30typedef std::queue<gearman_server_packet_st *> ProcPacketList;
31
31struct gearman_server_con_st32struct gearman_server_con_st
32{33{
33 gearman_connection_st con; /* This must be the first struct member. */34 gearman_connection_st _con; /* This must be the first struct member. */
34 bool is_sleeping;35 bool is_sleeping;
35 bool is_exceptions;36 bool is_exceptions;
36 bool is_dead;37 bool is_dead;
@@ -39,166 +40,158 @@
39 bool io_list;40 bool io_list;
40 bool proc_list;41 bool proc_list;
41 bool proc_removed;42 bool proc_removed;
42 uint32_t io_packet_count;
43 uint32_t proc_packet_count;
44 uint32_t worker_count;43 uint32_t worker_count;
45 uint32_t client_count;44 uint32_t client_count;
46 gearman_server_thread_st *thread;45 gearman_server_thread_st *thread;
47 gearman_server_con_st *next;
48 gearman_server_con_st *prev;
49 gearman_server_packet_st *packet;46 gearman_server_packet_st *packet;
50 gearman_server_packet_st *io_packet_list;47 ProcPacketList io_packet_list;
51 gearman_server_packet_st *io_packet_end;48 ProcPacketList proc_packet_list;
52 gearman_server_packet_st *proc_packet_list;
53 gearman_server_packet_st *proc_packet_end;
54 gearman_server_con_st *io_next;49 gearman_server_con_st *io_next;
55 gearman_server_con_st *io_prev;50 gearman_server_con_st *io_prev;
56 gearman_server_con_st *proc_next;51 gearman_server_con_st *proc_next;
57 gearman_server_con_st *proc_prev;52 gearman_server_con_st *proc_prev;
58 gearman_server_worker_st *worker_list;53 gearman_server_worker_st *worker_list;
59 gearman_server_client_st *client_list;54 gearman_server_client_st *client_list;
60 const char *host;55 const char *_host;
61 const char *port;56 const char *_port;
62 char id[GEARMAN_SERVER_CON_ID_SIZE];57 char _id[GEARMAN_SERVER_CON_ID_SIZE];
58
59 gearman_server_con_st(gearman_server_thread_st *thread_arg);
60 ~gearman_server_con_st();
61
62 void free_workers();
63public:
64 gearman_server_client_st *client_create();
65 gearman_server_client_st *client_add();
66
67 gearman_return_t _server_run_text(gearman_packet_st *packet);
68
69 /**
70 * Remove connection from the io thread list.
71 */
72 void io_remove();
73
74 /**
75 * Add connection to the proc thread list.
76 */
77 void proc_add();
78
79 gearman_server_packet_st *proc_packet_remove();
80
81 /**
82 * Remove the first server packet structure from io queue for a connection.
83 */
84 void io_packet_remove();
85
86 /**
87 * Remove connection from the proc thread list.
88 */
89 void proc_remove();
90
91 /**
92 * Get gearman connection pointer the server connection uses.
93 */
94 gearman_connection_st *con()
95 {
96 return &_con;
97 }
98
99 /**
100 * Set client id.
101 */
102 void set_id(char *id_arg, size_t size);
103
104 /**
105 * Set client port.
106 */
107 void set_port(const char *port);
108
109 /**
110 * Set client host.
111 */
112 void set_host(const char *host_arg);
113
114 /**
115 * Get client host.
116 */
117 const char *host()
118 {
119 return _host;
120 }
121
122 /**
123 * Get client port.
124 */
125 const char *port()
126 {
127 return _port;
128 }
129
130 /**
131 * Get client id.
132 */
133 const char *id()
134 {
135 return _id;
136 }
137
138 /**
139 * Get application data pointer.
140 */
141 const void *data();
142
143 /**
144 * Add connection to the io thread list.
145 */
146 void io_add();
147
148 /**
149 * Free server worker struction with name for a server connection.
150 */
151 void free_worker(const char *function_name_arg,
152 size_t function_name_size_arg);
153
154 /**
155 * Add a server packet structure to io queue for a connection.
156 */
157 gearman_return_t io_packet_add(bool take_data,
158 enum gearman_magic_t magic,
159 gearman_command_t command,
160 const void *arg, ...);
161
162 /**
163 * Add a new worker to a server instance.
164 */
165 gearman_server_worker_st *
166 worker_add(const char *function_name, size_t function_name_size, uint32_t timeout);
167
168 gearman_server_worker_st *
169 worker_create(gearman_server_function_st *function);
170
171 /**
172 * See if there are any jobs to be run for the server worker connection.
173 */
174 gearman_server_job_st *job_peek();
175
176 /**
177 * Start running a job for the server worker connection.
178 */
179 gearman_server_job_st *job_take();
180
181 gearman_return_t _thread_packet_read();
182
183/**
184 * Remove the first server packet structure from proc queue for a connection.
185 */
186
187 gearman_return_t _server_error_packet(const char *error_code, const char *error_string);
188
189 /**
190 * Add a server packet structure to proc queue for a connection.
191 */
192 void gearman_server_proc_packet_add(gearman_server_packet_st *packet);
63};193};
64194
65/**
66 * Add a connection to a server thread. This goes into a list of connections
67 * that is used later with server_thread_run, no socket I/O happens here.
68 * @param thread Thread structure previously initialized with
69 * gearman_server_thread_create.
70 * @param fd File descriptor for a newly accepted connection.
71 * @param data Application data pointer.
72 * @return Gearman server connection pointer.
73 */
74GEARMAN_API
75gearman_server_con_st *gearman_server_con_add(gearman_server_thread_st *thread,
76 int fd, void *data);
77
78/**
79 * Initialize a server connection structure.
80 */
81GEARMAN_API
82gearman_server_con_st *
83gearman_server_con_create(gearman_server_thread_st *thread);
84
85/**
86 * Free a server connection structure.
87 */
88GEARMAN_API
89void gearman_server_con_free(gearman_server_con_st *con);
90
91/**
92 * Get gearman connection pointer the server connection uses.
93 */
94GEARMAN_API
95gearman_connection_st *gearman_server_con_con(gearman_server_con_st *con);
96
97/**
98 * Get application data pointer.
99 */
100GEARMAN_API
101const void *gearman_server_con_data(const gearman_server_con_st *con);
102
103/**
104 * Set application data pointer.
105 */
106GEARMAN_API
107void gearman_server_con_set_data(gearman_server_con_st *con, void *data);
108
109/**
110 * Get client host.
111 */
112GEARMAN_API
113const char *gearman_server_con_host(gearman_server_con_st *con);
114
115/**
116 * Set client host.
117 */
118GEARMAN_API
119void gearman_server_con_set_host(gearman_server_con_st *con, const char *host);
120
121/**
122 * Get client port.
123 */
124GEARMAN_API
125const char *gearman_server_con_port(gearman_server_con_st *con);
126
127/**
128 * Set client port.
129 */
130GEARMAN_API
131void gearman_server_con_set_port(gearman_server_con_st *con, const char *port);
132
133/**
134 * Get client id.
135 */
136GEARMAN_API
137const char *gearman_server_con_id(gearman_server_con_st *con);
138
139/**
140 * Set client id.
141 */
142GEARMAN_API
143void gearman_server_con_set_id(gearman_server_con_st *con, char *id,
144 size_t size);
145
146/**
147 * Free server worker struction with name for a server connection.
148 */
149GEARMAN_API
150void gearman_server_con_free_worker(gearman_server_con_st *con,
151 char *function_name,
152 size_t function_name_size);
153
154/**
155 * Free all server worker structures for a server connection.
156 */
157GEARMAN_API
158void gearman_server_con_free_workers(gearman_server_con_st *con);
159
160/**
161 * Add connection to the io thread list.
162 */
163GEARMAN_API
164void gearman_server_con_io_add(gearman_server_con_st *con);
165
166/**
167 * Remove connection from the io thread list.
168 */
169GEARMAN_API
170void gearman_server_con_io_remove(gearman_server_con_st *con);
171
172/**
173 * Get next connection from the io thread list.
174 */
175GEARMAN_API
176gearman_server_con_st *
177gearman_server_con_io_next(gearman_server_thread_st *thread);
178
179/**
180 * Add connection to the proc thread list.
181 */
182GEARMAN_API
183void gearman_server_con_proc_add(gearman_server_con_st *con);
184
185/**
186 * Remove connection from the proc thread list.
187 */
188GEARMAN_API
189void gearman_server_con_proc_remove(gearman_server_con_st *con);
190
191/**
192 * Get next connection from the proc thread list.
193 */
194GEARMAN_API
195gearman_server_con_st *
196gearman_server_con_proc_next(gearman_server_thread_st *thread);
197
198/** @} */195/** @} */
199196
200#ifdef __cplusplus
201}
202#endif
203
204#endif /* __GEARMAN_SERVER_CON_H__ */197#endif /* __GEARMAN_SERVER_CON_H__ */
205198
=== modified file 'libgearman-server/constants.h'
--- libgearman-server/constants.h 2010-04-06 19:40:28 +0000
+++ libgearman-server/constants.h 2010-07-01 01:31:26 +0000
@@ -1,4 +1,5 @@
1/* Gearman server and library1/* Gearman server and library
2 * Copyright (C) 2010 Data Differential
2 * Copyright (C) 2008 Brian Aker, Eric Day3 * Copyright (C) 2008 Brian Aker, Eric Day
3 * All rights reserved.4 * All rights reserved.
4 *5 *
@@ -14,10 +15,6 @@
14#ifndef __GEARMAN_SERVER_CONSTANTS_H__15#ifndef __GEARMAN_SERVER_CONSTANTS_H__
15#define __GEARMAN_SERVER_CONSTANTS_H__16#define __GEARMAN_SERVER_CONSTANTS_H__
1617
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/**18/**
22 * @addtogroup gearman_server_constants Constants19 * @addtogroup gearman_server_constants Constants
23 * @ingroup gearman_server20 * @ingroup gearman_server
@@ -70,13 +67,13 @@
70typedef struct gearman_server_client_st gearman_server_client_st;67typedef struct gearman_server_client_st gearman_server_client_st;
71typedef struct gearman_server_worker_st gearman_server_worker_st;68typedef struct gearman_server_worker_st gearman_server_worker_st;
72typedef struct gearman_server_job_st gearman_server_job_st;69typedef struct gearman_server_job_st gearman_server_job_st;
73typedef struct gearmand_st gearmand_st;
74typedef struct gearmand_port_st gearmand_port_st;70typedef struct gearmand_port_st gearmand_port_st;
75typedef struct gearmand_con_st gearmand_con_st;71typedef struct gearmand_con_st gearmand_con_st;
76typedef struct gearmand_thread_st gearmand_thread_st;72typedef struct gearmand_thread_st gearmand_thread_st;
77typedef struct gearman_conf_st gearman_conf_st;73typedef struct gearman_conf_st gearman_conf_st;
78typedef struct gearman_conf_option_st gearman_conf_option_st;74typedef struct gearman_conf_option_st gearman_conf_option_st;
79typedef struct gearman_conf_module_st gearman_conf_module_st;75typedef struct gearman_conf_module_st gearman_conf_module_st;
76struct gearmand_st;
8077
81/* Function types. */78/* Function types. */
82typedef void (gearman_server_thread_run_fn)(gearman_server_thread_st *thread,79typedef void (gearman_server_thread_run_fn)(gearman_server_thread_st *thread,
@@ -91,35 +88,9 @@
91 const void *data,88 const void *data,
92 size_t data_size,89 size_t data_size,
93 gearman_job_priority_t priority);90 gearman_job_priority_t priority);
94typedef gearman_return_t (gearman_queue_flush_fn)(gearman_server_st *server,
95 void *context);
96typedef gearman_return_t (gearman_queue_done_fn)(gearman_server_st *server,
97 void *context,
98 const void *unique,
99 size_t unique_size,
100 const void *function_name,
101 size_t function_name_size);
102typedef gearman_return_t (gearman_queue_replay_fn)(gearman_server_st *server,
103 void *context,
104 gearman_queue_add_fn *add_fn,
105 void *add_context);
10691
107typedef gearman_return_t (gearman_connection_add_fn)(gearman_connection_st *con);92typedef gearman_return_t (gearman_connection_add_fn)(gearman_connection_st *con);
10893
109/** @} */94/** @} */
11095
111/**
112 * @addtogroup gearman_server_protocol Protocol Plugins
113 * @ingroup gearman_server
114 */
115
116/**
117 * @addtogroup gearman_server_queue Queue Plugins
118 * @ingroup gearman_server
119 */
120
121#ifdef __cplusplus
122}
123#endif
124
125#endif /* __GEARMAN_SERVER_CONSTANTS_H__ */96#endif /* __GEARMAN_SERVER_CONSTANTS_H__ */
12697
=== renamed file 'libgearman-server/function.c' => 'libgearman-server/function.cc'
--- libgearman-server/function.c 2010-04-06 21:41:46 +0000
+++ libgearman-server/function.cc 2010-07-01 01:31:26 +0000
@@ -1,4 +1,5 @@
1/* Gearman server and library1/* Gearman server and library
2 * Copyright (C) 2010 Data Differential
2 * Copyright (C) 2008 Brian Aker, Eric Day3 * Copyright (C) 2008 Brian Aker, Eric Day
3 * All rights reserved.4 * All rights reserved.
4 *5 *
@@ -11,33 +12,55 @@
11 * @brief Server function definitions12 * @brief Server function definitions
12 */13 */
1314
14#include "common.h"15#include "libgearman-server/common.h"
1516
16/*17/*
17 * Public definitions18 * Public definitions
18 */19 */
1920
21gearman_server_function_st::gearman_server_function_st(gearman_server_st *server_arg,
22 const std::string &function_name_arg) :
23 worker_count(0),
24 job_count(0),
25 job_total(0),
26 job_running(0),
27 max_queue_size(GEARMAN_DEFAULT_MAX_QUEUE_SIZE),
28 server(server_arg),
29 next(NULL),
30 prev(NULL),
31 function_name(function_name_arg),
32 worker_list(NULL)
33{
34 memset(job_list, 0, sizeof(gearman_server_job_st *) * GEARMAN_JOB_PRIORITY_MAX);
35 memset(job_end, 0, sizeof(gearman_server_job_st *) * GEARMAN_JOB_PRIORITY_MAX);
36}
37
38gearman_server_function_st::~gearman_server_function_st()
39{
40}
41
20gearman_server_function_st *42gearman_server_function_st *
21gearman_server_function_get(gearman_server_st *server,43gearman_server_st::function_get(const std::string &function_name_arg)
22 const char *function_name,
23 size_t function_name_size)
24{44{
25 gearman_server_function_st *function;45 gearman_server_function_st *function;
2646
27 for (function= server->function_list; function != NULL;47 if (function_name_arg.empty())
48 return NULL;
49
50 for (function= function_list; function != NULL;
28 function= function->next)51 function= function->next)
29 {52 {
30 if (function->function_name_size == function_name_size &&53 if (not function->function_name.compare(function_name_arg))
31 !memcmp(function->function_name, function_name, function_name_size))
32 {54 {
33 return function;55 return function;
34 }56 }
35 }57 }
3658
37 function= gearman_server_function_create(server, NULL);59 function= gearman_server_function_create(this, function_name_arg);
38 if (function == NULL)60 if (function == NULL)
39 return NULL;61 return NULL;
4062
63<<<<<<< TREE
41 function->function_name= (char *)malloc(function_name_size + 1);64 function->function_name= (char *)malloc(function_name_size + 1);
42 if (function->function_name == NULL)65 if (function->function_name == NULL)
43 {66 {
@@ -49,13 +72,15 @@
49 function->function_name[function_name_size]= 0;72 function->function_name[function_name_size]= 0;
50 function->function_name_size= function_name_size;73 function->function_name_size= function_name_size;
5174
75=======
76>>>>>>> MERGE-SOURCE
52 return function;77 return function;
53}78}
5479
55gearman_server_function_st *80gearman_server_function_st *gearman_server_function_create(gearman_server_st *server,
56gearman_server_function_create(gearman_server_st *server,81 const std::string &function_name)
57 gearman_server_function_st *function)
58{82{
83<<<<<<< TREE
59 if (function == NULL)84 if (function == NULL)
60 {85 {
61 function= (gearman_server_function_st *)malloc(sizeof(gearman_server_function_st));86 function= (gearman_server_function_st *)malloc(sizeof(gearman_server_function_st));
@@ -76,24 +101,20 @@
76 function->max_queue_size= GEARMAN_DEFAULT_MAX_QUEUE_SIZE;101 function->max_queue_size= GEARMAN_DEFAULT_MAX_QUEUE_SIZE;
77 function->function_name_size= 0;102 function->function_name_size= 0;
78 function->server= server;103 function->server= server;
104=======
105 gearman_server_function_st *function;
106
107 function= new gearman_server_function_st(server, function_name);
108
109>>>>>>> MERGE-SOURCE
79 GEARMAN_LIST_ADD(server->function, function,)110 GEARMAN_LIST_ADD(server->function, function,)
80 function->function_name= NULL;
81 function->worker_list= NULL;
82 memset(function->job_list, 0,
83 sizeof(gearman_server_job_st *) * GEARMAN_JOB_PRIORITY_MAX);
84 memset(function->job_end, 0,
85 sizeof(gearman_server_job_st *) * GEARMAN_JOB_PRIORITY_MAX);
86111
87 return function;112 return function;
88}113}
89114
90void gearman_server_function_free(gearman_server_function_st *function)115void gearman_server_function_free(gearman_server_function_st *function)
91{116{
92 if (function->function_name != NULL)117 GEARMAN_LIST_DEL(function->server->function, function,);
93 free(function->function_name);118
94119 delete function;
95 GEARMAN_LIST_DEL(function->server->function, function,)
96
97 if (function->options.allocated)
98 free(function);
99}120}
100121
=== modified file 'libgearman-server/function.h'
--- libgearman-server/function.h 2010-03-11 19:52:09 +0000
+++ libgearman-server/function.h 2010-07-01 01:31:26 +0000
@@ -1,4 +1,5 @@
1/* Gearman server and library1/* Gearman server and library
2 * Copyright (C) 2010 Data Differential
2 * Copyright (C) 2008 Brian Aker, Eric Day3 * Copyright (C) 2008 Brian Aker, Eric Day
3 * All rights reserved.4 * All rights reserved.
4 *5 *
@@ -14,9 +15,7 @@
14#ifndef __GEARMAN_SERVER_FUNCTION_H__15#ifndef __GEARMAN_SERVER_FUNCTION_H__
15#define __GEARMAN_SERVER_FUNCTION_H__16#define __GEARMAN_SERVER_FUNCTION_H__
1617
17#ifdef __cplusplus18#include <string>
18extern "C" {
19#endif
2019
21/**20/**
22 * @addtogroup gearman_server_function Function Declarations21 * @addtogroup gearman_server_function Function Declarations
@@ -41,32 +40,24 @@
41 uint32_t job_total;40 uint32_t job_total;
42 uint32_t job_running;41 uint32_t job_running;
43 uint32_t max_queue_size;42 uint32_t max_queue_size;
44 size_t function_name_size;
45 gearman_server_st *server;43 gearman_server_st *server;
46 gearman_server_function_st *next;44 gearman_server_function_st *next;
47 gearman_server_function_st *prev;45 gearman_server_function_st *prev;
48 char *function_name;46 std::string function_name;
49 gearman_server_worker_st *worker_list;47 gearman_server_worker_st *worker_list;
50 gearman_server_job_st *job_list[GEARMAN_JOB_PRIORITY_MAX];48 gearman_server_job_st *job_list[GEARMAN_JOB_PRIORITY_MAX];
51 gearman_server_job_st *job_end[GEARMAN_JOB_PRIORITY_MAX];49 gearman_server_job_st *job_end[GEARMAN_JOB_PRIORITY_MAX];
50
51 gearman_server_function_st(gearman_server_st *server, const std::string &function_name_arg);
52 ~gearman_server_function_st();
52};53};
5354
54/**55/**
55 * Add a new function to a server instance.
56 */
57GEARMAN_API
58gearman_server_function_st *
59gearman_server_function_get(gearman_server_st *server,
60 const char *function_name,
61 size_t function_name_size);
62
63/**
64 * Initialize a server function structure.56 * Initialize a server function structure.
65 */57 */
66GEARMAN_API58GEARMAN_API
67gearman_server_function_st *59gearman_server_function_st *
68gearman_server_function_create(gearman_server_st *server,60gearman_server_function_create(gearman_server_st *server, const std::string &function_name_arg);
69 gearman_server_function_st *function);
7061
71/**62/**
72 * Free a server function structure.63 * Free a server function structure.
@@ -76,8 +67,4 @@
7667
77/** @} */68/** @} */
7869
79#ifdef __cplusplus
80}
81#endif
82
83#endif /* __GEARMAN_SERVER_FUNCTION_H__ */70#endif /* __GEARMAN_SERVER_FUNCTION_H__ */
8471
=== renamed file 'libgearman-server/gearmand.c' => 'libgearman-server/gearmand.cc'
--- libgearman-server/gearmand.c 2010-04-06 21:41:46 +0000
+++ libgearman-server/gearmand.cc 2010-07-01 01:31:26 +0000
@@ -1,4 +1,5 @@
1/* Gearman server and library1/* Gearman server and library
2 * Copyright (C) 2010 Data Differential
2 * Copyright (C) 2008 Brian Aker, Eric Day3 * Copyright (C) 2008 Brian Aker, Eric Day
3 * All rights reserved.4 * All rights reserved.
4 *5 *
@@ -11,43 +12,14 @@
11 * @brief Gearmand Definitions12 * @brief Gearmand Definitions
12 */13 */
1314
14#include "common.h"15#include "libgearman-server/common.h"
15#include "gearmand.h"16#include "gearmand.h"
1617
17/*18/*
18 * Private declarations
19 */
20
21/**
22 * @addtogroup gearmand_private Private Gearman Daemon Functions
23 * @ingroup gearmand
24 * @{
25 */
26
27static void _log(const char *line, gearman_verbose_t verbose, void *context);
28
29static gearman_return_t _listen_init(gearmand_st *gearmand);
30static void _listen_close(gearmand_st *gearmand);
31static gearman_return_t _listen_watch(gearmand_st *gearmand);
32static void _listen_clear(gearmand_st *gearmand);
33static void _listen_event(int fd, short events, void *arg);
34
35static gearman_return_t _wakeup_init(gearmand_st *gearmand);
36static void _wakeup_close(gearmand_st *gearmand);
37static gearman_return_t _wakeup_watch(gearmand_st *gearmand);
38static void _wakeup_clear(gearmand_st *gearmand);
39static void _wakeup_event(int fd, short events, void *arg);
40
41static gearman_return_t _watch_events(gearmand_st *gearmand);
42static void _clear_events(gearmand_st *gearmand);
43static void _close_events(gearmand_st *gearmand);
44
45/** @} */
46
47/*
48 * Public definitions19 * Public definitions
49 */20 */
5021
22<<<<<<< TREE
51gearmand_st *gearmand_create(const char *host, in_port_t port)23gearmand_st *gearmand_create(const char *host, in_port_t port)
52{24{
53 gearmand_st *gearmand;25 gearmand_st *gearmand;
@@ -82,10 +54,33 @@
82 gearmand->thread_list= NULL;54 gearmand->thread_list= NULL;
83 gearmand->thread_add_next= NULL;55 gearmand->thread_add_next= NULL;
84 gearmand->free_dcon_list= NULL;56 gearmand->free_dcon_list= NULL;
57=======
58static in_port_t global_port= 0;
59
60in_port_t libgearmand_server_port()
61{
62 return global_port;
63}
64
65gearmand_st::gearmand_st(const char *host_arg,
66 in_port_t port,
67 uint32_t threads_arg) :
68 ret(GEARMAN_SUCCESS),
69 backlog(0),
70 is_listen_event(false),
71 threads(threads_arg),
72 host(0),
73 base(0),
74 port_list(0),
75 thread_add_next(0)
76{
77 host= host_arg;
78>>>>>>> MERGE-SOURCE
8579
86 if (port == 0)80 if (port == 0)
87 port= GEARMAN_DEFAULT_TCP_PORT;81 port= GEARMAN_DEFAULT_TCP_PORT;
8882
83<<<<<<< TREE
89 if (gearmand_port_add(gearmand, port, NULL) != GEARMAN_SUCCESS)84 if (gearmand_port_add(gearmand, port, NULL) != GEARMAN_SUCCESS)
90 {85 {
91 gearmand_free(gearmand);86 gearmand_free(gearmand);
@@ -188,109 +183,137 @@
188183
189 gearmand->port_list= port_list;184 gearmand->port_list= port_list;
190 gearmand->port_count++;185 gearmand->port_count++;
186=======
187 global_port= port;
188
189 port_add(port);
190}
191
192gearmand_st::~gearmand_st()
193{
194 _close_events();
195
196 Log::Instance()->info("Stopping Services");
197
198 Services::Instance()->stop();
199
200 thread_add_next= thread_list.end();
201
202 if (thread_list.size())
203 {
204 Log::Instance()->info("Shutting down all threads");
205 }
206 for (std::vector<ThreadPtr>::iterator iter= thread_list.begin();
207 iter != thread_list.end();
208 iter++)
209 {
210 delete *iter;
211 }
212 thread_list.clear();
213
214 if (base != NULL)
215 event_base_free(base);
216
217 port_list.clear();
218
219 Log::Instance()->info("Shutdown complete");
220}
221
222gearman_return_t gearmand_st::port_add(in_port_t port,
223 gearman_connection_add_fn *function,
224 Protocol *protocol)
225{
226 PortPtr new_port(new gearmand_port_st(this, port, function, protocol));
227
228 port_list.push_back(new_port);
229>>>>>>> MERGE-SOURCE
191230
192 return GEARMAN_SUCCESS;231 return GEARMAN_SUCCESS;
193}232}
194233
195gearman_return_t gearmand_run(gearmand_st *gearmand)234gearman_return_t gearmand_st::run()
196{235{
197 uint32_t x;
198236
199 /* Initialize server components. */237 /* Initialize server components. */
200 if (gearmand->base == NULL)238 if (base == NULL)
201 {239 {
202 gearmand_log_info(gearmand, "Starting up");240 Log::Instance()->info("Starting up");
203241
204 if (gearmand->threads > 0)242 if (threads > 0)
205 {243 {
206#ifndef HAVE_EVENT_BASE_NEW244#ifndef HAVE_EVENT_BASE_NEW
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 "
208 "thread-safe interface.");246 "thread-safe interface.");
209 return GEARMAN_EVENT;247 return GEARMAN_EVENT;
210#else
211 /* Set the number of free connection structures each thread should keep
212 around before the main thread is forced to take them. We compute this
213 here so we don't need to on every new connection. */
214 gearmand->max_thread_free_dcon_count= ((GEARMAN_MAX_FREE_SERVER_CON /
215 gearmand->threads) / 2);
216#endif248#endif
217 }249 }
218250
219 gearmand_log_debug(gearmand, "Initializing libevent for main thread");251 Log::Instance()->debug("Initializing libevent for main thread");
220252
221 gearmand->base= event_base_new();253 base= event_base_new();
222 if (gearmand->base == NULL)254 if (base == NULL)
223 {255 {
224 gearmand_log_fatal(gearmand, "gearmand_run:event_base_new:NULL");256 Log::Instance()->fatal("gearmand_run:event_base_new:NULL");
225 return GEARMAN_EVENT;257 return GEARMAN_EVENT;
226 }258 }
227259
228 gearmand_log_debug(gearmand, "Method for libevent: %s",260 Log::Instance()->debug("Method for libevent: %s", event_base_get_method(base));
229 event_base_get_method(gearmand->base));261
230262 ret= _listen_init();
231 gearmand->ret= _listen_init(gearmand);263 if (ret != GEARMAN_SUCCESS)
232 if (gearmand->ret != GEARMAN_SUCCESS)264 return ret;
233 return gearmand->ret;265
234266 ret= _wakeup_init(base);
235 gearmand->ret= _wakeup_init(gearmand);267 if (ret != GEARMAN_SUCCESS)
236 if (gearmand->ret != GEARMAN_SUCCESS)268 return ret;
237 return gearmand->ret;269
238270 Log::Instance()->debug("Creating %u threads", threads);
239 gearmand_log_debug(gearmand, "Creating %u threads", gearmand->threads);
240271
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. */
242 x= 0;273 uint32_t x= 0;
243 do274 do
244 {275 {
245 gearmand->ret= gearmand_thread_create(gearmand);276 ThreadPtr thread(new gearmand_thread_st(this));
246 if (gearmand->ret != GEARMAN_SUCCESS)277 thread_list.push_back(thread);
247 return gearmand->ret;278
279 if (ret != GEARMAN_SUCCESS)
280 return ret;
248 x++;281 x++;
249 }282 } while (x < threads);
250 while (x < gearmand->threads);283
251284 thread_add_next= thread_list.end();
252 gearmand->ret= gearman_server_queue_replay(&(gearmand->server));285
253 if (gearmand->ret != GEARMAN_SUCCESS)286 ret= server.queue_replay();
254 return gearmand->ret;287 if (ret != GEARMAN_SUCCESS)
288 return ret;
255 }289 }
256290
257 gearmand->ret= _watch_events(gearmand);291 ret= _watch_events();
258 if (gearmand->ret != GEARMAN_SUCCESS)292 if (ret != GEARMAN_SUCCESS)
259 return gearmand->ret;293 return ret;
260294
261 gearmand_log_info(gearmand, "Entering main event loop");295 Log::Instance()->info("Starting Services");
262296
263 if (event_base_loop(gearmand->base, 0) == -1)297 Services::Instance()->start();
298
299 Log::Instance()->info("Entering main event loop");
300
301 if (event_base_loop(base, 0) == -1)
264 {302 {
265 gearmand_log_fatal(gearmand, "gearmand_run:event_base_loop:-1");303 Log::Instance()->fatal("gearmand_run:event_base_loop:-1");
266 return GEARMAN_EVENT;304 return GEARMAN_EVENT;
267 }305 }
268306
269 gearmand_log_info(gearmand, "Exited main event loop");307 Log::Instance()->info("Exited main event loop");
270308
271 return gearmand->ret;309 return ret;
272}310}
273
274void gearmand_wakeup(gearmand_st *gearmand, gearmand_wakeup_t wakeup)
275{
276 uint8_t buffer= wakeup;
277
278 /* If this fails, there is not much we can really do. This should never fail
279 though if the main gearmand thread is still active. */
280 if (write(gearmand->wakeup_fd[1], &buffer, 1) != 1)
281 gearmand_log_error(gearmand, "gearmand_wakeup:write:%d", errno);
282}
283
284void gearmand_set_round_robin(gearmand_st *gearmand, bool round_robin)
285{
286 gearmand->server.flags.round_robin= round_robin;
287}
288
289311
290/*312/*
291 * Private definitions313 * Private definitions
292 */314 */
293315
316<<<<<<< TREE
294static void _log(const char *line, gearman_verbose_t verbose, void *context)317static void _log(const char *line, gearman_verbose_t verbose, void *context)
295{318{
296 gearmand_st *gearmand= (gearmand_st *)context;319 gearmand_st *gearmand= (gearmand_st *)context;
@@ -623,21 +646,86 @@
623 void *arg)646 void *arg)
624{647{
625 gearmand_st *gearmand= (gearmand_st *)arg;648 gearmand_st *gearmand= (gearmand_st *)arg;
649=======
650gearman_return_t gearmand_st::_listen_init()
651{
652 for (std::vector<PortPtr>::iterator iter= port_list.begin();
653 iter != port_list.end(); iter++)
654 {
655 gearman_return_t rc= (*iter)->_listen_init(host, base, backlog);
656
657 if (rc != GEARMAN_SUCCESS)
658 return rc;
659 }
660
661 return GEARMAN_SUCCESS;
662}
663
664void gearmand_st::_listen_close()
665{
666 _listen_clear();
667}
668
669gearman_return_t gearmand_st::_listen_watch()
670{
671 if (is_listen_event)
672 return GEARMAN_SUCCESS;
673
674 for (std::vector<PortPtr>::iterator iter= port_list.begin(); iter != port_list.end(); iter++)
675 {
676
677 gearman_return_t rc= (*iter)->_listen_watch();
678
679 if (rc == GEARMAN_EVENT)
680 return GEARMAN_EVENT;
681 }
682
683 is_listen_event= true;
684 return GEARMAN_SUCCESS;
685}
686
687void gearmand_st::_listen_clear()
688{
689 if (! (is_listen_event))
690 return;
691
692 for (std::vector<PortPtr>::iterator iter= port_list.begin(); iter != port_list.end(); iter++)
693 {
694 (*iter)->_listen_clear();
695 }
696
697 is_listen_event= false;
698}
699
700void gearmand_st::_wake_up_thread_for_shutdown()
701{
702 for (std::vector<ThreadPtr>::iterator iter= thread_list.begin();
703 iter != thread_list.end();
704 iter++)
705 {
706 (*iter)->set_wakeup(GEARMAND_WAKEUP_SHUTDOWN_GRACEFUL);
707 }
708}
709
710void gearmand_st::_wakeup_event(int fd, short events __attribute__ ((unused)))
711{
712 gearmand_st *gearmand= (gearmand_st *)this;
713>>>>>>> MERGE-SOURCE
626 uint8_t buffer[GEARMAN_PIPE_BUFFER_SIZE];714 uint8_t buffer[GEARMAN_PIPE_BUFFER_SIZE];
627 ssize_t ret;
628 gearmand_thread_st *thread;
629715
630 while (1)716 while (1)
631 {717 {
632 ret= read(fd, buffer, GEARMAN_PIPE_BUFFER_SIZE);718 ssize_t rc;
633 if (ret == 0)719 rc= read(fd, buffer, GEARMAN_PIPE_BUFFER_SIZE);
720 if (rc == 0)
634 {721 {
635 _clear_events(gearmand);722 gearmand->_clear_events();
636 gearmand_log_fatal(gearmand, "_wakeup_event:read:EOF");723 Log::Instance()->fatal("_wakeup_event:read:EOF");
637 gearmand->ret= GEARMAN_PIPE_EOF;724 gearmand->ret= GEARMAN_PIPE_EOF;
725
638 return;726 return;
639 }727 }
640 else if (ret == -1)728 else if (rc == -1)
641 {729 {
642 if (errno == EINTR)730 if (errno == EINTR)
643 continue;731 continue;
@@ -645,46 +733,42 @@
645 if (errno == EAGAIN)733 if (errno == EAGAIN)
646 break;734 break;
647735
648 _clear_events(gearmand);736 gearmand->_clear_events();
649 gearmand_log_fatal(gearmand, "_wakeup_event:read:%d", errno);737 Log::Instance()->fatal("_wakeup_event:read:%d", errno);
650 gearmand->ret= GEARMAN_ERRNO;738 gearmand->ret= GEARMAN_ERRNO;
651 return;739 return;
652 }740 }
653741
654 for (ssize_t x= 0; x < ret; x++)742 for (ssize_t x= 0; x < rc; x++)
655 {743 {
656 switch ((gearmand_wakeup_t)buffer[x])744 switch ((gearmand_wakeup_t)buffer[x])
657 {745 {
658 case GEARMAND_WAKEUP_PAUSE:746 case GEARMAND_WAKEUP_PAUSE:
659 gearmand_log_info(gearmand, "Received PAUSE wakeup event");747 Log::Instance()->info("Received PAUSE wakeup event");
660 _clear_events(gearmand);748 gearmand->_clear_events();
661 gearmand->ret= GEARMAN_PAUSE;749 gearmand->ret= GEARMAN_PAUSE;
662 break;750 break;
663751
664 case GEARMAND_WAKEUP_SHUTDOWN_GRACEFUL:752 case GEARMAND_WAKEUP_SHUTDOWN_GRACEFUL:
665 gearmand_log_info(gearmand, "Received SHUTDOWN_GRACEFUL wakeup event");753 Log::Instance()->info("Received SHUTDOWN_GRACEFUL wakeup event");
666 _listen_close(gearmand);
667754
668 for (thread= gearmand->thread_list; thread != NULL;755 gearmand->_listen_close();
669 thread= thread->next)756 gearmand->_wake_up_thread_for_shutdown();
670 {
671 gearmand_thread_wakeup(thread, GEARMAND_WAKEUP_SHUTDOWN_GRACEFUL);
672 }
673757
674 gearmand->ret= GEARMAN_SHUTDOWN_GRACEFUL;758 gearmand->ret= GEARMAN_SHUTDOWN_GRACEFUL;
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches