gqtp 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/text/news.md +7 -0
- data/lib/gqtp/client.rb +16 -11
- data/lib/gqtp/proxy.rb +3 -3
- data/lib/gqtp/sequential-request.rb +35 -0
- data/lib/gqtp/server.rb +3 -3
- data/lib/gqtp/version.rb +1 -1
- data/test/run-test.rb +2 -1
- data/test/test-proxy.rb +29 -0
- metadata +16 -19
data/doc/text/news.md
CHANGED
data/lib/gqtp/client.rb
CHANGED
@@ -17,6 +17,7 @@
|
|
17
17
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
18
|
|
19
19
|
require "gqtp/parser"
|
20
|
+
require "gqtp/sequential-request"
|
20
21
|
|
21
22
|
module GQTP
|
22
23
|
class Client
|
@@ -32,16 +33,15 @@ module GQTP
|
|
32
33
|
header = options[:header] || Header.new
|
33
34
|
header.size = body.bytesize
|
34
35
|
|
35
|
-
write_request = @connection.write(header.pack, body) do
|
36
|
-
if block_given?
|
37
|
-
read(&block)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
36
|
if block_given?
|
42
|
-
|
37
|
+
sequential_request = SequentialRequest.new
|
38
|
+
write_request = @connection.write(header.pack, body) do
|
39
|
+
sequential_request << read(&block)
|
40
|
+
end
|
41
|
+
sequential_request << write_request
|
42
|
+
sequential_request
|
43
43
|
else
|
44
|
-
|
44
|
+
@connection.write(header.pack, body)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -49,18 +49,23 @@ module GQTP
|
|
49
49
|
sync = !block_given?
|
50
50
|
parser = Parser.new
|
51
51
|
response_body = nil
|
52
|
-
|
52
|
+
|
53
|
+
sequential_request = SequentialRequest.new
|
53
54
|
read_header_request = @connection.read(Header.size) do |header|
|
54
55
|
parser << header
|
55
56
|
read_body_request = @connection.read(parser.header.size) do |body|
|
56
57
|
response_body = body
|
57
58
|
yield(parser.header, response_body) if block_given?
|
58
59
|
end
|
60
|
+
sequential_request << read_body_request
|
59
61
|
end
|
62
|
+
sequential_request << read_header_request
|
63
|
+
|
60
64
|
if sync
|
61
|
-
|
62
|
-
read_body_request.wait
|
65
|
+
sequential_request.wait
|
63
66
|
[parser.header, response_body]
|
67
|
+
else
|
68
|
+
sequential_request
|
64
69
|
end
|
65
70
|
end
|
66
71
|
|
data/lib/gqtp/proxy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
3
|
+
# Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
|
4
4
|
#
|
5
5
|
# This library is free software; you can redistribute it and/or
|
6
6
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -40,9 +40,9 @@ module GQTP
|
|
40
40
|
end
|
41
41
|
@server.on_request do |request, client, connection|
|
42
42
|
connection.write(request.header.pack, request.body) do
|
43
|
-
|
43
|
+
connection.read(Header.size) do |header|
|
44
44
|
response_header = Header.parse(header)
|
45
|
-
|
45
|
+
connection.read(response_header.size) do |body|
|
46
46
|
client.write(header, body) do
|
47
47
|
end
|
48
48
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
module GQTP
|
20
|
+
class SequentialRequest
|
21
|
+
def initialize
|
22
|
+
@requests = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def wait
|
26
|
+
while (request = @requests.pop)
|
27
|
+
request.wait
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def <<(request)
|
32
|
+
@requests << request
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/gqtp/server.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
3
|
+
# Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
|
4
4
|
#
|
5
5
|
# This library is free software; you can redistribute it and/or
|
6
6
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -78,9 +78,9 @@ module GQTP
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def process_request(client, connect_info)
|
81
|
-
|
81
|
+
client.read(Header.size) do |header|
|
82
82
|
request_header = Header.parse(header)
|
83
|
-
|
83
|
+
client.read(request_header.size) do |body|
|
84
84
|
request = Request.new(request_header, body)
|
85
85
|
on_request(request, client, connect_info)
|
86
86
|
process_request(client, connect_info)
|
data/lib/gqtp/version.rb
CHANGED
data/test/run-test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
# -*- coding: utf-8 -*-
|
2
3
|
#
|
3
|
-
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
# Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
|
4
5
|
#
|
5
6
|
# This library is free software; you can redistribute it and/or
|
6
7
|
# modify it under the terms of the GNU Lesser General Public
|
data/test/test-proxy.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "gqtp/proxy"
|
20
|
+
|
21
|
+
class ProxyTest < Test::Unit::TestCase
|
22
|
+
def setup
|
23
|
+
@proxy = GQTP::Proxy.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown
|
27
|
+
@proxy.shutdown
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gqtp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -126,22 +126,24 @@ files:
|
|
126
126
|
- Gemfile
|
127
127
|
- gqtp.gemspec
|
128
128
|
- .yardopts
|
129
|
-
- lib/gqtp
|
130
|
-
- lib/gqtp/server.rb
|
131
|
-
- lib/gqtp/connection/thread.rb
|
132
|
-
- lib/gqtp/connection/coolio.rb
|
133
|
-
- lib/gqtp/connection/synchronous.rb
|
129
|
+
- lib/gqtp.rb
|
134
130
|
- lib/gqtp/version.rb
|
131
|
+
- lib/gqtp/connection/synchronous.rb
|
132
|
+
- lib/gqtp/connection/coolio.rb
|
133
|
+
- lib/gqtp/connection/thread.rb
|
135
134
|
- lib/gqtp/header.rb
|
136
|
-
- lib/gqtp/client.rb
|
137
|
-
- lib/gqtp/proxy.rb
|
138
135
|
- lib/gqtp/error.rb
|
139
|
-
- lib/gqtp.rb
|
140
|
-
-
|
136
|
+
- lib/gqtp/sequential-request.rb
|
137
|
+
- lib/gqtp/parser.rb
|
138
|
+
- lib/gqtp/server.rb
|
139
|
+
- lib/gqtp/proxy.rb
|
140
|
+
- lib/gqtp/client.rb
|
141
141
|
- doc/text/lgpl-2.1.txt
|
142
|
-
-
|
142
|
+
- doc/text/news.md
|
143
143
|
- test/test-header.rb
|
144
144
|
- test/test-parser.rb
|
145
|
+
- test/test-proxy.rb
|
146
|
+
- test/run-test.rb
|
145
147
|
- test/test-client.rb
|
146
148
|
- bin/gqtp-proxy
|
147
149
|
homepage: https://github.com/ranguba/gqtp
|
@@ -157,18 +159,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
159
|
- - ! '>='
|
158
160
|
- !ruby/object:Gem::Version
|
159
161
|
version: '0'
|
160
|
-
segments:
|
161
|
-
- 0
|
162
|
-
hash: 2123818797887154120
|
163
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
163
|
none: false
|
165
164
|
requirements:
|
166
165
|
- - ! '>='
|
167
166
|
- !ruby/object:Gem::Version
|
168
167
|
version: '0'
|
169
|
-
segments:
|
170
|
-
- 0
|
171
|
-
hash: 2123818797887154120
|
172
168
|
requirements: []
|
173
169
|
rubyforge_project:
|
174
170
|
rubygems_version: 1.8.23
|
@@ -177,8 +173,9 @@ specification_version: 3
|
|
177
173
|
summary: Gqtp gem is a [GQTP (Groonga Query Transfer Protocol)](http://groonga.org/docs/spec/gqtp.html)
|
178
174
|
Ruby implementation.
|
179
175
|
test_files:
|
180
|
-
- test/run-test.rb
|
181
176
|
- test/test-header.rb
|
182
177
|
- test/test-parser.rb
|
178
|
+
- test/test-proxy.rb
|
179
|
+
- test/run-test.rb
|
183
180
|
- test/test-client.rb
|
184
181
|
has_rdoc:
|