vincentchu-handlersocket 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/HandlerSocket-Plugin-for-MySQL/AUTHORS +22 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/COPYING +30 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/ChangeLog +12 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/Makefile.am +87 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/README +78 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/autogen.sh +117 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/Makefile.am +24 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hsclient.cpp +88 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hslongrun.cpp +1041 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hspool_test.pl +224 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest.cpp +1532 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest.pl +228 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_hs.sh +4 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_hs_more50.sh +4 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_md.sh +7 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_my.sh +3 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_my_more50.sh +3 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/configure.ac +144 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/about-handlersocket.en.txt +72 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/configuration-options.en.txt +99 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/installation.en.txt +92 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/perl-client.en.txt +135 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/protocol.en.txt +205 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-ja/about-handlersocket.ja.txt +51 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-ja/installation.ja.txt +88 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-ja/perl-client.ja.txt +127 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-ja/protocol.ja.txt +180 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/COPYRIGHT.txt +27 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/Makefile.am +10 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/Makefile.plain.template +31 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/database.cpp +1190 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/database.hpp +142 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/handlersocket.cpp +222 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/handlersocket.spec.template +29 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/hstcpsvr.cpp +149 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/hstcpsvr.hpp +58 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/hstcpsvr_worker.cpp +951 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/hstcpsvr_worker.hpp +35 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/mysql_incl.hpp +50 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/COPYRIGHT.txt +27 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/Makefile.am +12 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/Makefile.plain +27 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/allocator.hpp +64 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/auto_addrinfo.hpp +49 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/auto_file.hpp +64 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/auto_ptrcontainer.hpp +67 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/config.cpp +67 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/config.hpp +32 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/escape.cpp +127 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/escape.hpp +66 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/fatal.cpp +36 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/fatal.hpp +22 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/hstcpcli.cpp +441 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/hstcpcli.hpp +62 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/libhsclient.spec.template +39 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/mutex.hpp +51 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/socket.cpp +186 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/socket.hpp +51 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/string_buffer.hpp +118 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/string_ref.hpp +63 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/string_util.cpp +182 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/string_util.hpp +53 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/thread.hpp +84 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/util.hpp +25 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/misc/microbench-hs.log +130 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/misc/microbench-my.log +125 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/COPYRIGHT.txt +27 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/Changes +6 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/HandlerSocket.xs +632 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/MANIFEST +8 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/Makefile.PL +18 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/Makefile.PL.installed +20 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/README +30 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/lib/Net/HandlerSocket.pm +68 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/lib/Net/HandlerSocket/Pool.pm +362 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/perl-Net-HandlerSocket.spec.template +127 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/ppport.h +6375 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/t/Net-HandlerSocket.t +15 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/Makefile +79 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/common/binary_my.cnf +4 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/common/compat.sh +29 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/common/hstest.pm +66 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/Makefile +4 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/run.sh +27 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test01.expected +100 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test01.pl +38 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test02.expected +100 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test02.pl +49 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test03.expected +771 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test03.pl +61 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test04.expected +0 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test04.pl +63 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test05.expected +771 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test05.pl +59 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test06.expected +644 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test06.pl +90 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test07.expected +304 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test07.pl +98 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test08.expected +2 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test08.pl +48 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test09.expected +12 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test09.pl +67 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test10.expected +771 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test10.pl +93 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test11.expected +37 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test11.pl +112 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test12.expected +273 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test12.pl +134 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test13.expected +92 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test13.pl +92 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test14.expected +144 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test14.pl +80 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test15.expected +764 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test15.pl +114 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test16.expected +66 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test16.pl +88 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test17.expected +0 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test17.pl +125 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test18.expected +22 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test18.pl +63 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test19.expected +14894 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test19.pl +190 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test20.expected +2 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test20.pl +33 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test21.expected +11 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test21.pl +58 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test22.expected +9 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test22.pl +61 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test23.expected +101 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test23.pl +53 -0
- data/ext/winebarrel-ruby-handlersocket-c19841e47ea2/README +33 -0
- data/ext/winebarrel-ruby-handlersocket-c19841e47ea2/extconf.rb +27 -0
- data/ext/winebarrel-ruby-handlersocket-c19841e47ea2/handlersocket.cpp +437 -0
- data/ext/winebarrel-ruby-handlersocket-c19841e47ea2/handlersocket.h +32 -0
- metadata +200 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
// vim:sw=2:ai
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
|
6
|
+
* See COPYRIGHT.txt for details.
|
7
|
+
*/
|
8
|
+
|
9
|
+
#ifndef DENA_HSTCPSVR_WORKER_HPP
|
10
|
+
#define DENA_HSTCPSVR_WORKER_HPP
|
11
|
+
|
12
|
+
#include "hstcpsvr.hpp"
|
13
|
+
|
14
|
+
namespace dena {
|
15
|
+
|
16
|
+
struct hstcpsvr_worker_i;
|
17
|
+
typedef std::auto_ptr<hstcpsvr_worker_i> hstcpsvr_worker_ptr;
|
18
|
+
|
19
|
+
struct hstcpsvr_worker_arg {
|
20
|
+
const hstcpsvr_shared_c *cshared;
|
21
|
+
volatile hstcpsvr_shared_v *vshared;
|
22
|
+
long worker_id;
|
23
|
+
hstcpsvr_worker_arg() : cshared(0), vshared(0), worker_id(0) { }
|
24
|
+
};
|
25
|
+
|
26
|
+
struct hstcpsvr_worker_i {
|
27
|
+
virtual ~hstcpsvr_worker_i() { }
|
28
|
+
virtual void run() = 0;
|
29
|
+
static hstcpsvr_worker_ptr create(const hstcpsvr_worker_arg& arg);
|
30
|
+
};
|
31
|
+
|
32
|
+
};
|
33
|
+
|
34
|
+
#endif
|
35
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
// vim:sw=2:ai
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
|
6
|
+
* See COPYRIGHT.txt for details.
|
7
|
+
*/
|
8
|
+
|
9
|
+
#ifndef DENA_MYSQL_INCL_HPP
|
10
|
+
#define DENA_MYSQL_INCL_HPP
|
11
|
+
|
12
|
+
#ifndef HAVE_CONFIG_H
|
13
|
+
#define HAVE_CONFIG_H
|
14
|
+
#endif
|
15
|
+
|
16
|
+
#define MYSQL_DYNAMIC_PLUGIN
|
17
|
+
#define MYSQL_SERVER 1
|
18
|
+
|
19
|
+
#include <my_config.h>
|
20
|
+
|
21
|
+
#include <mysql_version.h>
|
22
|
+
|
23
|
+
#if MYSQL_VERSION_ID >= 50505
|
24
|
+
#include <my_pthread.h>
|
25
|
+
#include <sql_priv.h>
|
26
|
+
#include "sql_class.h"
|
27
|
+
#include "unireg.h"
|
28
|
+
#include "lock.h"
|
29
|
+
#include "key.h" // key_copy()
|
30
|
+
#include <my_global.h>
|
31
|
+
#include <mysql/plugin.h>
|
32
|
+
#include <transaction.h>
|
33
|
+
#include <sql_base.h>
|
34
|
+
// FIXME FIXME FIXME
|
35
|
+
#define safeFree(X) my_free(X)
|
36
|
+
#define pthread_cond_timedwait mysql_cond_timedwait
|
37
|
+
#define pthread_mutex_lock mysql_mutex_lock
|
38
|
+
#define pthread_mutex_unlock mysql_mutex_unlock
|
39
|
+
#define current_stmt_binlog_row_based is_current_stmt_binlog_format_row
|
40
|
+
#define clear_current_stmt_binlog_row_based clear_current_stmt_binlog_format_row
|
41
|
+
|
42
|
+
#else
|
43
|
+
#include "mysql_priv.h"
|
44
|
+
#endif
|
45
|
+
|
46
|
+
#undef min
|
47
|
+
#undef max
|
48
|
+
|
49
|
+
#endif
|
50
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2010 DeNA Co.,Ltd.
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
* Neither the name of DeNA Co.,Ltd. nor the names of its contributors
|
14
|
+
may be used to endorse or promote products derived from this software
|
15
|
+
without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY DeNA Co.,Ltd. "AS IS" AND ANY EXPRESS OR
|
18
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
19
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
20
|
+
EVENT SHALL DeNA Co.,Ltd. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
23
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
24
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
25
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
26
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
instdir = $(includedir)/handlersocket
|
2
|
+
# TODO: these headers should be in dena/
|
3
|
+
inst_HEADERS = allocator.hpp config.hpp mutex.hpp string_util.hpp \
|
4
|
+
auto_addrinfo.hpp escape.hpp socket.hpp thread.hpp auto_file.hpp \
|
5
|
+
fatal.hpp string_buffer.hpp util.hpp auto_ptrcontainer.hpp \
|
6
|
+
hstcpcli.hpp string_ref.hpp
|
7
|
+
lib_LTLIBRARIES = libhsclient.la
|
8
|
+
libhsclient_la_SOURCES = config.cpp escape.cpp fatal.cpp hstcpcli.cpp \
|
9
|
+
socket.cpp string_util.cpp
|
10
|
+
libhsclient_la_LDFLAGS = -static
|
11
|
+
libhsclient_la_CFLAGS = $(AM_CFLAGS)
|
12
|
+
libhsclient_la_CXXFLAGS = $(AM_CFLAGS)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
CXX = g++ -Wall -g -fno-rtti -fno-exceptions -fPIC -DPIC
|
3
|
+
LDFLAGS =
|
4
|
+
|
5
|
+
CXXFLAGS += -O3 -DNDEBUG
|
6
|
+
|
7
|
+
COMMON_OBJS = config.o fatal.o socket.o string_util.o escape.o
|
8
|
+
HSCLIENT_OBJS = $(COMMON_OBJS) hstcpcli.o
|
9
|
+
|
10
|
+
all: libhsclient.a
|
11
|
+
|
12
|
+
libhsclient.a: $(HSCLIENT_OBJS)
|
13
|
+
$(AR) rc $@ $^
|
14
|
+
$(AR) s $@
|
15
|
+
|
16
|
+
clean:
|
17
|
+
rm -f *.a *.so *.o
|
18
|
+
|
19
|
+
LIBDIR = $(shell \
|
20
|
+
if [ -e /usr/lib64/mysql ]; then echo /usr/lib64; else echo /usr/lib; fi)
|
21
|
+
|
22
|
+
install: libhsclient.a
|
23
|
+
sudo sh -c 'cp libhsclient.a libhsclient.a.cpy && \
|
24
|
+
mv libhsclient.a.cpy $(LIBDIR)/libhsclient.a && \
|
25
|
+
mkdir -p /usr/include/handlersocket && \
|
26
|
+
cp -a *.hpp /usr/include/handlersocket/'
|
27
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
// vim:sw=2:ai
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
|
6
|
+
* See COPYRIGHT.txt for details.
|
7
|
+
*/
|
8
|
+
|
9
|
+
#ifndef DENA_ALLOCATOR_HPP
|
10
|
+
#define DENA_ALLOCATOR_HPP
|
11
|
+
|
12
|
+
#include <stdlib.h>
|
13
|
+
#include <string.h>
|
14
|
+
|
15
|
+
#if 0
|
16
|
+
extern "C" {
|
17
|
+
#include <tlsf.h>
|
18
|
+
};
|
19
|
+
#define DENA_MALLOC(x) tlsf_malloc(x)
|
20
|
+
#define DENA_REALLOC(x, y) tlsf_realloc(x, y)
|
21
|
+
#define DENA_FREE(x) tlsf_free(x)
|
22
|
+
#define DENA_NEWCHAR(x) static_cast<char *>(tlsf_malloc(x))
|
23
|
+
#define DENA_DELETE(x) tlsf_free(x)
|
24
|
+
typedef std::allocator<int> allocator_type;
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#if 1
|
28
|
+
#define DENA_MALLOC(x) malloc(x)
|
29
|
+
#define DENA_REALLOC(x, y) realloc(x, y)
|
30
|
+
#define DENA_FREE(x) free(x)
|
31
|
+
#define DENA_NEWCHAR(x) (new char[x])
|
32
|
+
#define DENA_DELETE(x) (delete [] x)
|
33
|
+
typedef std::allocator<int> allocator_type;
|
34
|
+
#endif
|
35
|
+
|
36
|
+
#if 1
|
37
|
+
#define DENA_ALLOCA_ALLOCATE(typ, len) \
|
38
|
+
static_cast<typ *>(alloca((len) * sizeof(typ)))
|
39
|
+
#define DENA_ALLOCA_FREE(x)
|
40
|
+
#else
|
41
|
+
#define DENA_ALLOCA_ALLOCATE(typ, len) \
|
42
|
+
static_cast<typ *>(malloc((len) * sizeof(typ)))
|
43
|
+
#define DENA_ALLOCA_FREE(x) free(x)
|
44
|
+
#endif
|
45
|
+
|
46
|
+
namespace dena {
|
47
|
+
|
48
|
+
template <typename T> struct auto_alloca_free {
|
49
|
+
auto_alloca_free(T *value) : value(value) { }
|
50
|
+
~auto_alloca_free() {
|
51
|
+
/* no-op if alloca() is used */
|
52
|
+
DENA_ALLOCA_FREE(value);
|
53
|
+
}
|
54
|
+
private:
|
55
|
+
auto_alloca_free(const auto_alloca_free&);
|
56
|
+
auto_alloca_free& operator =(const auto_alloca_free&);
|
57
|
+
private:
|
58
|
+
T *value;
|
59
|
+
};
|
60
|
+
|
61
|
+
};
|
62
|
+
|
63
|
+
#endif
|
64
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
// vim:sw=2:ai
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
|
6
|
+
* See COPYRIGHT.txt for details.
|
7
|
+
*/
|
8
|
+
|
9
|
+
#ifndef DENA_AUTO_ADDRINFO_HPP
|
10
|
+
#define DENA_AUTO_ADDRINFO_HPP
|
11
|
+
|
12
|
+
#include <sys/types.h>
|
13
|
+
#include <sys/socket.h>
|
14
|
+
#include <netdb.h>
|
15
|
+
|
16
|
+
#include "util.hpp"
|
17
|
+
|
18
|
+
namespace dena {
|
19
|
+
|
20
|
+
struct auto_addrinfo : private noncopyable {
|
21
|
+
auto_addrinfo() : addr(0) { }
|
22
|
+
~auto_addrinfo() {
|
23
|
+
reset();
|
24
|
+
}
|
25
|
+
void reset(addrinfo *a = 0) {
|
26
|
+
if (addr != 0) {
|
27
|
+
freeaddrinfo(addr);
|
28
|
+
}
|
29
|
+
addr = a;
|
30
|
+
}
|
31
|
+
const addrinfo *get() const { return addr; }
|
32
|
+
int resolve(const char *node, const char *service, int flags = 0,
|
33
|
+
int family = AF_UNSPEC, int socktype = SOCK_STREAM, int protocol = 0) {
|
34
|
+
reset();
|
35
|
+
addrinfo hints = { };
|
36
|
+
hints.ai_flags = flags;
|
37
|
+
hints.ai_family = family;
|
38
|
+
hints.ai_socktype = socktype;
|
39
|
+
hints.ai_protocol = protocol;
|
40
|
+
return getaddrinfo(node, service, &hints, &addr);
|
41
|
+
}
|
42
|
+
private:
|
43
|
+
addrinfo *addr;
|
44
|
+
};
|
45
|
+
|
46
|
+
};
|
47
|
+
|
48
|
+
#endif
|
49
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
// vim:sw=2:ai
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
|
6
|
+
* See COPYRIGHT.txt for details.
|
7
|
+
*/
|
8
|
+
|
9
|
+
#ifndef DENA_AUTO_FILE_HPP
|
10
|
+
#define DENA_AUTO_FILE_HPP
|
11
|
+
|
12
|
+
#include <unistd.h>
|
13
|
+
#include <sys/types.h>
|
14
|
+
#include <dirent.h>
|
15
|
+
#include <stdio.h>
|
16
|
+
|
17
|
+
#include "util.hpp"
|
18
|
+
|
19
|
+
namespace dena {
|
20
|
+
|
21
|
+
struct auto_file : private noncopyable {
|
22
|
+
auto_file() : fd(-1) { }
|
23
|
+
~auto_file() {
|
24
|
+
reset();
|
25
|
+
}
|
26
|
+
int get() const { return fd; }
|
27
|
+
int close() {
|
28
|
+
if (fd < 0) {
|
29
|
+
return 0;
|
30
|
+
}
|
31
|
+
const int r = ::close(fd);
|
32
|
+
fd = -1;
|
33
|
+
return r;
|
34
|
+
}
|
35
|
+
void reset(int x = -1) {
|
36
|
+
if (fd >= 0) {
|
37
|
+
this->close();
|
38
|
+
}
|
39
|
+
fd = x;
|
40
|
+
}
|
41
|
+
private:
|
42
|
+
int fd;
|
43
|
+
};
|
44
|
+
|
45
|
+
struct auto_dir : private noncopyable {
|
46
|
+
auto_dir() : dp(0) { }
|
47
|
+
~auto_dir() {
|
48
|
+
reset();
|
49
|
+
}
|
50
|
+
DIR *get() const { return dp; }
|
51
|
+
void reset(DIR *d = 0) {
|
52
|
+
if (dp != 0) {
|
53
|
+
closedir(dp);
|
54
|
+
}
|
55
|
+
dp = d;
|
56
|
+
}
|
57
|
+
private:
|
58
|
+
DIR *dp;
|
59
|
+
};
|
60
|
+
|
61
|
+
};
|
62
|
+
|
63
|
+
#endif
|
64
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
|
2
|
+
// vim:sw=2:ai
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
|
6
|
+
* See COPYRIGHT.txt for details.
|
7
|
+
*/
|
8
|
+
|
9
|
+
#ifndef DENA_AUTO_PTRCONTAINER_HPP
|
10
|
+
#define DENA_AUTO_PTRCONTAINER_HPP
|
11
|
+
|
12
|
+
namespace dena {
|
13
|
+
|
14
|
+
template <typename Tcnt>
|
15
|
+
struct auto_ptrcontainer {
|
16
|
+
typedef Tcnt container_type;
|
17
|
+
typedef typename container_type::value_type value_type;
|
18
|
+
typedef typename container_type::pointer pointer;
|
19
|
+
typedef typename container_type::reference reference;
|
20
|
+
typedef typename container_type::const_reference const_reference;
|
21
|
+
typedef typename container_type::size_type size_type;
|
22
|
+
typedef typename container_type::difference_type difference_type;
|
23
|
+
typedef typename container_type::iterator iterator;
|
24
|
+
typedef typename container_type::const_iterator const_iterator;
|
25
|
+
typedef typename container_type::reverse_iterator reverse_iterator;
|
26
|
+
typedef typename container_type::const_reverse_iterator
|
27
|
+
const_reverse_iterator;
|
28
|
+
iterator begin() { return cnt.begin(); }
|
29
|
+
const_iterator begin() const { return cnt.begin(); }
|
30
|
+
iterator end() { return cnt.end(); }
|
31
|
+
const_iterator end() const { return cnt.end(); }
|
32
|
+
reverse_iterator rbegin() { return cnt.rbegin(); }
|
33
|
+
reverse_iterator rend() { return cnt.rend(); }
|
34
|
+
const_reverse_iterator rbegin() const { return cnt.rbegin(); }
|
35
|
+
const_reverse_iterator rend() const { return cnt.rend(); }
|
36
|
+
size_type size() const { return cnt.size(); }
|
37
|
+
size_type max_size() const { return cnt.max_size(); }
|
38
|
+
bool empty() const { return cnt.empty(); }
|
39
|
+
reference front() { return cnt.front(); }
|
40
|
+
const_reference front() const { cnt.front(); }
|
41
|
+
reference back() { return cnt.back(); }
|
42
|
+
const_reference back() const { cnt.back(); }
|
43
|
+
void swap(auto_ptrcontainer& x) { cnt.swap(x.cnt); }
|
44
|
+
~auto_ptrcontainer() {
|
45
|
+
for (iterator i = begin(); i != end(); ++i) {
|
46
|
+
delete *i;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
template <typename Tap> void push_back_ptr(Tap& ap) {
|
50
|
+
cnt.push_back(ap.get());
|
51
|
+
ap.release();
|
52
|
+
}
|
53
|
+
void erase_ptr(iterator i) {
|
54
|
+
delete *i;
|
55
|
+
cnt.erase(i);
|
56
|
+
}
|
57
|
+
reference operator [](size_type n) { return cnt[n]; }
|
58
|
+
const_reference operator [](size_type n) const { return cnt[n]; }
|
59
|
+
void clear() { cnt.clear(); }
|
60
|
+
private:
|
61
|
+
Tcnt cnt;
|
62
|
+
};
|
63
|
+
|
64
|
+
};
|
65
|
+
|
66
|
+
#endif
|
67
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
|
2
|
+
// vim:sw=2:ai
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
|
6
|
+
* See COPYRIGHT.txt for details.
|
7
|
+
*/
|
8
|
+
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <stdio.h>
|
11
|
+
#include <string.h>
|
12
|
+
|
13
|
+
#include "config.hpp"
|
14
|
+
|
15
|
+
namespace dena {
|
16
|
+
|
17
|
+
unsigned int verbose_level = 0;
|
18
|
+
|
19
|
+
std::string
|
20
|
+
config::get_str(const std::string& key, const std::string& def) const
|
21
|
+
{
|
22
|
+
const_iterator iter = this->find(key);
|
23
|
+
if (iter == this->end()) {
|
24
|
+
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s(default)\n", key.c_str(),
|
25
|
+
def.c_str()));
|
26
|
+
return def;
|
27
|
+
}
|
28
|
+
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n", key.c_str(),
|
29
|
+
iter->second.c_str()));
|
30
|
+
return iter->second;
|
31
|
+
}
|
32
|
+
|
33
|
+
long long
|
34
|
+
config::get_int(const std::string& key, long long def) const
|
35
|
+
{
|
36
|
+
const_iterator iter = this->find(key);
|
37
|
+
if (iter == this->end()) {
|
38
|
+
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld(default)\n", key.c_str(),
|
39
|
+
def));
|
40
|
+
return def;
|
41
|
+
}
|
42
|
+
const long long r = atoll(iter->second.c_str());
|
43
|
+
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld\n", key.c_str(), r));
|
44
|
+
return r;
|
45
|
+
}
|
46
|
+
|
47
|
+
void
|
48
|
+
parse_args(int argc, char **argv, config& conf)
|
49
|
+
{
|
50
|
+
for (int i = 1; i < argc; ++i) {
|
51
|
+
const char *const arg = argv[i];
|
52
|
+
const char *const eq = strchr(arg, '=');
|
53
|
+
if (eq == 0) {
|
54
|
+
continue;
|
55
|
+
}
|
56
|
+
const std::string key(arg, eq - arg);
|
57
|
+
const std::string val(eq + 1);
|
58
|
+
conf[key] = val;
|
59
|
+
}
|
60
|
+
config::const_iterator iter = conf.find("verbose");
|
61
|
+
if (iter != conf.end()) {
|
62
|
+
verbose_level = atoi(iter->second.c_str());
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
};
|
67
|
+
|