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,53 @@
1
+ #!/usr/bin/perl
2
+
3
+ # vim:sw=2:ai
4
+
5
+ # test for 'IN', filters, and modifications
6
+
7
+ BEGIN {
8
+ push @INC, "../common/";
9
+ };
10
+
11
+ use strict;
12
+ use warnings;
13
+ use hstest;
14
+
15
+ my $dbh = hstest::init_testdb();
16
+ my $table = 'hstesttbl';
17
+ my $tablesize = 100;
18
+ $dbh->do(
19
+ "create table $table (k varchar(30) primary key, " .
20
+ "v varchar(30) not null, v2 int not null) " .
21
+ "engine = innodb");
22
+ srand(999);
23
+
24
+ my %valmap = ();
25
+
26
+ my $sth = $dbh->prepare("insert into $table values (?,?,?)");
27
+ for (my $i = 0; $i < $tablesize; ++$i) {
28
+ my $k = "k" . $i;
29
+ my $v = "v" . int(rand(1000)) . "-" . $i;
30
+ my $v2 = ($i / 10) % 2;
31
+ $sth->execute($k, $v, $v2);
32
+ $valmap{$k} = $v;
33
+ }
34
+
35
+ my $hs = hstest::get_hs_connection(undef, 9999);
36
+ my $dbname = $hstest::conf{dbname};
37
+ $hs->open_index(1, $dbname, $table, '', 'k,v,v2', 'v2');
38
+ $hs->open_index(2, $dbname, $table, '', 'v', 'v2');
39
+ my $vs = [ 'k10', 'k20x', 'k30', 'k40', 'k50' ];
40
+ # update $table set v = 'MOD' where k in $vs and v2 = '1'
41
+ my $r = $hs->execute_single(2, '=', [ '' ], 10000, 0, 'U', [ 'MOD' ],
42
+ [['F', '=', 0, '1']], 0, $vs);
43
+ $r = $hs->execute_single(1, '>=', [ '' ], 10000, 0);
44
+ shift(@$r);
45
+ print "HS\n";
46
+ my $len = scalar(@$r) / 3;
47
+ for (my $i = 0; $i < $len; ++$i) {
48
+ my $k = $r->[$i * 3];
49
+ my $v = $r->[$i * 3 + 1];
50
+ my $v2 = $r->[$i * 3 + 2];
51
+ print "$k $v $v2\n";
52
+ }
53
+
@@ -0,0 +1,33 @@
1
+ = ruby-handlersocket
2
+
3
+ == Description
4
+
5
+ Ruby bindings for HandlerSocket plugin
6
+ see http://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL
7
+
8
+ == Build
9
+
10
+ ruby extconf.rb
11
+ make
12
+
13
+ == API Specifications
14
+
15
+ see http://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL/blob/master/docs-en/perl-client.en.txt
16
+
17
+ == Example
18
+
19
+ require 'handlersocket'
20
+
21
+ hs = HandlerSocket.new('127.0.0.1', 9999)
22
+ # Args (default value)
23
+ # host(localhost), port(9998), timeout(600), listen_backlog(256)
24
+
25
+ hs.open_index(3, 'employees', 'departments', 'PRIMARY', 'dept_no,dept_name');
26
+
27
+ res = hs.execute_single(3, '>=', ['d004'], 100, 0);
28
+ # => [0, "d005", "Development", "d006", "Quality Management", "d007", "Sales", "d008", "Research", "d009", "Customer Service"]
29
+
30
+ hs.execute_insert(3, ['d999', 'XYZ']);
31
+ hs.execute_delete(3, '=', ['d007'], 1, 0);
32
+
33
+ hs.close
@@ -0,0 +1,27 @@
1
+ require 'mkmf'
2
+
3
+ def execute_cmd( cmd )
4
+ puts "Executing #{cmd}"
5
+ puts system(cmd)
6
+ end
7
+
8
+ base_dir = File.expand_path( File.dirname(__FILE__) )
9
+ libhs_dir = File.expand_path( File.join(base_dir, "../HandlerSocket-Plugin-for-MySQL/") )
10
+ libhs_inst_dir = File.join(libhs_dir, "install")
11
+ libhs_client = File.join(libhs_dir, "libhsclient")
12
+ libhs_libs = File.join(libhs_inst_dir, "lib")
13
+ libhs_include = File.join(libhs_inst_dir, "include")
14
+
15
+ puts "***** Building libhsclient"
16
+ execute_cmd %Q[cd #{libhs_dir} && ./autogen.sh]
17
+ execute_cmd %Q[cd #{libhs_dir} && ./configure --disable-handlersocket-server --prefix=#{libhs_inst_dir}]
18
+ execute_cmd %Q[cd #{libhs_dir} && make]
19
+ execute_cmd %Q[cd #{libhs_dir} && make install]
20
+ execute_cmd %Q[cp -r #{libhs_client} #{base_dir}]
21
+
22
+ puts "***** Building ruby-handlersocket"
23
+ dir_config("hsclient", libhs_include, libhs_libs)
24
+ if have_library('stdc++') and have_library('hsclient')
25
+ create_makefile('handlersocket')
26
+ end
27
+
@@ -0,0 +1,437 @@
1
+ #include <libhsclient/hstcpcli.cpp>
2
+ #include "handlersocket.h"
3
+
4
+ namespace {
5
+
6
+ void ary2vec(VALUE ary, std::vector<dena::string_ref>& vec) {
7
+ int len = RARRAY_LEN(ary);
8
+
9
+ for (int i = 0; i < len; i++) {
10
+ VALUE entry = rb_ary_entry(ary, i);
11
+
12
+ if (NIL_P(entry)) {
13
+ vec.push_back(dena::string_ref());
14
+ } else {
15
+ entry = rb_check_convert_type(entry, T_STRING, "String", "to_s");
16
+ char *s = StringValuePtr(entry);
17
+ vec.push_back(dena::string_ref(s, strlen(s)));
18
+ }
19
+ }
20
+ }
21
+
22
+ struct HandlerSocket {
23
+ dena::hstcpcli_i *tcpcli;
24
+
25
+ static void free(HandlerSocket *p) {
26
+ if (p->tcpcli) {
27
+ delete p->tcpcli;
28
+ }
29
+
30
+ delete p;
31
+ }
32
+
33
+ static VALUE alloc(VALUE klass) {
34
+ HandlerSocket *p;
35
+
36
+ p = new HandlerSocket;
37
+ p->tcpcli = NULL;
38
+
39
+ return Data_Wrap_Struct(klass, 0, &free, p);
40
+ }
41
+
42
+ static VALUE initialize(int argc, VALUE *argv, VALUE self) {
43
+ HandlerSocket *p;
44
+ VALUE host, port, timeout, listen_backlog, verbose_level;
45
+
46
+ rb_scan_args(argc, argv, "05", &host, &port, &timeout, &listen_backlog, &verbose_level);
47
+
48
+ dena::config conf;
49
+
50
+ if (NIL_P(host)) {
51
+ conf["host"] = "localhost";
52
+ } else {
53
+ Check_Type(host, T_STRING);
54
+ conf["host"] = RSTRING_PTR(host);
55
+ }
56
+
57
+ if (NIL_P(port)) {
58
+ conf["port"] = "9998";
59
+ } else {
60
+ Check_Type(port, T_FIXNUM);
61
+ port = rb_check_convert_type(port, T_STRING, "String", "to_s");
62
+ conf["port"] = StringValuePtr(port);
63
+ }
64
+
65
+ if (NIL_P(timeout)) {
66
+ conf["timeout"] = "600";
67
+ } else {
68
+ Check_Type(timeout, T_FIXNUM);
69
+ timeout = rb_check_convert_type(timeout, T_STRING, "String", "to_s");
70
+ conf["timeout"] = StringValuePtr(timeout);
71
+ }
72
+
73
+ if (NIL_P(listen_backlog)) {
74
+ conf["listen_backlog"] = "256";
75
+ } else {
76
+ Check_Type(listen_backlog, T_FIXNUM);
77
+ listen_backlog = rb_check_convert_type(listen_backlog, T_STRING, "String", "to_s");
78
+ conf["listen_backlog"] = StringValuePtr(listen_backlog);
79
+ }
80
+
81
+ if (!NIL_P(verbose_level)) {
82
+ dena::verbose_level = NUM2INT(verbose_level);
83
+ }
84
+
85
+ dena::socket_args sargs;
86
+ sargs.set(conf);
87
+ dena::hstcpcli_ptr tcpcli_ptr = dena::hstcpcli_i::create(sargs);
88
+
89
+ Data_Get_Struct(self, HandlerSocket, p);
90
+ p->tcpcli = tcpcli_ptr.get();
91
+
92
+ tcpcli_ptr.release();
93
+
94
+ return Qnil;
95
+ }
96
+
97
+ static VALUE close(VALUE self) {
98
+ HandlerSocket *p;
99
+
100
+ Data_Get_Struct(self, HandlerSocket, p);
101
+ Check_TcpCli(p);
102
+
103
+ p->tcpcli->close();
104
+
105
+ return Qnil;
106
+ }
107
+
108
+ static VALUE reconnect(VALUE self) {
109
+ HandlerSocket *p;
110
+
111
+ Data_Get_Struct(self, HandlerSocket, p);
112
+ Check_TcpCli(p);
113
+
114
+ int retval = p->tcpcli->reconnect();
115
+
116
+ return INT2FIX(retval);
117
+ }
118
+
119
+ static VALUE stable_point(VALUE self) {
120
+ HandlerSocket *p;
121
+
122
+ Data_Get_Struct(self, HandlerSocket, p);
123
+ Check_TcpCli(p);
124
+
125
+ bool retval = p->tcpcli->stable_point();
126
+
127
+ return retval ? Qtrue : Qfalse;
128
+ }
129
+
130
+ static VALUE get_error_code(VALUE self) {
131
+ HandlerSocket *p;
132
+
133
+ Data_Get_Struct(self, HandlerSocket, p);
134
+ Check_TcpCli(p);
135
+
136
+ int retval = p->tcpcli->get_error_code();
137
+
138
+ return INT2FIX(retval);
139
+ }
140
+
141
+ static VALUE get_error(VALUE self) {
142
+ HandlerSocket *p;
143
+
144
+ Data_Get_Struct(self, HandlerSocket, p);
145
+ Check_TcpCli(p);
146
+
147
+ std::string s = p->tcpcli->get_error();
148
+
149
+ return rb_str_new(s.data(), s.size());
150
+ }
151
+
152
+ static VALUE open_index(VALUE self, VALUE id, VALUE db, VALUE table, VALUE index, VALUE fields) {
153
+ HandlerSocket *p;
154
+
155
+ Data_Get_Struct(self, HandlerSocket, p);
156
+ Check_TcpCli(p);
157
+ Check_Type(id, T_FIXNUM);
158
+ Check_Type(db, T_STRING);
159
+ Check_Type(table, T_STRING);
160
+ Check_Type(index, T_STRING);
161
+ Check_Type(fields, T_STRING);
162
+
163
+ do {
164
+ p->tcpcli->request_buf_open_index(
165
+ FIX2INT(id), RSTRING_PTR(db), RSTRING_PTR(table), RSTRING_PTR(index),RSTRING_PTR(fields));
166
+
167
+ if (p->tcpcli->request_send() != 0) {
168
+ break;
169
+ }
170
+
171
+ size_t nflds = 0;
172
+ p->tcpcli->response_recv(nflds);
173
+
174
+ int e = p->tcpcli->get_error_code();
175
+
176
+ if (e >= 0) {
177
+ p->tcpcli->response_buf_remove();
178
+ }
179
+ } while (0);
180
+
181
+ int retval = p->tcpcli->get_error_code();
182
+
183
+ return INT2FIX(retval);
184
+ }
185
+
186
+ static VALUE execute_single(int argc, VALUE *argv, VALUE self) {
187
+ VALUE id, op, keys, limit, skip, modo, modvals;
188
+ char *modop = NULL;
189
+
190
+ rb_scan_args(argc, argv, "34", &id, &op, &keys, &limit, &skip, &modo, &modvals);
191
+
192
+ if (NIL_P(limit)) {
193
+ limit = INT2FIX(0);
194
+ }
195
+
196
+ if (NIL_P(skip)) {
197
+ skip = INT2FIX(0);
198
+ }
199
+
200
+ if (!NIL_P(modo)) {
201
+ Check_Type(modo, T_STRING);
202
+ Check_Type(modvals, T_ARRAY);
203
+ modop = RSTRING_PTR(modo);
204
+ }
205
+
206
+ return execute_internal(self, id, op, keys, limit, skip, modop, modvals);
207
+ }
208
+
209
+ static VALUE execute_multi(VALUE self, VALUE args) {
210
+ return execute_multi_internal(self, args);
211
+ }
212
+
213
+ static VALUE execute_update(VALUE self, VALUE id, VALUE op, VALUE keys, VALUE limit, VALUE skip, VALUE modvals) {
214
+ return execute_internal(self, id, op, keys, limit, skip, "U", modvals);
215
+ }
216
+
217
+ static VALUE execute_delete(VALUE self, VALUE id, VALUE op, VALUE keys, VALUE limit, VALUE skip) {
218
+ return execute_internal(self, id, op, keys, limit, skip, "D", rb_ary_new());
219
+ }
220
+
221
+ static VALUE execute_insert(VALUE self, VALUE id, VALUE fvals) {
222
+ VALUE op = rb_str_new("+", 1);
223
+ char *modop = NULL;
224
+ return execute_internal(self, id, op, fvals, INT2FIX(0), INT2FIX(0), modop, Qnil);
225
+ }
226
+
227
+ static void init() {
228
+ VALUE rb_cHandlerSocket = rb_define_class("HandlerSocket", rb_cObject);
229
+ rb_define_alloc_func(rb_cHandlerSocket, &alloc);
230
+
231
+ rb_define_method(rb_cHandlerSocket, "initialize", __F(&initialize), -1);
232
+ rb_define_method(rb_cHandlerSocket, "close", __F(&close), 0);
233
+ rb_define_method(rb_cHandlerSocket, "reconnect", __F(&reconnect), 0);
234
+ rb_define_method(rb_cHandlerSocket, "stable_point", __F(&stable_point), 0);
235
+ rb_define_method(rb_cHandlerSocket, "get_error_code", __F(&get_error_code), 0);
236
+ rb_define_method(rb_cHandlerSocket, "get_error", __F(&get_error), 0);
237
+ rb_define_method(rb_cHandlerSocket, "open_index", __F(&open_index), 5);
238
+ rb_define_method(rb_cHandlerSocket, "execute_single", __F(&execute_single), -1);
239
+ rb_define_method(rb_cHandlerSocket, "execute_find", __F(&execute_single), -1);
240
+ rb_define_method(rb_cHandlerSocket, "execute_multi", __F(&execute_multi), 1);
241
+ rb_define_method(rb_cHandlerSocket, "execute_update", __F(&execute_update), 6);
242
+ rb_define_method(rb_cHandlerSocket, "execute_delete", __F(&execute_delete), 5);
243
+ rb_define_method(rb_cHandlerSocket, "execute_insert", __F(&execute_insert), 2);
244
+ }
245
+
246
+ private:
247
+ static VALUE execute_internal(VALUE self, VALUE v_id, VALUE v_op, VALUE v_keys, VALUE v_limit, VALUE v_skip, char *modop, VALUE v_modvals) {
248
+ HandlerSocket *p;
249
+ VALUE retval = Qnil;
250
+
251
+ Data_Get_Struct(self, HandlerSocket, p);
252
+ Check_TcpCli(p);
253
+ Check_Type(v_id, T_FIXNUM);
254
+ Check_Type(v_op, T_STRING);
255
+ Check_Type(v_keys, T_ARRAY);
256
+ Check_Type(v_limit, T_FIXNUM);
257
+ Check_Type(v_skip, T_FIXNUM);
258
+
259
+ do {
260
+ dena::hstcpcli_i *tcpcli = p->tcpcli;
261
+ int id = FIX2INT(v_id);
262
+ dena::string_ref op = dena::string_ref(RSTRING_PTR(v_op), RSTRING_LEN(v_op));
263
+ std::vector<dena::string_ref> keyarr, mvarr;
264
+ ary2vec(v_keys, keyarr);
265
+ dena::string_ref modop_ref;
266
+
267
+ if (modop) {
268
+ modop_ref = dena::string_ref(modop, strlen(modop));
269
+ ary2vec(v_modvals, mvarr);
270
+ }
271
+
272
+ int limit = FIX2INT(v_limit);
273
+ int skip = FIX2INT(v_skip);
274
+
275
+ tcpcli->request_buf_exec_generic(
276
+ id, op, &keyarr[0], keyarr.size(), limit, skip, modop_ref, &mvarr[0], mvarr.size());
277
+
278
+ if (tcpcli->request_send() != 0) {
279
+ break;
280
+ }
281
+
282
+ size_t nflds = 0;
283
+ tcpcli->response_recv(nflds);
284
+
285
+ int e = tcpcli->get_error_code();
286
+ retval = rb_ary_new();
287
+ rb_ary_push(retval, INT2FIX(e));
288
+
289
+ if (e != 0) {
290
+ std::string s = tcpcli->get_error();
291
+ rb_ary_push(retval, rb_str_new(s.data(), s.size()));
292
+ } else {
293
+ const dena::string_ref *row = 0;
294
+
295
+ while ((row = tcpcli->get_next_row()) != 0) {
296
+ for (size_t i = 0; i < nflds; i++) {
297
+ const dena::string_ref& v = row[i];
298
+
299
+ if (v.begin() != 0) {
300
+ VALUE s = rb_str_new(v.begin(), v.size());
301
+ rb_ary_push(retval, s);
302
+ } else {
303
+ rb_ary_push(retval, Qnil);
304
+ }
305
+ }
306
+ }
307
+ }
308
+
309
+ if (e >= 0) {
310
+ tcpcli->response_buf_remove();
311
+ }
312
+ } while(0);
313
+
314
+ return retval;
315
+ }
316
+
317
+ static VALUE execute_multi_internal(VALUE self, VALUE args) {
318
+ HandlerSocket *p;
319
+ VALUE rvs = Qnil;
320
+
321
+ Data_Get_Struct(self, HandlerSocket, p);
322
+ Check_TcpCli(p);
323
+ Check_Type(args, T_ARRAY);
324
+
325
+ dena::hstcpcli_i *tcpcli = p->tcpcli;
326
+ size_t num_args = RARRAY_LEN(args);
327
+
328
+ for (size_t args_index = 0; args_index < num_args; args_index++) {
329
+ VALUE v_arg = rb_ary_entry(args, args_index);
330
+ Check_Type(v_arg, T_ARRAY);
331
+
332
+ VALUE v_id = rb_ary_entry(v_arg, 0);
333
+ VALUE v_op = rb_ary_entry(v_arg, 1);
334
+ VALUE v_keys = rb_ary_entry(v_arg, 2);
335
+ VALUE v_limit = rb_ary_entry(v_arg, 3);
336
+ VALUE v_skip = rb_ary_entry(v_arg, 4);
337
+ VALUE v_modo = rb_ary_entry(v_arg, 5);
338
+ VALUE v_modvals = rb_ary_entry(v_arg, 6);
339
+
340
+ Check_Type(v_id, T_FIXNUM);
341
+ Check_Type(v_op, T_STRING);
342
+ Check_Type(v_keys, T_ARRAY);
343
+ Check_Type(v_limit, T_FIXNUM);
344
+ Check_Type(v_skip, T_FIXNUM);
345
+
346
+ if (!NIL_P(v_modo)) {
347
+ Check_Type(v_modo, T_STRING);
348
+ Check_Type(v_modvals, T_ARRAY);
349
+ }
350
+ }
351
+
352
+ for (size_t args_index = 0; args_index < num_args; args_index++) {
353
+ VALUE v_arg = rb_ary_entry(args, args_index);
354
+ VALUE v_id = rb_ary_entry(v_arg, 0);
355
+ VALUE v_op = rb_ary_entry(v_arg, 1);
356
+ VALUE v_keys = rb_ary_entry(v_arg, 2);
357
+ VALUE v_limit = rb_ary_entry(v_arg, 3);
358
+ VALUE v_skip = rb_ary_entry(v_arg, 4);
359
+ VALUE v_modo = rb_ary_entry(v_arg, 5);
360
+ VALUE v_modvals = rb_ary_entry(v_arg, 6);
361
+
362
+ int id = FIX2INT(v_id);
363
+ dena::string_ref op = dena::string_ref(RSTRING_PTR(v_op), RSTRING_LEN(v_op));
364
+ std::vector<dena::string_ref> keyarr, mvarr;
365
+ ary2vec(v_keys, keyarr);
366
+ dena::string_ref modop_ref;
367
+
368
+ if (!NIL_P(v_modo)) {
369
+ modop_ref = dena::string_ref(RSTRING_PTR(v_modo), RSTRING_LEN(v_modo));
370
+ ary2vec(v_modvals, mvarr);
371
+ }
372
+
373
+ int limit = FIX2INT(v_limit);
374
+ int skip = FIX2INT(v_skip);
375
+
376
+ tcpcli->request_buf_exec_generic(
377
+ id, op, &keyarr[0], keyarr.size(), limit, skip, modop_ref, &mvarr[0], mvarr.size());
378
+ }
379
+
380
+ rvs = rb_ary_new();
381
+
382
+ if (tcpcli->request_send() < 0) {
383
+ VALUE retval = rb_ary_new();
384
+ rb_ary_push(rvs, retval);
385
+ rb_ary_push(retval, INT2FIX(tcpcli->get_error_code()));
386
+ const std::string& s = tcpcli->get_error();
387
+ rb_ary_push(retval, rb_str_new(s.data(), s.size()));
388
+ return rvs;
389
+ }
390
+
391
+ for (size_t args_index = 0; args_index < num_args; args_index++) {
392
+ VALUE retval = rb_ary_new();
393
+ rb_ary_push(rvs, retval);
394
+
395
+ size_t nflds = 0;
396
+ int e = tcpcli->response_recv(nflds);
397
+ rb_ary_push(retval, INT2FIX(e));
398
+
399
+ if (e != 0) {
400
+ const std::string& s = tcpcli->get_error();
401
+ rb_ary_push(retval, rb_str_new(s.data(), s.size()));
402
+ } else {
403
+ const dena::string_ref *row = 0;
404
+
405
+ while ((row = tcpcli->get_next_row()) != 0) {
406
+ for (size_t i = 0; i < nflds; i++) {
407
+ const dena::string_ref& v = row[i];
408
+
409
+ if (v.begin() != 0) {
410
+ VALUE s = rb_str_new(v.begin(), v.size());
411
+ rb_ary_push(retval, s);
412
+ } else {
413
+ rb_ary_push(retval, Qnil);
414
+ }
415
+ }
416
+ }
417
+ }
418
+
419
+ if (e >= 0) {
420
+ tcpcli->response_buf_remove();
421
+ }
422
+
423
+ if (e < 0) {
424
+ return rvs;
425
+ }
426
+ }
427
+
428
+ return rvs;
429
+ }
430
+
431
+ };
432
+
433
+ } // namespace
434
+
435
+ void Init_handlersocket() {
436
+ HandlerSocket::init();
437
+ }