async-io 1.32.1 → 1.34.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0eedd48282062fbeed1ef84ec609fc2f380c122ebf33f9035af7a9bbe21fee5e
4
- data.tar.gz: 83a33c4964ffd1777ca948dce4c20a3e62cc575793268e70e517f0f2858f9cdf
3
+ metadata.gz: a0131359c594306a5fbe0e355a33392e6e59608f771677974aa376336ace05e4
4
+ data.tar.gz: f3e3d7ebd90014cf4692a64cb39e107a95899a64d07536959ec208c45f69044e
5
5
  SHA512:
6
- metadata.gz: c4eb398ef67e38c31feaee2da4d7c2e9b7e8dd49350082d01615c914c2d483ab36e52d42db0b32e4a80adc5a8683e06805bc5814a4a7c9a7a60b9c4aab983522
7
- data.tar.gz: 3dc2b05cc064e479da2528860370d51cbff0f332bdef4f3819c8b8ebf92ff59e3f04e737a371b99e74c9d324637903213d56808dab2e3fa2783061086b593a33
6
+ metadata.gz: 135c73883230c4c902c75b5070bec585fa5849d832eef7e6f1e70df8a456d77c8ebd43869c938ad6b7345b9c05e64f6fd423f53bf93a80cc193453a2d532b981
7
+ data.tar.gz: 4b6689c582cca834d15d0358a71fd9325ff295ef6477dfd9ec3bf6e5ec84de356c2dee39ad9502fc17c8b76ad3d82d19feef1fb6d4b678eb30d3a2d5076fbd7d
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require_relative 'endpoint'
24
+
25
+ module Async
26
+ module IO
27
+ class CompositeEndpoint < Endpoint
28
+ def initialize(endpoints, **options)
29
+ super(**options)
30
+ @endpoints = endpoints
31
+ end
32
+
33
+ def each(&block)
34
+ @endpoints.each(&block)
35
+ end
36
+
37
+ def connect(&block)
38
+ error = nil
39
+
40
+ @endpoints.each do |endpoint|
41
+ begin
42
+ return endpoint.connect(&block)
43
+ rescue => error
44
+ end
45
+ end
46
+
47
+ raise error
48
+ end
49
+
50
+ def bind(&block)
51
+ @endpoints.map(&:bind)
52
+ end
53
+ end
54
+
55
+ class Endpoint
56
+ def self.composite(*endpoints, **options)
57
+ CompositeEndpoint.new(endpoints, **options)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -21,6 +21,7 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  require_relative 'endpoint'
24
+ require_relative 'composite_endpoint'
24
25
 
25
26
  module Async
26
27
  module IO
@@ -29,7 +30,13 @@ module Async
29
30
  # Create a new `SharedEndpoint` by binding to the given endpoint.
30
31
  def self.bound(endpoint, backlog: Socket::SOMAXCONN, close_on_exec: false)
31
32
  wrappers = endpoint.bound do |server|
32
- server.listen(backlog)
33
+ # This is somewhat optional. We want to have a generic interface as much as possible so that users of this interface can just call it without knowing a lot of internal details. Therefore, we ignore errors here if it's because the underlying socket does not support the operation.
34
+ begin
35
+ server.listen(backlog)
36
+ rescue Errno::EOPNOTSUPP
37
+ # Ignore.
38
+ end
39
+
33
40
  server.close_on_exec = close_on_exec
34
41
  server.reactor = nil
35
42
  end
@@ -57,6 +64,22 @@ module Async
57
64
  attr :endpoint
58
65
  attr :wrappers
59
66
 
67
+ def local_address_endpoint(**options)
68
+ endpoints = @wrappers.map do |wrapper|
69
+ AddressEndpoint.new(wrapper.to_io.local_address)
70
+ end
71
+
72
+ return CompositeEndpoint.new(endpoints, **options)
73
+ end
74
+
75
+ def remote_address_endpoint(**options)
76
+ endpoints = @wrappers.map do |wrapper|
77
+ AddressEndpoint.new(wrapper.to_io.remote_address)
78
+ end
79
+
80
+ return CompositeEndpoint.new(endpoints, **options)
81
+ end
82
+
60
83
  # Close all the internal wrappers.
61
84
  def close
62
85
  @wrappers.each(&:close)
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Async
24
24
  module IO
25
- VERSION = "1.32.1"
25
+ VERSION = "1.34.0"
26
26
  end
27
27
  end
data/lib/async/io.rb CHANGED
@@ -34,5 +34,9 @@ module Async
34
34
  def self.file_descriptor_limit
35
35
  Process.getrlimit(Process::RLIMIT_NOFILE).first
36
36
  end
37
+
38
+ def self.buffer?
39
+ ::IO.const_defined?(:Buffer)
40
+ end
37
41
  end
38
42
  end
metadata CHANGED
@@ -1,29 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.32.1
4
+ version: 1.34.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Aurora
9
+ - Olle Jonsson
10
+ - Bruno Sutic
11
+ - Benoit Daloze
12
+ - Cyril Roelandt
13
+ - Thibaut Girka
14
+ - Jiang Jinyang
15
+ - Janko Marohnić
8
16
  autorequire:
9
17
  bindir: bin
10
18
  cert_chain: []
11
- date: 2021-06-09 00:00:00.000000000 Z
19
+ date: 2022-08-28 00:00:00.000000000 Z
12
20
  dependencies:
13
21
  - !ruby/object:Gem::Dependency
14
22
  name: async
15
23
  requirement: !ruby/object:Gem::Requirement
16
24
  requirements:
17
- - - "~>"
25
+ - - ">="
18
26
  - !ruby/object:Gem::Version
19
- version: '1.14'
27
+ version: '0'
20
28
  type: :runtime
21
29
  prerelease: false
22
30
  version_requirements: !ruby/object:Gem::Requirement
23
31
  requirements:
24
- - - "~>"
32
+ - - ">="
25
33
  - !ruby/object:Gem::Version
26
- version: '1.14'
34
+ version: '0'
27
35
  - !ruby/object:Gem::Dependency
28
36
  name: async-container
29
37
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +60,20 @@ dependencies:
52
60
  - - "~>"
53
61
  - !ruby/object:Gem::Version
54
62
  version: '1.10'
63
+ - !ruby/object:Gem::Dependency
64
+ name: bake
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
55
77
  - !ruby/object:Gem::Dependency
56
78
  name: covered
57
79
  requirement: !ruby/object:Gem::Requirement
@@ -105,6 +127,7 @@ files:
105
127
  - lib/async/io/address_endpoint.rb
106
128
  - lib/async/io/binary_string.rb
107
129
  - lib/async/io/buffer.rb
130
+ - lib/async/io/composite_endpoint.rb
108
131
  - lib/async/io/endpoint.rb
109
132
  - lib/async/io/endpoint/each.rb
110
133
  - lib/async/io/generic.rb
@@ -147,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
170
  - !ruby/object:Gem::Version
148
171
  version: '0'
149
172
  requirements: []
150
- rubygems_version: 3.1.2
173
+ rubygems_version: 3.3.7
151
174
  signing_key:
152
175
  specification_version: 4
153
176
  summary: Provides support for asynchonous TCP, UDP, UNIX and SSL sockets.