async-io 1.30.1 → 1.43.2
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
- checksums.yaml.gz.sig +0 -0
- data/lib/async/io/address.rb +2 -19
- data/lib/async/io/address_endpoint.rb +2 -19
- data/lib/async/io/binary_string.rb +2 -19
- data/lib/async/io/buffer.rb +2 -19
- data/lib/async/io/composite_endpoint.rb +44 -0
- data/lib/async/io/endpoint/each.rb +3 -19
- data/lib/async/io/endpoint.rb +3 -36
- data/lib/async/io/generic.rb +11 -22
- data/lib/async/io/host_endpoint.rb +4 -19
- data/lib/async/io/notification.rb +2 -19
- data/lib/async/io/peer.rb +7 -21
- data/lib/async/io/protocol/generic.rb +2 -19
- data/lib/async/io/protocol/line.rb +2 -19
- data/lib/async/io/server.rb +2 -19
- data/lib/async/io/shared_endpoint.rb +48 -35
- data/lib/async/io/socket.rb +7 -22
- data/lib/async/io/socket_endpoint.rb +2 -19
- data/lib/async/io/ssl_endpoint.rb +6 -20
- data/lib/async/io/ssl_socket.rb +25 -33
- data/lib/async/io/standard.rb +2 -19
- data/lib/async/io/stream.rb +46 -28
- data/lib/async/io/tcp_socket.rb +4 -20
- data/lib/async/io/threads.rb +44 -39
- data/lib/async/io/trap.rb +2 -19
- data/lib/async/io/udp_socket.rb +2 -19
- data/lib/async/io/unix_endpoint.rb +6 -21
- data/lib/async/io/unix_socket.rb +2 -19
- data/lib/async/io/version.rb +3 -20
- data/lib/async/io.rb +7 -19
- data/license.md +33 -0
- data/readme.md +152 -0
- data.tar.gz.sig +0 -0
- metadata +52 -118
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 63fad81fc33f05f6cffc286731b2ca97c856ad2b3679046270ee9b5370566973
|
|
4
|
+
data.tar.gz: 5696bbab2014b6ed160b784502e4928986ba7189f78c8653ab1f3b7c7a7d2f5f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 82e94e119920c19ebbc054f1aa3e0cce1de8f5702591f8d84334ec28f92ba564b4ffe762a2fc966300f085c7077d015bfa48e5738075bc78ab36145a11e5fb39
|
|
7
|
+
data.tar.gz: c025094d9a34299cca00f256df4b304b376a7aeb54a36e187463530cea21b7108b6e628c53c2e5706c9674474eae904dd694f747b05732666f30c3694886e570
|
checksums.yaml.gz.sig
ADDED
|
Binary file
|
data/lib/async/io/address.rb
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2017-2023, by Samuel Williams.
|
|
22
5
|
|
|
23
6
|
require 'socket'
|
|
24
7
|
|
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2018-2023, by Samuel Williams.
|
|
22
5
|
|
|
23
6
|
require_relative 'endpoint'
|
|
24
7
|
|
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2017-2023, by Samuel Williams.
|
|
22
5
|
|
|
23
6
|
require_relative 'buffer'
|
|
24
7
|
|
data/lib/async/io/buffer.rb
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2018-2023, by Samuel Williams.
|
|
22
5
|
|
|
23
6
|
module Async
|
|
24
7
|
module IO
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2022-2023, by Samuel Williams.
|
|
5
|
+
|
|
6
|
+
require_relative 'endpoint'
|
|
7
|
+
|
|
8
|
+
module Async
|
|
9
|
+
module IO
|
|
10
|
+
class CompositeEndpoint < Endpoint
|
|
11
|
+
def initialize(endpoints, **options)
|
|
12
|
+
super(**options)
|
|
13
|
+
@endpoints = endpoints
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def each(&block)
|
|
17
|
+
@endpoints.each(&block)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def connect(&block)
|
|
21
|
+
error = nil
|
|
22
|
+
|
|
23
|
+
@endpoints.each do |endpoint|
|
|
24
|
+
begin
|
|
25
|
+
return endpoint.connect(&block)
|
|
26
|
+
rescue => error
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
raise error
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def bind(&block)
|
|
34
|
+
@endpoints.map(&:bind)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class Endpoint
|
|
39
|
+
def self.composite(*endpoints, **options)
|
|
40
|
+
CompositeEndpoint.new(endpoints, **options)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2018-2023, by Samuel Williams.
|
|
5
|
+
# Copyright, 2019, by Olle Jonsson.
|
|
22
6
|
|
|
23
7
|
require_relative "../host_endpoint"
|
|
24
8
|
require_relative "../socket_endpoint"
|
data/lib/async/io/endpoint.rb
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2017-2024, by Samuel Williams.
|
|
5
|
+
# Copyright, 2019, by Olle Jonsson.
|
|
22
6
|
|
|
23
7
|
require_relative 'address'
|
|
24
8
|
require_relative 'socket'
|
|
@@ -94,23 +78,6 @@ module Async
|
|
|
94
78
|
end
|
|
95
79
|
end
|
|
96
80
|
|
|
97
|
-
# Map all endpoints by invoking `#bind`.
|
|
98
|
-
# @yield the bound wrapper.
|
|
99
|
-
def bound
|
|
100
|
-
wrappers = []
|
|
101
|
-
|
|
102
|
-
self.each do |endpoint|
|
|
103
|
-
wrapper = endpoint.bind
|
|
104
|
-
wrappers << wrapper
|
|
105
|
-
|
|
106
|
-
yield wrapper
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
return wrappers
|
|
110
|
-
ensure
|
|
111
|
-
wrappers.each(&:close) if $!
|
|
112
|
-
end
|
|
113
|
-
|
|
114
81
|
# Create an Endpoint instance by URI scheme. The host and port of the URI will be passed to the Endpoint factory method, along with any options.
|
|
115
82
|
#
|
|
116
83
|
# @param string [String] URI as string. Scheme will decide implementation used.
|
data/lib/async/io/generic.rb
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2017-2023, by Samuel Williams.
|
|
5
|
+
# Copyright, 2021, by Aurora Nockert.
|
|
6
|
+
# Copyright, 2023, by Patrik Wenger.
|
|
22
7
|
|
|
23
8
|
require 'async/wrapper'
|
|
24
9
|
require 'forwardable'
|
|
@@ -98,7 +83,7 @@ module Async
|
|
|
98
83
|
end
|
|
99
84
|
end
|
|
100
85
|
|
|
101
|
-
wraps ::IO, :external_encoding, :internal_encoding, :autoclose?, :autoclose=, :pid, :stat, :binmode, :flush, :set_encoding, :set_encoding_by_bom, :to_io, :to_i, :reopen, :fileno, :fsync, :fdatasync, :sync, :sync=, :tell, :seek, :rewind, :pos, :pos=, :eof, :eof?, :close_on_exec?, :close_on_exec=, :closed?, :close_read, :close_write, :isatty, :tty?, :binmode?, :sysseek, :advise, :ioctl, :fcntl, :nread, :ready?, :pread, :pwrite, :pathconf
|
|
86
|
+
wraps ::IO, :external_encoding, :internal_encoding, :autoclose?, :autoclose=, :pid, :stat, :binmode, :flush, :set_encoding, :set_encoding_by_bom, :to_path, :to_io, :to_i, :reopen, :fileno, :fsync, :fdatasync, :sync, :sync=, :tell, :seek, :rewind, :path, :pos, :pos=, :eof, :eof?, :close_on_exec?, :close_on_exec=, :closed?, :close_read, :close_write, :isatty, :tty?, :binmode?, :sysseek, :advise, :ioctl, :fcntl, :nread, :ready?, :pread, :pwrite, :pathconf
|
|
102
87
|
|
|
103
88
|
# Read the specified number of bytes from the input stream. This is fast path.
|
|
104
89
|
# @example
|
|
@@ -116,7 +101,7 @@ module Async
|
|
|
116
101
|
end
|
|
117
102
|
|
|
118
103
|
if length
|
|
119
|
-
return
|
|
104
|
+
return String.new(encoding: Encoding::BINARY) if length <= 0
|
|
120
105
|
|
|
121
106
|
# Fast path:
|
|
122
107
|
if buffer = self.sysread(length, buffer)
|
|
@@ -185,7 +170,7 @@ module Async
|
|
|
185
170
|
when :write
|
|
186
171
|
wait_writable(timeout)
|
|
187
172
|
else
|
|
188
|
-
wait_any(
|
|
173
|
+
wait_any(timeout)
|
|
189
174
|
end
|
|
190
175
|
rescue TimeoutError
|
|
191
176
|
return nil
|
|
@@ -207,6 +192,10 @@ module Async
|
|
|
207
192
|
!@io.closed?
|
|
208
193
|
end
|
|
209
194
|
|
|
195
|
+
def readable?
|
|
196
|
+
@io.readable?
|
|
197
|
+
end
|
|
198
|
+
|
|
210
199
|
attr_accessor :timeout
|
|
211
200
|
|
|
212
201
|
protected
|
|
@@ -1,24 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2018-2023, by Samuel Williams.
|
|
5
|
+
# Copyright, 2019, by Olle Jonsson.
|
|
6
|
+
# Copyright, 2020, by Benoit Daloze.
|
|
22
7
|
|
|
23
8
|
require_relative 'address_endpoint'
|
|
24
9
|
|
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2018-2023, by Samuel Williams.
|
|
22
5
|
|
|
23
6
|
require_relative 'generic'
|
|
24
7
|
|
data/lib/async/io/peer.rb
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2020-2023, by Samuel Williams.
|
|
22
5
|
|
|
23
6
|
require 'socket'
|
|
24
7
|
|
|
@@ -35,6 +18,9 @@ module Async
|
|
|
35
18
|
# If we can wait for the socket to become readable, we know that the socket may still be open.
|
|
36
19
|
result = to_io.recv_nonblock(1, MSG_PEEK, exception: false)
|
|
37
20
|
|
|
21
|
+
# No data was available - newer Ruby can return nil instead of empty string:
|
|
22
|
+
return false if result.nil?
|
|
23
|
+
|
|
38
24
|
# Either there was some data available, or we can wait to see if there is data avaialble.
|
|
39
25
|
return !result.empty? || result == :wait_readable
|
|
40
26
|
|
|
@@ -59,13 +45,13 @@ module Async
|
|
|
59
45
|
when 0, IPPROTO_TCP
|
|
60
46
|
self.setsockopt(IPPROTO_TCP, TCP_NODELAY, value ? 1 : 0)
|
|
61
47
|
else
|
|
62
|
-
|
|
48
|
+
Console.logger.warn(self) {"Unsure how to sync=#{value} for #{self.protocol}!"}
|
|
63
49
|
end
|
|
64
50
|
rescue Errno::EINVAL
|
|
65
51
|
# On Darwin, sometimes occurs when the connection is not yet fully formed. Empirically, TCP_NODELAY is enabled despite this result.
|
|
66
52
|
rescue Errno::EOPNOTSUPP
|
|
67
53
|
# Some platforms may simply not support the operation.
|
|
68
|
-
#
|
|
54
|
+
# Console.logger.warn(self) {"Unable to set sync=#{value}!"}
|
|
69
55
|
end
|
|
70
56
|
|
|
71
57
|
def sync
|
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2018-2023, by Samuel Williams.
|
|
22
5
|
|
|
23
6
|
require_relative '../stream'
|
|
24
7
|
|
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2017-2023, by Samuel Williams.
|
|
22
5
|
|
|
23
6
|
require_relative 'generic'
|
|
24
7
|
|
data/lib/async/io/server.rb
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2020-2023, by Samuel Williams.
|
|
22
5
|
|
|
23
6
|
require 'async/task'
|
|
24
7
|
|
|
@@ -1,36 +1,29 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
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.
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2018-2024, by Samuel Williams.
|
|
5
|
+
# Copyright, 2019, by Olle Jonsson.
|
|
22
6
|
|
|
23
7
|
require_relative 'endpoint'
|
|
8
|
+
require_relative 'composite_endpoint'
|
|
24
9
|
|
|
25
10
|
module Async
|
|
26
11
|
module IO
|
|
27
12
|
# Pre-connect and pre-bind sockets so that it can be used between processes.
|
|
28
13
|
class SharedEndpoint < Endpoint
|
|
29
14
|
# Create a new `SharedEndpoint` by binding to the given endpoint.
|
|
30
|
-
def self.bound(endpoint, backlog
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
def self.bound(endpoint, backlog: Socket::SOMAXCONN, close_on_exec: false, **options)
|
|
16
|
+
sockets = Array(endpoint.bind(**options))
|
|
17
|
+
|
|
18
|
+
wrappers = sockets.each do |server|
|
|
19
|
+
# 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.
|
|
20
|
+
begin
|
|
21
|
+
server.listen(backlog)
|
|
22
|
+
rescue Errno::EOPNOTSUPP
|
|
23
|
+
# Ignore.
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
server.close_on_exec = close_on_exec
|
|
34
27
|
server.reactor = nil
|
|
35
28
|
end
|
|
36
29
|
|
|
@@ -38,10 +31,10 @@ module Async
|
|
|
38
31
|
end
|
|
39
32
|
|
|
40
33
|
# Create a new `SharedEndpoint` by connecting to the given endpoint.
|
|
41
|
-
def self.connected(endpoint)
|
|
34
|
+
def self.connected(endpoint, close_on_exec: false)
|
|
42
35
|
wrapper = endpoint.connect
|
|
43
36
|
|
|
44
|
-
wrapper.close_on_exec =
|
|
37
|
+
wrapper.close_on_exec = close_on_exec
|
|
45
38
|
wrapper.reactor = nil
|
|
46
39
|
|
|
47
40
|
return self.new(endpoint, [wrapper])
|
|
@@ -57,6 +50,23 @@ module Async
|
|
|
57
50
|
attr :endpoint
|
|
58
51
|
attr :wrappers
|
|
59
52
|
|
|
53
|
+
def local_address_endpoint(**options)
|
|
54
|
+
endpoints = @wrappers.map do |wrapper|
|
|
55
|
+
# Forward the options to the internal endpoints:
|
|
56
|
+
AddressEndpoint.new(wrapper.to_io.local_address, **options)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
return CompositeEndpoint.new(endpoints)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def remote_address_endpoint(**options)
|
|
63
|
+
endpoints = @wrappers.map do |wrapper|
|
|
64
|
+
AddressEndpoint.new(wrapper.to_io.remote_address)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
return CompositeEndpoint.new(endpoints, **options)
|
|
68
|
+
end
|
|
69
|
+
|
|
60
70
|
# Close all the internal wrappers.
|
|
61
71
|
def close
|
|
62
72
|
@wrappers.each(&:close)
|
|
@@ -67,16 +77,9 @@ module Async
|
|
|
67
77
|
task = Async::Task.current
|
|
68
78
|
|
|
69
79
|
@wrappers.each do |server|
|
|
70
|
-
server = server.dup
|
|
71
|
-
|
|
72
80
|
task.async do |task|
|
|
73
81
|
task.annotate "binding to #{server.inspect}"
|
|
74
|
-
|
|
75
|
-
begin
|
|
76
|
-
yield server, task
|
|
77
|
-
ensure
|
|
78
|
-
server.close
|
|
79
|
-
end
|
|
82
|
+
yield server, task
|
|
80
83
|
end
|
|
81
84
|
end
|
|
82
85
|
end
|
|
@@ -99,9 +102,9 @@ module Async
|
|
|
99
102
|
end
|
|
100
103
|
end
|
|
101
104
|
|
|
102
|
-
def accept(backlog = nil, &block)
|
|
105
|
+
def accept(backlog = nil, **options, &block)
|
|
103
106
|
bind do |server|
|
|
104
|
-
server.accept_each(&block)
|
|
107
|
+
server.accept_each(**options, &block)
|
|
105
108
|
end
|
|
106
109
|
end
|
|
107
110
|
|
|
@@ -109,5 +112,15 @@ module Async
|
|
|
109
112
|
"\#<#{self.class} #{@wrappers.size} descriptors for #{@endpoint}>"
|
|
110
113
|
end
|
|
111
114
|
end
|
|
115
|
+
|
|
116
|
+
class Endpoint
|
|
117
|
+
def bound(**options)
|
|
118
|
+
SharedEndpoint.bound(self, **options)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def connected(**options)
|
|
122
|
+
SharedEndpoint.connected(self, **options)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
112
125
|
end
|
|
113
126
|
end
|