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.
- 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,62 @@
|
|
|
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_HSTCPCLI_HPP
|
|
10
|
+
#define DENA_HSTCPCLI_HPP
|
|
11
|
+
|
|
12
|
+
#include <sys/types.h>
|
|
13
|
+
#include <sys/socket.h>
|
|
14
|
+
#include <string>
|
|
15
|
+
#include <memory>
|
|
16
|
+
|
|
17
|
+
#include "config.hpp"
|
|
18
|
+
#include "socket.hpp"
|
|
19
|
+
#include "string_ref.hpp"
|
|
20
|
+
#include "string_buffer.hpp"
|
|
21
|
+
|
|
22
|
+
namespace dena {
|
|
23
|
+
|
|
24
|
+
struct hstcpcli_filter {
|
|
25
|
+
string_ref filter_type;
|
|
26
|
+
string_ref op;
|
|
27
|
+
size_t ff_offset;
|
|
28
|
+
string_ref val;
|
|
29
|
+
hstcpcli_filter() : ff_offset(0) { }
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
struct hstcpcli_i;
|
|
33
|
+
typedef std::auto_ptr<hstcpcli_i> hstcpcli_ptr;
|
|
34
|
+
|
|
35
|
+
struct hstcpcli_i {
|
|
36
|
+
virtual ~hstcpcli_i() { }
|
|
37
|
+
virtual void close() = 0;
|
|
38
|
+
virtual int reconnect() = 0;
|
|
39
|
+
virtual bool stable_point() = 0;
|
|
40
|
+
virtual void request_buf_auth(const char *secret, const char *typ) = 0;
|
|
41
|
+
virtual void request_buf_open_index(size_t pst_id, const char *dbn,
|
|
42
|
+
const char *tbl, const char *idx, const char *retflds,
|
|
43
|
+
const char *filflds = 0) = 0;
|
|
44
|
+
virtual void request_buf_exec_generic(size_t pst_id, const string_ref& op,
|
|
45
|
+
const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip,
|
|
46
|
+
const string_ref& mod_op, const string_ref *mvs, size_t mvslen,
|
|
47
|
+
const hstcpcli_filter *fils = 0, size_t filslen = 0,
|
|
48
|
+
int invalues_keypart = -1, const string_ref *invalues = 0,
|
|
49
|
+
size_t invalueslen = 0) = 0; // FIXME: too long
|
|
50
|
+
virtual int request_send() = 0;
|
|
51
|
+
virtual int response_recv(size_t& num_flds_r) = 0;
|
|
52
|
+
virtual const string_ref *get_next_row() = 0;
|
|
53
|
+
virtual void response_buf_remove() = 0;
|
|
54
|
+
virtual int get_error_code() = 0;
|
|
55
|
+
virtual std::string get_error() = 0;
|
|
56
|
+
static hstcpcli_ptr create(const socket_args& args);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
#endif
|
|
62
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Summary: handlersocket client library
|
|
2
|
+
Name: libhsclient
|
|
3
|
+
Version: HANDLERSOCKET_VERSION
|
|
4
|
+
Release: 1%{?dist}
|
|
5
|
+
Group: System Environment/Libraries
|
|
6
|
+
License: BSD
|
|
7
|
+
Source: libhsclient.tar.gz
|
|
8
|
+
Packager: Akira Higuchi <higuchi dot akira at dena dot jp>
|
|
9
|
+
BuildRoot: /var/tmp/%{name}-%{version}-root
|
|
10
|
+
|
|
11
|
+
%description
|
|
12
|
+
|
|
13
|
+
%prep
|
|
14
|
+
%setup -n %{name}
|
|
15
|
+
|
|
16
|
+
%define _use_internal_dependency_generator 0
|
|
17
|
+
|
|
18
|
+
%build
|
|
19
|
+
make -f Makefile.plain
|
|
20
|
+
|
|
21
|
+
%install
|
|
22
|
+
rm -rf $RPM_BUILD_ROOT
|
|
23
|
+
mkdir -p $RPM_BUILD_ROOT/usr/include/handlersocket
|
|
24
|
+
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
|
|
25
|
+
mkdir -p $RPM_BUILD_ROOT/%{_libdir}
|
|
26
|
+
install -m 755 libhsclient.a $RPM_BUILD_ROOT/%{_libdir}
|
|
27
|
+
install -m 644 *.hpp $RPM_BUILD_ROOT/usr/include/handlersocket/
|
|
28
|
+
|
|
29
|
+
%post
|
|
30
|
+
/sbin/ldconfig
|
|
31
|
+
|
|
32
|
+
%postun
|
|
33
|
+
/sbin/ldconfig
|
|
34
|
+
|
|
35
|
+
%files
|
|
36
|
+
%defattr(-, root, root)
|
|
37
|
+
/usr/include/*
|
|
38
|
+
%{_libdir}/*.a
|
|
39
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
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_MUTEX_HPP
|
|
10
|
+
#define DENA_MUTEX_HPP
|
|
11
|
+
|
|
12
|
+
#include <pthread.h>
|
|
13
|
+
#include <stdlib.h>
|
|
14
|
+
|
|
15
|
+
#include "fatal.hpp"
|
|
16
|
+
#include "util.hpp"
|
|
17
|
+
|
|
18
|
+
namespace dena {
|
|
19
|
+
|
|
20
|
+
struct condition;
|
|
21
|
+
|
|
22
|
+
struct mutex : private noncopyable {
|
|
23
|
+
friend struct condition;
|
|
24
|
+
mutex() {
|
|
25
|
+
if (pthread_mutex_init(&mtx, 0) != 0) {
|
|
26
|
+
fatal_abort("pthread_mutex_init");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
~mutex() {
|
|
30
|
+
if (pthread_mutex_destroy(&mtx) != 0) {
|
|
31
|
+
fatal_abort("pthread_mutex_destroy");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
void lock() const {
|
|
35
|
+
if (pthread_mutex_lock(&mtx) != 0) {
|
|
36
|
+
fatal_abort("pthread_mutex_lock");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
void unlock() const {
|
|
40
|
+
if (pthread_mutex_unlock(&mtx) != 0) {
|
|
41
|
+
fatal_abort("pthread_mutex_unlock");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
private:
|
|
45
|
+
mutable pthread_mutex_t mtx;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
#endif
|
|
51
|
+
|
|
@@ -0,0 +1,186 @@
|
|
|
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 <stdexcept>
|
|
10
|
+
#include <string.h>
|
|
11
|
+
#include <errno.h>
|
|
12
|
+
#include <unistd.h>
|
|
13
|
+
#include <fcntl.h>
|
|
14
|
+
#include <signal.h>
|
|
15
|
+
#include <sys/un.h>
|
|
16
|
+
|
|
17
|
+
#include "socket.hpp"
|
|
18
|
+
#include "string_util.hpp"
|
|
19
|
+
#include "fatal.hpp"
|
|
20
|
+
|
|
21
|
+
namespace dena {
|
|
22
|
+
|
|
23
|
+
void
|
|
24
|
+
ignore_sigpipe()
|
|
25
|
+
{
|
|
26
|
+
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
|
|
27
|
+
fatal_abort("SIGPIPE SIG_IGN");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void
|
|
32
|
+
socket_args::set(const config& conf)
|
|
33
|
+
{
|
|
34
|
+
timeout = conf.get_int("timeout", 600);
|
|
35
|
+
listen_backlog = conf.get_int("listen_backlog", 256);
|
|
36
|
+
std::string node = conf.get_str("host", "");
|
|
37
|
+
std::string port = conf.get_str("port", "");
|
|
38
|
+
if (!node.empty() || !port.empty()) {
|
|
39
|
+
if (family == AF_UNIX || node == "/") {
|
|
40
|
+
set_unix_domain(port.c_str());
|
|
41
|
+
} else {
|
|
42
|
+
const char *nd = node.empty() ? 0 : node.c_str();
|
|
43
|
+
if (resolve(nd, port.c_str()) != 0) {
|
|
44
|
+
fatal_exit("getaddrinfo failed: " + node + ":" + port);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
sndbuf = conf.get_int("sndbuf", 0);
|
|
49
|
+
rcvbuf = conf.get_int("rcvbuf", 0);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void
|
|
53
|
+
socket_args::set_unix_domain(const char *path)
|
|
54
|
+
{
|
|
55
|
+
family = AF_UNIX;
|
|
56
|
+
addr = sockaddr_storage();
|
|
57
|
+
addrlen = sizeof(sockaddr_un);
|
|
58
|
+
sockaddr_un *const ap = reinterpret_cast<sockaddr_un *>(&addr);
|
|
59
|
+
ap->sun_family = AF_UNIX;
|
|
60
|
+
strncpy(ap->sun_path, path, sizeof(ap->sun_path) - 1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
int
|
|
64
|
+
socket_args::resolve(const char *node, const char *service)
|
|
65
|
+
{
|
|
66
|
+
const int flags = (node == 0) ? AI_PASSIVE : 0;
|
|
67
|
+
auto_addrinfo ai;
|
|
68
|
+
addr = sockaddr_storage();
|
|
69
|
+
addrlen = 0;
|
|
70
|
+
const int r = ai.resolve(node, service, flags, family, socktype, protocol);
|
|
71
|
+
if (r != 0) {
|
|
72
|
+
return r;
|
|
73
|
+
}
|
|
74
|
+
memcpy(&addr, ai.get()->ai_addr, ai.get()->ai_addrlen);
|
|
75
|
+
addrlen = ai.get()->ai_addrlen;
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
int
|
|
80
|
+
socket_set_options(auto_file& fd, const socket_args& args, std::string& err_r)
|
|
81
|
+
{
|
|
82
|
+
if (args.timeout != 0 && !args.nonblocking) {
|
|
83
|
+
struct timeval tv = { };
|
|
84
|
+
tv.tv_sec = args.timeout;
|
|
85
|
+
tv.tv_usec = 0;
|
|
86
|
+
if (setsockopt(fd.get(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) != 0) {
|
|
87
|
+
return errno_string("setsockopt SO_RCVTIMEO", errno, err_r);
|
|
88
|
+
}
|
|
89
|
+
tv.tv_sec = args.timeout;
|
|
90
|
+
tv.tv_usec = 0;
|
|
91
|
+
if (setsockopt(fd.get(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) != 0) {
|
|
92
|
+
return errno_string("setsockopt SO_RCVTIMEO", errno, err_r);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (args.nonblocking && fcntl(fd.get(), F_SETFL, O_NONBLOCK) != 0) {
|
|
96
|
+
return errno_string("fcntl O_NONBLOCK", errno, err_r);
|
|
97
|
+
}
|
|
98
|
+
if (args.sndbuf != 0) {
|
|
99
|
+
const int v = args.sndbuf;
|
|
100
|
+
if (setsockopt(fd.get(), SOL_SOCKET, SO_SNDBUF, &v, sizeof(v)) != 0) {
|
|
101
|
+
return errno_string("setsockopt SO_SNDBUF", errno, err_r);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (args.rcvbuf != 0) {
|
|
105
|
+
const int v = args.rcvbuf;
|
|
106
|
+
if (setsockopt(fd.get(), SOL_SOCKET, SO_RCVBUF, &v, sizeof(v)) != 0) {
|
|
107
|
+
return errno_string("setsockopt SO_RCVBUF", errno, err_r);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
int
|
|
114
|
+
socket_open(auto_file& fd, const socket_args& args, std::string& err_r)
|
|
115
|
+
{
|
|
116
|
+
fd.reset(socket(args.family, args.socktype, args.protocol));
|
|
117
|
+
if (fd.get() < 0) {
|
|
118
|
+
return errno_string("socket", errno, err_r);
|
|
119
|
+
}
|
|
120
|
+
return socket_set_options(fd, args, err_r);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
int
|
|
124
|
+
socket_connect(auto_file& fd, const socket_args& args, std::string& err_r)
|
|
125
|
+
{
|
|
126
|
+
int r = 0;
|
|
127
|
+
if ((r = socket_open(fd, args, err_r)) != 0) {
|
|
128
|
+
return r;
|
|
129
|
+
}
|
|
130
|
+
if (connect(fd.get(), reinterpret_cast<const sockaddr *>(&args.addr),
|
|
131
|
+
args.addrlen) != 0) {
|
|
132
|
+
if (!args.nonblocking || errno != EINPROGRESS) {
|
|
133
|
+
return errno_string("connect", errno, err_r);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
int
|
|
140
|
+
socket_bind(auto_file& fd, const socket_args& args, std::string& err_r)
|
|
141
|
+
{
|
|
142
|
+
fd.reset(socket(args.family, args.socktype, args.protocol));
|
|
143
|
+
if (fd.get() < 0) {
|
|
144
|
+
return errno_string("socket", errno, err_r);
|
|
145
|
+
}
|
|
146
|
+
if (args.reuseaddr) {
|
|
147
|
+
if (args.family == AF_UNIX) {
|
|
148
|
+
const sockaddr_un *const ap =
|
|
149
|
+
reinterpret_cast<const sockaddr_un *>(&args.addr);
|
|
150
|
+
if (unlink(ap->sun_path) != 0 && errno != ENOENT) {
|
|
151
|
+
return errno_string("unlink uds", errno, err_r);
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
int v = 1;
|
|
155
|
+
if (setsockopt(fd.get(), SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v)) != 0) {
|
|
156
|
+
return errno_string("setsockopt SO_REUSEADDR", errno, err_r);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (bind(fd.get(), reinterpret_cast<const sockaddr *>(&args.addr),
|
|
161
|
+
args.addrlen) != 0) {
|
|
162
|
+
return errno_string("bind", errno, err_r);
|
|
163
|
+
}
|
|
164
|
+
if (listen(fd.get(), args.listen_backlog) != 0) {
|
|
165
|
+
return errno_string("listen", errno, err_r);
|
|
166
|
+
}
|
|
167
|
+
if (args.nonblocking && fcntl(fd.get(), F_SETFL, O_NONBLOCK) != 0) {
|
|
168
|
+
return errno_string("fcntl O_NONBLOCK", errno, err_r);
|
|
169
|
+
}
|
|
170
|
+
return 0;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
int
|
|
174
|
+
socket_accept(int listen_fd, auto_file& fd, const socket_args& args,
|
|
175
|
+
sockaddr_storage& addr_r, socklen_t& addrlen_r, std::string& err_r)
|
|
176
|
+
{
|
|
177
|
+
fd.reset(accept(listen_fd, reinterpret_cast<sockaddr *>(&addr_r),
|
|
178
|
+
&addrlen_r));
|
|
179
|
+
if (fd.get() < 0) {
|
|
180
|
+
return errno_string("accept", errno, err_r);
|
|
181
|
+
}
|
|
182
|
+
return socket_set_options(fd, args, err_r);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
};
|
|
186
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
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_SOCKET_HPP
|
|
10
|
+
#define DENA_SOCKET_HPP
|
|
11
|
+
|
|
12
|
+
#include <string>
|
|
13
|
+
|
|
14
|
+
#include "auto_addrinfo.hpp"
|
|
15
|
+
#include "auto_file.hpp"
|
|
16
|
+
#include "config.hpp"
|
|
17
|
+
|
|
18
|
+
namespace dena {
|
|
19
|
+
|
|
20
|
+
struct socket_args {
|
|
21
|
+
sockaddr_storage addr;
|
|
22
|
+
socklen_t addrlen;
|
|
23
|
+
int family;
|
|
24
|
+
int socktype;
|
|
25
|
+
int protocol;
|
|
26
|
+
int timeout;
|
|
27
|
+
int listen_backlog;
|
|
28
|
+
bool reuseaddr;
|
|
29
|
+
bool nonblocking;
|
|
30
|
+
bool use_epoll;
|
|
31
|
+
int sndbuf;
|
|
32
|
+
int rcvbuf;
|
|
33
|
+
socket_args() : addr(), addrlen(0), family(AF_INET), socktype(SOCK_STREAM),
|
|
34
|
+
protocol(0), timeout(600), listen_backlog(256),
|
|
35
|
+
reuseaddr(true), nonblocking(false), use_epoll(false),
|
|
36
|
+
sndbuf(0), rcvbuf(0) { }
|
|
37
|
+
void set(const config& conf);
|
|
38
|
+
void set_unix_domain(const char *path);
|
|
39
|
+
int resolve(const char *node, const char *service);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
void ignore_sigpipe();
|
|
43
|
+
int socket_bind(auto_file& fd, const socket_args& args, std::string& err_r);
|
|
44
|
+
int socket_connect(auto_file& fd, const socket_args& args, std::string& err_r);
|
|
45
|
+
int socket_accept(int listen_fd, auto_file& fd, const socket_args& args,
|
|
46
|
+
sockaddr_storage& addr_r, socklen_t& addrlen_r, std::string& err_r);
|
|
47
|
+
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
#endif
|
|
51
|
+
|
|
@@ -0,0 +1,118 @@
|
|
|
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_STRING_BUFFER_HPP
|
|
10
|
+
#define DENA_STRING_BUFFER_HPP
|
|
11
|
+
|
|
12
|
+
#include <vector>
|
|
13
|
+
#include <stdlib.h>
|
|
14
|
+
#include <string.h>
|
|
15
|
+
|
|
16
|
+
#include "util.hpp"
|
|
17
|
+
#include "allocator.hpp"
|
|
18
|
+
#include "fatal.hpp"
|
|
19
|
+
|
|
20
|
+
namespace dena {
|
|
21
|
+
|
|
22
|
+
struct string_buffer : private noncopyable {
|
|
23
|
+
string_buffer() : buffer(0), begin_offset(0), end_offset(0), alloc_size(0) { }
|
|
24
|
+
~string_buffer() {
|
|
25
|
+
DENA_FREE(buffer);
|
|
26
|
+
}
|
|
27
|
+
const char *begin() const {
|
|
28
|
+
return buffer + begin_offset;
|
|
29
|
+
}
|
|
30
|
+
const char *end() const {
|
|
31
|
+
return buffer + end_offset;
|
|
32
|
+
}
|
|
33
|
+
char *begin() {
|
|
34
|
+
return buffer + begin_offset;
|
|
35
|
+
}
|
|
36
|
+
char *end() {
|
|
37
|
+
return buffer + end_offset;
|
|
38
|
+
}
|
|
39
|
+
size_t size() const {
|
|
40
|
+
return end_offset - begin_offset;
|
|
41
|
+
}
|
|
42
|
+
void clear() {
|
|
43
|
+
begin_offset = end_offset = 0;
|
|
44
|
+
}
|
|
45
|
+
void resize(size_t len) {
|
|
46
|
+
if (size() < len) {
|
|
47
|
+
reserve(len);
|
|
48
|
+
memset(buffer + end_offset, 0, len - size());
|
|
49
|
+
}
|
|
50
|
+
end_offset = begin_offset + len;
|
|
51
|
+
}
|
|
52
|
+
void reserve(size_t len) {
|
|
53
|
+
if (alloc_size >= begin_offset + len) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
size_t asz = alloc_size;
|
|
57
|
+
while (asz < begin_offset + len) {
|
|
58
|
+
if (asz == 0) {
|
|
59
|
+
asz = 16;
|
|
60
|
+
}
|
|
61
|
+
const size_t asz_n = asz << 1;
|
|
62
|
+
if (asz_n < asz) {
|
|
63
|
+
fatal_abort("string_buffer::resize() overflow");
|
|
64
|
+
}
|
|
65
|
+
asz = asz_n;
|
|
66
|
+
}
|
|
67
|
+
void *const p = DENA_REALLOC(buffer, asz);
|
|
68
|
+
if (p == 0) {
|
|
69
|
+
fatal_abort("string_buffer::resize() realloc");
|
|
70
|
+
}
|
|
71
|
+
buffer = static_cast<char *>(p);
|
|
72
|
+
alloc_size = asz;
|
|
73
|
+
}
|
|
74
|
+
void erase_front(size_t len) {
|
|
75
|
+
if (len >= size()) {
|
|
76
|
+
clear();
|
|
77
|
+
} else {
|
|
78
|
+
begin_offset += len;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
char *make_space(size_t len) {
|
|
82
|
+
reserve(size() + len);
|
|
83
|
+
return buffer + end_offset;
|
|
84
|
+
}
|
|
85
|
+
void space_wrote(size_t len) {
|
|
86
|
+
len = std::min(len, alloc_size - end_offset);
|
|
87
|
+
end_offset += len;
|
|
88
|
+
}
|
|
89
|
+
template <size_t N>
|
|
90
|
+
void append_literal(const char (& str)[N]) {
|
|
91
|
+
append(str, str + N - 1);
|
|
92
|
+
}
|
|
93
|
+
void append(const char *start, const char *finish) {
|
|
94
|
+
const size_t len = finish - start;
|
|
95
|
+
reserve(size() + len);
|
|
96
|
+
memcpy(buffer + end_offset, start, len);
|
|
97
|
+
end_offset += len;
|
|
98
|
+
}
|
|
99
|
+
void append_2(const char *s1, const char *f1, const char *s2,
|
|
100
|
+
const char *f2) {
|
|
101
|
+
const size_t l1 = f1 - s1;
|
|
102
|
+
const size_t l2 = f2 - s2;
|
|
103
|
+
reserve(end_offset + l1 + l2);
|
|
104
|
+
memcpy(buffer + end_offset, s1, l1);
|
|
105
|
+
memcpy(buffer + end_offset + l1, s2, l2);
|
|
106
|
+
end_offset += l1 + l2;
|
|
107
|
+
}
|
|
108
|
+
private:
|
|
109
|
+
char *buffer;
|
|
110
|
+
size_t begin_offset;
|
|
111
|
+
size_t end_offset;
|
|
112
|
+
size_t alloc_size;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
#endif
|
|
118
|
+
|