net-protocol 0.2.2 → 0.3.0
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.
- checksums.yaml +4 -4
- data/.document +4 -0
- data/{LICENSE.txt → BSDL} +3 -3
- data/COPYING +56 -0
- data/lib/net/protocol.rb +58 -4
- metadata +7 -15
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/test.yml +0 -30
- data/.gitignore +0 -8
- data/Gemfile +0 -7
- data/Rakefile +0 -10
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/net-protocol.gemspec +0 -33
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d16f82437abceaa211dc99712afe1f8c42c0daef151b915f1366a420bf8a3322
|
|
4
|
+
data.tar.gz: 86d38fb6a43a0b62c6b3438b4e1b286806bb56caabd383cd5e3d7c82a8bcb88f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 876168c8096052d6230fc67c2383b8ce8e879c50eb338ad3f3a4b98c9a4ed1ba409c25c7a3644cb6e7e8893b2788bb33460a1613ea7cd1fb9952f64bb34bdcf8
|
|
7
|
+
data.tar.gz: a2be90f1ade432da76a949cc2112a2205ae5a732e0b2c00acd3c614abdf0a8e311954ad9f0c567876bfd66b09485511034a7590f97cfa2d2044b49e62c09d1e2
|
data/.document
ADDED
data/{LICENSE.txt → BSDL}
RENAMED
|
@@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
|
|
|
4
4
|
modification, are permitted provided that the following conditions
|
|
5
5
|
are met:
|
|
6
6
|
1. Redistributions of source code must retain the above copyright
|
|
7
|
-
notice, this list of conditions and the following disclaimer.
|
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
|
8
8
|
2. Redistributions in binary form must reproduce the above copyright
|
|
9
|
-
notice, this list of conditions and the following disclaimer in the
|
|
10
|
-
documentation and/or other materials provided with the distribution.
|
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
|
10
|
+
documentation and/or other materials provided with the distribution.
|
|
11
11
|
|
|
12
12
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
13
13
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
data/COPYING
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
|
2
|
+
You can redistribute it and/or modify it under either the terms of the
|
|
3
|
+
2-clause BSDL (see the file BSDL), or the conditions below:
|
|
4
|
+
|
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
|
6
|
+
software without restriction, provided that you duplicate all of the
|
|
7
|
+
original copyright notices and associated disclaimers.
|
|
8
|
+
|
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
|
10
|
+
you do at least ONE of the following:
|
|
11
|
+
|
|
12
|
+
a. place your modifications in the Public Domain or otherwise
|
|
13
|
+
make them Freely Available, such as by posting said
|
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
|
15
|
+
the author to include your modifications in the software.
|
|
16
|
+
|
|
17
|
+
b. use the modified software only within your corporation or
|
|
18
|
+
organization.
|
|
19
|
+
|
|
20
|
+
c. give non-standard binaries non-standard names, with
|
|
21
|
+
instructions on where to get the original software distribution.
|
|
22
|
+
|
|
23
|
+
d. make other distribution arrangements with the author.
|
|
24
|
+
|
|
25
|
+
3. You may distribute the software in object code or binary form,
|
|
26
|
+
provided that you do at least ONE of the following:
|
|
27
|
+
|
|
28
|
+
a. distribute the binaries and library files of the software,
|
|
29
|
+
together with instructions (in the manual page or equivalent)
|
|
30
|
+
on where to get the original distribution.
|
|
31
|
+
|
|
32
|
+
b. accompany the distribution with the machine-readable source of
|
|
33
|
+
the software.
|
|
34
|
+
|
|
35
|
+
c. give non-standard binaries non-standard names, with
|
|
36
|
+
instructions on where to get the original software distribution.
|
|
37
|
+
|
|
38
|
+
d. make other distribution arrangements with the author.
|
|
39
|
+
|
|
40
|
+
4. You may modify and include the part of the software into any other
|
|
41
|
+
software (possibly commercial). But some files in the distribution
|
|
42
|
+
are not written by the author, so that they are not under these terms.
|
|
43
|
+
|
|
44
|
+
For the list of those files and their copying conditions, see the
|
|
45
|
+
file LEGAL.
|
|
46
|
+
|
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
|
48
|
+
output from the software do not automatically fall under the
|
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
|
50
|
+
and may be sold commercially, and may be aggregated with this
|
|
51
|
+
software.
|
|
52
|
+
|
|
53
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
|
54
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
55
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
56
|
+
PURPOSE.
|
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.3.0"
|
|
30
30
|
|
|
31
31
|
private
|
|
32
32
|
def Protocol.protocol_param(name, val)
|
|
@@ -54,9 +54,20 @@ module Net # :nodoc:
|
|
|
54
54
|
s.connect
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
|
+
|
|
58
|
+
tcp_socket_parameters = TCPSocket.instance_method(:initialize).parameters
|
|
59
|
+
TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT = if tcp_socket_parameters != [[:rest]]
|
|
60
|
+
tcp_socket_parameters.include?([:key, :open_timeout])
|
|
61
|
+
else
|
|
62
|
+
# Use Socket.tcp to find out since there is no parameters information for TCPSocket#initialize
|
|
63
|
+
# See discussion in https://github.com/ruby/net-http/pull/224
|
|
64
|
+
Socket.method(:tcp).parameters.include?([:key, :open_timeout])
|
|
65
|
+
end
|
|
66
|
+
private_constant :TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT
|
|
57
67
|
end
|
|
58
68
|
|
|
59
69
|
|
|
70
|
+
# :stopdoc:
|
|
60
71
|
class ProtocolError < StandardError; end
|
|
61
72
|
class ProtoSyntaxError < ProtocolError; end
|
|
62
73
|
class ProtoFatalError < ProtocolError; end
|
|
@@ -66,6 +77,29 @@ module Net # :nodoc:
|
|
|
66
77
|
class ProtoCommandError < ProtocolError; end
|
|
67
78
|
class ProtoRetriableError < ProtocolError; end
|
|
68
79
|
ProtocRetryError = ProtoRetriableError
|
|
80
|
+
# :startdoc:
|
|
81
|
+
|
|
82
|
+
##
|
|
83
|
+
# ReadLimitExceeded, a subclass of ProtocolError, is raised if the
|
|
84
|
+
# terminator is not found within the byte limit given to
|
|
85
|
+
# Net::BufferedIO#readuntil.
|
|
86
|
+
#
|
|
87
|
+
# The limit is the largest result readuntil may return, counting the
|
|
88
|
+
# terminator itself, so a limit of 4 accepts "abc\n" and rejects
|
|
89
|
+
# "abcd\n". Unlike the limit of IO#gets it never truncates a result to
|
|
90
|
+
# fit. Either the whole thing comes back or this is raised, except
|
|
91
|
+
# under ignore_eof, which still returns what was buffered when the
|
|
92
|
+
# stream ended. The count is in bytes while the IO hands back binary
|
|
93
|
+
# strings, which every real one does.
|
|
94
|
+
#
|
|
95
|
+
# It bounds one call, not a connection. The unconsumed buffer can
|
|
96
|
+
# still run one BUFSIZE past the limit, and a peer sending endless
|
|
97
|
+
# short lines is not bounded at all.
|
|
98
|
+
#
|
|
99
|
+
# Nothing is consumed when this is raised, so the usual response is to
|
|
100
|
+
# close the connection rather than read on under a wider limit.
|
|
101
|
+
|
|
102
|
+
class ReadLimitExceeded < ProtocolError; end
|
|
69
103
|
|
|
70
104
|
##
|
|
71
105
|
# OpenTimeout, a subclass of Timeout::Error, is raised if a connection cannot
|
|
@@ -78,6 +112,7 @@ module Net # :nodoc:
|
|
|
78
112
|
# response cannot be read within the read_timeout.
|
|
79
113
|
|
|
80
114
|
class ReadTimeout < Timeout::Error
|
|
115
|
+
# :stopdoc:
|
|
81
116
|
def initialize(io = nil)
|
|
82
117
|
@io = io
|
|
83
118
|
end
|
|
@@ -97,6 +132,7 @@ module Net # :nodoc:
|
|
|
97
132
|
# response cannot be written within the write_timeout. Not raised on Windows.
|
|
98
133
|
|
|
99
134
|
class WriteTimeout < Timeout::Error
|
|
135
|
+
# :stopdoc:
|
|
100
136
|
def initialize(io = nil)
|
|
101
137
|
@io = io
|
|
102
138
|
end
|
|
@@ -191,14 +227,31 @@ module Net # :nodoc:
|
|
|
191
227
|
dest
|
|
192
228
|
end
|
|
193
229
|
|
|
194
|
-
def readuntil(terminator, ignore_eof = false)
|
|
230
|
+
def readuntil(terminator, ignore_eof = false, limit: nil)
|
|
231
|
+
unless limit.nil? || (Integer === limit && limit > 0)
|
|
232
|
+
# Integer === calls nothing on limit, and only an Integer is
|
|
233
|
+
# echoed back, so validation never runs the caller's code.
|
|
234
|
+
got = Integer === limit ? limit : "a non-Integer"
|
|
235
|
+
raise ArgumentError, "limit must be a positive Integer, got #{got}"
|
|
236
|
+
end
|
|
195
237
|
offset = @rbuf_offset
|
|
196
238
|
begin
|
|
197
239
|
until idx = @rbuf.index(terminator, offset)
|
|
198
|
-
|
|
240
|
+
if limit && rbuf_size > limit
|
|
241
|
+
raise ReadLimitExceeded, "exceeded the #{limit} byte read limit"
|
|
242
|
+
end
|
|
243
|
+
# Rewind so a terminator split across reads is still found. The
|
|
244
|
+
# floor guards two things. String#index reads a negative offset
|
|
245
|
+
# as counting from the end, and an offset below @rbuf_offset
|
|
246
|
+
# matches inside bytes already returned.
|
|
247
|
+
offset = [@rbuf.bytesize - terminator.bytesize + 1, @rbuf_offset].max
|
|
199
248
|
rbuf_fill
|
|
200
249
|
end
|
|
201
|
-
|
|
250
|
+
len = idx + terminator.bytesize - @rbuf_offset
|
|
251
|
+
if limit && len > limit
|
|
252
|
+
raise ReadLimitExceeded, "exceeded the #{limit} byte read limit"
|
|
253
|
+
end
|
|
254
|
+
return rbuf_consume(len)
|
|
202
255
|
rescue EOFError
|
|
203
256
|
raise unless ignore_eof
|
|
204
257
|
return rbuf_consume
|
|
@@ -484,6 +537,7 @@ module Net # :nodoc:
|
|
|
484
537
|
# The writer adapter class
|
|
485
538
|
#
|
|
486
539
|
class WriteAdapter
|
|
540
|
+
# :stopdoc:
|
|
487
541
|
def initialize(writer)
|
|
488
542
|
@writer = writer
|
|
489
543
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: net-protocol
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yukihiro Matsumoto
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: timeout
|
|
@@ -31,17 +30,11 @@ executables: []
|
|
|
31
30
|
extensions: []
|
|
32
31
|
extra_rdoc_files: []
|
|
33
32
|
files:
|
|
34
|
-
- ".
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
- Gemfile
|
|
38
|
-
- LICENSE.txt
|
|
33
|
+
- ".document"
|
|
34
|
+
- BSDL
|
|
35
|
+
- COPYING
|
|
39
36
|
- README.md
|
|
40
|
-
- Rakefile
|
|
41
|
-
- bin/console
|
|
42
|
-
- bin/setup
|
|
43
37
|
- lib/net/protocol.rb
|
|
44
|
-
- net-protocol.gemspec
|
|
45
38
|
homepage: https://github.com/ruby/net-protocol
|
|
46
39
|
licenses:
|
|
47
40
|
- Ruby
|
|
@@ -49,7 +42,7 @@ licenses:
|
|
|
49
42
|
metadata:
|
|
50
43
|
homepage_uri: https://github.com/ruby/net-protocol
|
|
51
44
|
source_code_uri: https://github.com/ruby/net-protocol
|
|
52
|
-
|
|
45
|
+
changelog_uri: https://github.com/ruby/net-protocol/releases
|
|
53
46
|
rdoc_options: []
|
|
54
47
|
require_paths:
|
|
55
48
|
- lib
|
|
@@ -64,8 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
64
57
|
- !ruby/object:Gem::Version
|
|
65
58
|
version: '0'
|
|
66
59
|
requirements: []
|
|
67
|
-
rubygems_version: 3.
|
|
68
|
-
signing_key:
|
|
60
|
+
rubygems_version: 3.6.9
|
|
69
61
|
specification_version: 4
|
|
70
62
|
summary: The abstract interface for net-* client.
|
|
71
63
|
test_files: []
|
data/.github/dependabot.yml
DELETED
data/.github/workflows/test.yml
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
name: test
|
|
2
|
-
|
|
3
|
-
on: [push, pull_request]
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
ruby-verions:
|
|
7
|
-
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
|
|
8
|
-
with:
|
|
9
|
-
min_version: 2.6
|
|
10
|
-
|
|
11
|
-
test:
|
|
12
|
-
needs: ruby-verions
|
|
13
|
-
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
|
14
|
-
strategy:
|
|
15
|
-
matrix:
|
|
16
|
-
ruby: ${{ fromJson(needs.ruby-verions.outputs.versions) }}
|
|
17
|
-
os: [ ubuntu-latest, macos-latest, windows-latest ]
|
|
18
|
-
exclude:
|
|
19
|
-
- { os: windows-latest, ruby: truffleruby-head }
|
|
20
|
-
- { os: windows-latest, ruby: truffleruby }
|
|
21
|
-
runs-on: ${{ matrix.os }}
|
|
22
|
-
steps:
|
|
23
|
-
- uses: actions/checkout@v4
|
|
24
|
-
- name: Set up Ruby
|
|
25
|
-
uses: ruby/setup-ruby@v1
|
|
26
|
-
with:
|
|
27
|
-
ruby-version: ${{ matrix.ruby }}
|
|
28
|
-
bundler-cache: true # 'bundle install' and cache gems
|
|
29
|
-
- name: Run test
|
|
30
|
-
run: bundle exec rake test
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/bin/console
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "net/protocol"
|
|
5
|
-
|
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
-
|
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
-
# require "pry"
|
|
11
|
-
# Pry.start
|
|
12
|
-
|
|
13
|
-
require "irb"
|
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/net-protocol.gemspec
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
name = File.basename(__FILE__, ".gemspec")
|
|
4
|
-
version = ["lib", Array.new(name.count("-"), "..").join("/")].find do |dir|
|
|
5
|
-
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
|
|
6
|
-
/^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
|
|
7
|
-
end rescue nil
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
Gem::Specification.new do |spec|
|
|
11
|
-
spec.name = name
|
|
12
|
-
spec.version = version
|
|
13
|
-
spec.authors = ["Yukihiro Matsumoto"]
|
|
14
|
-
spec.email = ["matz@ruby-lang.org"]
|
|
15
|
-
|
|
16
|
-
spec.summary = %q{The abstract interface for net-* client.}
|
|
17
|
-
spec.description = %q{The abstract interface for net-* client.}
|
|
18
|
-
spec.homepage = "https://github.com/ruby/net-protocol"
|
|
19
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
|
20
|
-
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
|
21
|
-
|
|
22
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
|
23
|
-
spec.metadata["source_code_uri"] = spec.homepage
|
|
24
|
-
|
|
25
|
-
# Specify which files should be added to the gem when it is released.
|
|
26
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
27
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
28
|
-
`git ls-files -z 2>#{IO::NULL}`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
29
|
-
end
|
|
30
|
-
spec.require_paths = ["lib"]
|
|
31
|
-
|
|
32
|
-
spec.add_dependency "timeout"
|
|
33
|
-
end
|