vincentchu-handlersocket 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. data/ext/HandlerSocket-Plugin-for-MySQL/AUTHORS +22 -0
  2. data/ext/HandlerSocket-Plugin-for-MySQL/COPYING +30 -0
  3. data/ext/HandlerSocket-Plugin-for-MySQL/ChangeLog +12 -0
  4. data/ext/HandlerSocket-Plugin-for-MySQL/Makefile.am +87 -0
  5. data/ext/HandlerSocket-Plugin-for-MySQL/README +78 -0
  6. data/ext/HandlerSocket-Plugin-for-MySQL/autogen.sh +117 -0
  7. data/ext/HandlerSocket-Plugin-for-MySQL/client/Makefile.am +24 -0
  8. data/ext/HandlerSocket-Plugin-for-MySQL/client/hsclient.cpp +88 -0
  9. data/ext/HandlerSocket-Plugin-for-MySQL/client/hslongrun.cpp +1041 -0
  10. data/ext/HandlerSocket-Plugin-for-MySQL/client/hspool_test.pl +224 -0
  11. data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest.cpp +1532 -0
  12. data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest.pl +228 -0
  13. data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_hs.sh +4 -0
  14. data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_hs_more50.sh +4 -0
  15. data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_md.sh +7 -0
  16. data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_my.sh +3 -0
  17. data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_my_more50.sh +3 -0
  18. data/ext/HandlerSocket-Plugin-for-MySQL/configure.ac +144 -0
  19. data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/about-handlersocket.en.txt +72 -0
  20. data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/configuration-options.en.txt +99 -0
  21. data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/installation.en.txt +92 -0
  22. data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/perl-client.en.txt +135 -0
  23. data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/protocol.en.txt +205 -0
  24. data/ext/HandlerSocket-Plugin-for-MySQL/docs-ja/about-handlersocket.ja.txt +51 -0
  25. data/ext/HandlerSocket-Plugin-for-MySQL/docs-ja/installation.ja.txt +88 -0
  26. data/ext/HandlerSocket-Plugin-for-MySQL/docs-ja/perl-client.ja.txt +127 -0
  27. data/ext/HandlerSocket-Plugin-for-MySQL/docs-ja/protocol.ja.txt +180 -0
  28. data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/COPYRIGHT.txt +27 -0
  29. data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/Makefile.am +10 -0
  30. data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/Makefile.plain.template +31 -0
  31. data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/database.cpp +1190 -0
  32. data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/database.hpp +142 -0
  33. data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/handlersocket.cpp +222 -0
  34. data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/handlersocket.spec.template +29 -0
  35. data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/hstcpsvr.cpp +149 -0
  36. data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/hstcpsvr.hpp +58 -0
  37. data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/hstcpsvr_worker.cpp +951 -0
  38. data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/hstcpsvr_worker.hpp +35 -0
  39. data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/mysql_incl.hpp +50 -0
  40. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/COPYRIGHT.txt +27 -0
  41. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/Makefile.am +12 -0
  42. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/Makefile.plain +27 -0
  43. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/allocator.hpp +64 -0
  44. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/auto_addrinfo.hpp +49 -0
  45. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/auto_file.hpp +64 -0
  46. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/auto_ptrcontainer.hpp +67 -0
  47. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/config.cpp +67 -0
  48. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/config.hpp +32 -0
  49. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/escape.cpp +127 -0
  50. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/escape.hpp +66 -0
  51. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/fatal.cpp +36 -0
  52. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/fatal.hpp +22 -0
  53. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/hstcpcli.cpp +441 -0
  54. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/hstcpcli.hpp +62 -0
  55. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/libhsclient.spec.template +39 -0
  56. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/mutex.hpp +51 -0
  57. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/socket.cpp +186 -0
  58. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/socket.hpp +51 -0
  59. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/string_buffer.hpp +118 -0
  60. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/string_ref.hpp +63 -0
  61. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/string_util.cpp +182 -0
  62. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/string_util.hpp +53 -0
  63. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/thread.hpp +84 -0
  64. data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/util.hpp +25 -0
  65. data/ext/HandlerSocket-Plugin-for-MySQL/misc/microbench-hs.log +130 -0
  66. data/ext/HandlerSocket-Plugin-for-MySQL/misc/microbench-my.log +125 -0
  67. data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/COPYRIGHT.txt +27 -0
  68. data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/Changes +6 -0
  69. data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/HandlerSocket.xs +632 -0
  70. data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/MANIFEST +8 -0
  71. data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/Makefile.PL +18 -0
  72. data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/Makefile.PL.installed +20 -0
  73. data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/README +30 -0
  74. data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/lib/Net/HandlerSocket.pm +68 -0
  75. data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/lib/Net/HandlerSocket/Pool.pm +362 -0
  76. data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/perl-Net-HandlerSocket.spec.template +127 -0
  77. data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/ppport.h +6375 -0
  78. data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/t/Net-HandlerSocket.t +15 -0
  79. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/Makefile +79 -0
  80. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/common/binary_my.cnf +4 -0
  81. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/common/compat.sh +29 -0
  82. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/common/hstest.pm +66 -0
  83. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/Makefile +4 -0
  84. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/run.sh +27 -0
  85. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test01.expected +100 -0
  86. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test01.pl +38 -0
  87. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test02.expected +100 -0
  88. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test02.pl +49 -0
  89. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test03.expected +771 -0
  90. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test03.pl +61 -0
  91. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test04.expected +0 -0
  92. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test04.pl +63 -0
  93. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test05.expected +771 -0
  94. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test05.pl +59 -0
  95. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test06.expected +644 -0
  96. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test06.pl +90 -0
  97. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test07.expected +304 -0
  98. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test07.pl +98 -0
  99. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test08.expected +2 -0
  100. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test08.pl +48 -0
  101. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test09.expected +12 -0
  102. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test09.pl +67 -0
  103. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test10.expected +771 -0
  104. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test10.pl +93 -0
  105. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test11.expected +37 -0
  106. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test11.pl +112 -0
  107. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test12.expected +273 -0
  108. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test12.pl +134 -0
  109. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test13.expected +92 -0
  110. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test13.pl +92 -0
  111. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test14.expected +144 -0
  112. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test14.pl +80 -0
  113. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test15.expected +764 -0
  114. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test15.pl +114 -0
  115. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test16.expected +66 -0
  116. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test16.pl +88 -0
  117. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test17.expected +0 -0
  118. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test17.pl +125 -0
  119. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test18.expected +22 -0
  120. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test18.pl +63 -0
  121. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test19.expected +14894 -0
  122. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test19.pl +190 -0
  123. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test20.expected +2 -0
  124. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test20.pl +33 -0
  125. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test21.expected +11 -0
  126. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test21.pl +58 -0
  127. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test22.expected +9 -0
  128. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test22.pl +61 -0
  129. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test23.expected +101 -0
  130. data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test23.pl +53 -0
  131. data/ext/winebarrel-ruby-handlersocket-c19841e47ea2/README +33 -0
  132. data/ext/winebarrel-ruby-handlersocket-c19841e47ea2/extconf.rb +27 -0
  133. data/ext/winebarrel-ruby-handlersocket-c19841e47ea2/handlersocket.cpp +437 -0
  134. data/ext/winebarrel-ruby-handlersocket-c19841e47ea2/handlersocket.h +32 -0
  135. 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
+