net-protocol 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/test.yml +4 -5
- data/README.md +1 -1
- data/lib/net/protocol.rb +65 -19
- data/net-protocol.gemspec +3 -6
- metadata +8 -22
- data/Gemfile.lock +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca28f0356ecc7ee77cb5d0ead1ea91d9a70446e9de9a8e4927bdd4caf8d8e910
|
4
|
+
data.tar.gz: 394be407dd3ab468f376be2032a2c6c6d78d05863bd21a9353e206ea473bbc37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52dcdc5b3c200e3f29dea711c392d6127e39cf5cdf12787bb585a41ca874ccb3b93c734145d688c4c83acf98f28f0c7e89ebc49aeeb64caa0cb172a452f9c73c
|
7
|
+
data.tar.gz: d57a73c0d8a1260012f26826ef257b4b6df616aa07e0fd46fc63710b2cd5cf3dafd322db057db1202ae1158c77d729c9e65ec3e12cc2d1705a4a2d2221cf0962
|
data/.github/workflows/test.yml
CHANGED
@@ -7,16 +7,15 @@ jobs:
|
|
7
7
|
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
|
-
ruby: [ '3.0', 2.7, 2.6
|
10
|
+
ruby: [ head, '3.1', '3.0', '2.7', '2.6' ]
|
11
11
|
os: [ ubuntu-latest, macos-latest ]
|
12
12
|
runs-on: ${{ matrix.os }}
|
13
13
|
steps:
|
14
|
-
- uses: actions/checkout@
|
14
|
+
- uses: actions/checkout@v3
|
15
15
|
- name: Set up Ruby
|
16
16
|
uses: ruby/setup-ruby@v1
|
17
17
|
with:
|
18
18
|
ruby-version: ${{ matrix.ruby }}
|
19
|
-
|
20
|
-
run: bundle install
|
19
|
+
bundler-cache: true # 'bundle install' and cache gems
|
21
20
|
- name: Run test
|
22
|
-
run: rake test
|
21
|
+
run: bundle exec rake test
|
data/README.md
CHANGED
data/lib/net/protocol.rb
CHANGED
@@ -26,7 +26,7 @@ require 'io/wait'
|
|
26
26
|
module Net # :nodoc:
|
27
27
|
|
28
28
|
class Protocol #:nodoc: internal use only
|
29
|
-
VERSION = "0.
|
29
|
+
VERSION = "0.2.0"
|
30
30
|
|
31
31
|
private
|
32
32
|
def Protocol.protocol_param(name, val)
|
@@ -120,6 +120,7 @@ module Net # :nodoc:
|
|
120
120
|
@continue_timeout = continue_timeout
|
121
121
|
@debug_output = debug_output
|
122
122
|
@rbuf = ''.b
|
123
|
+
@rbuf_offset = 0
|
123
124
|
end
|
124
125
|
|
125
126
|
attr_reader :io
|
@@ -154,14 +155,15 @@ module Net # :nodoc:
|
|
154
155
|
LOG "reading #{len} bytes..."
|
155
156
|
read_bytes = 0
|
156
157
|
begin
|
157
|
-
while read_bytes +
|
158
|
-
s =
|
159
|
-
|
160
|
-
|
158
|
+
while read_bytes + rbuf_size < len
|
159
|
+
if s = rbuf_consume_all_shareable!
|
160
|
+
read_bytes += s.bytesize
|
161
|
+
dest << s
|
162
|
+
end
|
161
163
|
rbuf_fill
|
162
164
|
end
|
163
165
|
s = rbuf_consume(len - read_bytes)
|
164
|
-
read_bytes += s.
|
166
|
+
read_bytes += s.bytesize
|
165
167
|
dest << s
|
166
168
|
rescue EOFError
|
167
169
|
raise unless ignore_eof
|
@@ -175,9 +177,10 @@ module Net # :nodoc:
|
|
175
177
|
read_bytes = 0
|
176
178
|
begin
|
177
179
|
while true
|
178
|
-
s =
|
179
|
-
|
180
|
-
|
180
|
+
if s = rbuf_consume_all_shareable!
|
181
|
+
read_bytes += s.bytesize
|
182
|
+
dest << s
|
183
|
+
end
|
181
184
|
rbuf_fill
|
182
185
|
end
|
183
186
|
rescue EOFError
|
@@ -188,14 +191,16 @@ module Net # :nodoc:
|
|
188
191
|
end
|
189
192
|
|
190
193
|
def readuntil(terminator, ignore_eof = false)
|
194
|
+
offset = @rbuf_offset
|
191
195
|
begin
|
192
|
-
until idx = @rbuf.index(terminator)
|
196
|
+
until idx = @rbuf.index(terminator, offset)
|
197
|
+
offset = @rbuf.bytesize
|
193
198
|
rbuf_fill
|
194
199
|
end
|
195
|
-
return rbuf_consume(idx + terminator.
|
200
|
+
return rbuf_consume(idx + terminator.bytesize - @rbuf_offset)
|
196
201
|
rescue EOFError
|
197
202
|
raise unless ignore_eof
|
198
|
-
return rbuf_consume
|
203
|
+
return rbuf_consume
|
199
204
|
end
|
200
205
|
end
|
201
206
|
|
@@ -208,12 +213,16 @@ module Net # :nodoc:
|
|
208
213
|
BUFSIZE = 1024 * 16
|
209
214
|
|
210
215
|
def rbuf_fill
|
211
|
-
tmp = @
|
216
|
+
tmp = @rbuf_empty ? @rbuf : nil
|
212
217
|
case rv = @io.read_nonblock(BUFSIZE, tmp, exception: false)
|
213
218
|
when String
|
214
|
-
|
215
|
-
|
216
|
-
|
219
|
+
@rbuf_empty = false
|
220
|
+
if rv.equal?(tmp)
|
221
|
+
@rbuf_offset = 0
|
222
|
+
else
|
223
|
+
@rbuf << rv
|
224
|
+
rv.clear
|
225
|
+
end
|
217
226
|
return
|
218
227
|
when :wait_readable
|
219
228
|
(io = @io.to_io).wait_readable(@read_timeout) or raise Net::ReadTimeout.new(io)
|
@@ -228,13 +237,50 @@ module Net # :nodoc:
|
|
228
237
|
end while true
|
229
238
|
end
|
230
239
|
|
231
|
-
def
|
232
|
-
if
|
240
|
+
def rbuf_flush
|
241
|
+
if @rbuf_empty
|
242
|
+
@rbuf.clear
|
243
|
+
@rbuf_offset = 0
|
244
|
+
end
|
245
|
+
nil
|
246
|
+
end
|
247
|
+
|
248
|
+
def rbuf_size
|
249
|
+
@rbuf.bytesize - @rbuf_offset
|
250
|
+
end
|
251
|
+
|
252
|
+
# Warning: this method may share the buffer to avoid
|
253
|
+
# copying. The caller must no longer use the returned
|
254
|
+
# string once rbuf_fill has been called again
|
255
|
+
def rbuf_consume_all_shareable!
|
256
|
+
@rbuf_empty = true
|
257
|
+
buf = if @rbuf_offset == 0
|
258
|
+
@rbuf
|
259
|
+
else
|
260
|
+
@rbuf.byteslice(@rbuf_offset..-1)
|
261
|
+
end
|
262
|
+
@rbuf_offset = @rbuf.bytesize
|
263
|
+
buf
|
264
|
+
end
|
265
|
+
|
266
|
+
def rbuf_consume(len = nil)
|
267
|
+
if @rbuf_offset == 0 && (len.nil? || len == @rbuf.bytesize)
|
233
268
|
s = @rbuf
|
234
269
|
@rbuf = ''.b
|
270
|
+
@rbuf_offset = 0
|
271
|
+
@rbuf_empty = true
|
272
|
+
elsif len.nil?
|
273
|
+
s = @rbuf.byteslice(@rbuf_offset..-1)
|
274
|
+
@rbuf = ''.b
|
275
|
+
@rbuf_offset = 0
|
276
|
+
@rbuf_empty = true
|
235
277
|
else
|
236
|
-
s = @rbuf.
|
278
|
+
s = @rbuf.byteslice(@rbuf_offset, len)
|
279
|
+
@rbuf_offset += len
|
280
|
+
@rbuf_empty = @rbuf_offset == @rbuf.bytesize
|
281
|
+
rbuf_flush
|
237
282
|
end
|
283
|
+
|
238
284
|
@debug_output << %Q[-> #{s.dump}\n] if @debug_output
|
239
285
|
s
|
240
286
|
end
|
data/net-protocol.gemspec
CHANGED
@@ -13,10 +13,10 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.authors = ["Yukihiro Matsumoto"]
|
14
14
|
spec.email = ["matz@ruby-lang.org"]
|
15
15
|
|
16
|
-
spec.summary = %q{The
|
17
|
-
spec.description = %q{The
|
16
|
+
spec.summary = %q{The abstract interface for net-* client.}
|
17
|
+
spec.description = %q{The abstract interface for net-* client.}
|
18
18
|
spec.homepage = "https://github.com/ruby/net-protocol"
|
19
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
19
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
20
20
|
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
21
21
|
|
22
22
|
spec.metadata["homepage_uri"] = spec.homepage
|
@@ -27,10 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
28
28
|
`git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
29
29
|
end
|
30
|
-
spec.bindir = "exe"
|
31
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
30
|
spec.require_paths = ["lib"]
|
33
31
|
|
34
32
|
spec.add_dependency "timeout"
|
35
|
-
spec.add_dependency "io-wait"
|
36
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yukihiro Matsumoto
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: timeout
|
@@ -24,31 +24,17 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
|
28
|
-
name: io-wait
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
description: The abstruct interface for net-* client.
|
27
|
+
description: The abstract interface for net-* client.
|
42
28
|
email:
|
43
29
|
- matz@ruby-lang.org
|
44
30
|
executables: []
|
45
31
|
extensions: []
|
46
32
|
extra_rdoc_files: []
|
47
33
|
files:
|
34
|
+
- ".github/dependabot.yml"
|
48
35
|
- ".github/workflows/test.yml"
|
49
36
|
- ".gitignore"
|
50
37
|
- Gemfile
|
51
|
-
- Gemfile.lock
|
52
38
|
- LICENSE.txt
|
53
39
|
- README.md
|
54
40
|
- Rakefile
|
@@ -71,15 +57,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
57
|
requirements:
|
72
58
|
- - ">="
|
73
59
|
- !ruby/object:Gem::Version
|
74
|
-
version: 2.
|
60
|
+
version: 2.6.0
|
75
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
62
|
requirements:
|
77
63
|
- - ">="
|
78
64
|
- !ruby/object:Gem::Version
|
79
65
|
version: '0'
|
80
66
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
67
|
+
rubygems_version: 3.4.0.dev
|
82
68
|
signing_key:
|
83
69
|
specification_version: 4
|
84
|
-
summary: The
|
70
|
+
summary: The abstract interface for net-* client.
|
85
71
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
net-protocol (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
power_assert (1.1.5)
|
10
|
-
rake (12.3.3)
|
11
|
-
test-unit (3.3.5)
|
12
|
-
power_assert
|
13
|
-
|
14
|
-
PLATFORMS
|
15
|
-
ruby
|
16
|
-
|
17
|
-
DEPENDENCIES
|
18
|
-
net-protocol!
|
19
|
-
rake
|
20
|
-
test-unit
|
21
|
-
|
22
|
-
BUNDLED WITH
|
23
|
-
2.1.4
|