async-io 1.27.6 → 1.30.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/io/host_endpoint.rb +1 -1
- data/lib/async/io/stream.rb +16 -42
- data/{spec/async/io/trap_spec.rb → lib/async/io/threads.rb} +37 -26
- data/lib/async/io/trap.rb +8 -3
- data/lib/async/io/version.rb +1 -1
- metadata +50 -99
- data/.editorconfig +0 -6
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.travis.yml +0 -25
- data/.yardopts +0 -2
- data/Gemfile +0 -20
- data/README.md +0 -171
- data/async-io.gemspec +0 -30
- data/examples/allocations/byteslice.rb +0 -29
- data/examples/allocations/memory.rb +0 -16
- data/examples/allocations/read_chunks.rb +0 -18
- data/examples/chat/client.rb +0 -58
- data/examples/chat/server.rb +0 -83
- data/examples/defer/worker.rb +0 -29
- data/examples/echo/client.rb +0 -23
- data/examples/echo/server.rb +0 -58
- data/examples/issues/broken_ssl.rb +0 -15
- data/examples/issues/pipes.rb +0 -34
- data/examples/millions/client.rb +0 -44
- data/examples/millions/server.rb +0 -41
- data/examples/udp/client.rb +0 -14
- data/examples/udp/server.rb +0 -16
- data/gems/nio4r-2.3.gemfile +0 -3
- data/spec/addrinfo.rb +0 -16
- data/spec/async/io/buffer_spec.rb +0 -48
- data/spec/async/io/c10k_spec.rb +0 -138
- data/spec/async/io/echo_spec.rb +0 -75
- data/spec/async/io/endpoint_spec.rb +0 -105
- data/spec/async/io/generic_examples.rb +0 -73
- data/spec/async/io/generic_spec.rb +0 -107
- data/spec/async/io/notification_spec.rb +0 -46
- data/spec/async/io/protocol/line_spec.rb +0 -81
- data/spec/async/io/shared_endpoint/server_spec.rb +0 -72
- data/spec/async/io/shared_endpoint_spec.rb +0 -67
- data/spec/async/io/socket/tcp_spec.rb +0 -101
- data/spec/async/io/socket/udp_spec.rb +0 -65
- data/spec/async/io/socket_spec.rb +0 -149
- data/spec/async/io/ssl_server_spec.rb +0 -133
- data/spec/async/io/ssl_socket_spec.rb +0 -96
- data/spec/async/io/standard_spec.rb +0 -47
- data/spec/async/io/stream_context.rb +0 -30
- data/spec/async/io/stream_spec.rb +0 -337
- data/spec/async/io/tcp_socket_spec.rb +0 -84
- data/spec/async/io/udp_socket_spec.rb +0 -56
- data/spec/async/io/unix_endpoint_spec.rb +0 -106
- data/spec/async/io/unix_socket_spec.rb +0 -66
- data/spec/async/io/wrap/http_rb_spec.rb +0 -47
- data/spec/async/io/wrap/tcp_spec.rb +0 -79
- data/spec/spec_helper.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78e506c80ee6dca2ec605f761ba21b978eae84ed299a9ec9aecad63b5c7cd71b
|
4
|
+
data.tar.gz: 2b8024c08e12cf4c1d7aae0765acc2d255c992a86550b5e734491e91101d0647
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4716622a716f04a70848e3775f3d7d25ff32c0b05176b4b4d9db8807fa16f53ebc0c9537764c848ec5036c9e9dfdc1bdefce2a3eec9dce739a89f556333cde1
|
7
|
+
data.tar.gz: c2bc7594737d8e2094fa8278d3187e8ca287eda156050593aa59e5fcbc9d9e449a32d10f769b6af6150ff61e6855939f06d4de4e606c4bbddb37fc85edcdecd2
|
@@ -77,7 +77,7 @@ module Async
|
|
77
77
|
# @yield [Socket] the bound socket
|
78
78
|
# @return [Array<Socket>] an array of bound sockets
|
79
79
|
def bind(&block)
|
80
|
-
Addrinfo.foreach(*@specification).
|
80
|
+
Addrinfo.foreach(*@specification).map do |address|
|
81
81
|
Socket.bind(address, **@options, &block)
|
82
82
|
end
|
83
83
|
end
|
data/lib/async/io/stream.rb
CHANGED
@@ -46,8 +46,9 @@ module Async
|
|
46
46
|
@io = io
|
47
47
|
@eof = false
|
48
48
|
|
49
|
-
@deferred = deferred
|
50
49
|
@pending = 0
|
50
|
+
# This field is ignored, but used to mean, try to buffer packets in a single iteration of the reactor.
|
51
|
+
# @deferred = deferred
|
51
52
|
|
52
53
|
@writing = Async::Semaphore.new(1)
|
53
54
|
|
@@ -148,16 +149,19 @@ module Async
|
|
148
149
|
end
|
149
150
|
|
150
151
|
# Flushes buffered data to the stream.
|
151
|
-
def flush
|
152
|
-
if
|
153
|
-
|
152
|
+
def flush
|
153
|
+
return if @write_buffer.empty?
|
154
|
+
|
155
|
+
@writing.acquire do
|
156
|
+
# Flip the write buffer and drain buffer:
|
157
|
+
@write_buffer, @drain_buffer = @drain_buffer, @write_buffer
|
154
158
|
|
155
|
-
|
156
|
-
|
157
|
-
|
159
|
+
begin
|
160
|
+
@io.write(@drain_buffer)
|
161
|
+
ensure
|
162
|
+
# If the write operation fails, we still need to clear this buffer, and the data is essentially lost.
|
163
|
+
@drain_buffer.clear
|
158
164
|
end
|
159
|
-
else
|
160
|
-
drain_write_buffer unless @write_buffer.empty?
|
161
165
|
end
|
162
166
|
end
|
163
167
|
|
@@ -203,7 +207,7 @@ module Async
|
|
203
207
|
end
|
204
208
|
|
205
209
|
def close_write
|
206
|
-
|
210
|
+
flush
|
207
211
|
ensure
|
208
212
|
@io.close_write
|
209
213
|
end
|
@@ -213,7 +217,7 @@ module Async
|
|
213
217
|
return if @io.closed?
|
214
218
|
|
215
219
|
begin
|
216
|
-
|
220
|
+
flush
|
217
221
|
rescue
|
218
222
|
# We really can't do anything here unless we want #close to raise exceptions.
|
219
223
|
ensure
|
@@ -243,34 +247,6 @@ module Async
|
|
243
247
|
|
244
248
|
private
|
245
249
|
|
246
|
-
def drain_write_buffer
|
247
|
-
@writing.acquire do
|
248
|
-
Async.logger.debug(self) do |buffer|
|
249
|
-
if @pending > 0
|
250
|
-
buffer.puts "Draining #{@pending} writes (#{@write_buffer.bytesize} bytes)..."
|
251
|
-
else
|
252
|
-
buffer.puts "Draining immediate write (#{@write_buffer.bytesize} bytes)..."
|
253
|
-
end
|
254
|
-
|
255
|
-
# buffer.puts "@write_buffer = #{@write_buffer.inspect}"
|
256
|
-
# buffer.puts "@drain_buffer = #{@drain_buffer.inspect}"
|
257
|
-
end
|
258
|
-
|
259
|
-
# Flip the write buffer and drain buffer:
|
260
|
-
@write_buffer, @drain_buffer = @drain_buffer, @write_buffer
|
261
|
-
|
262
|
-
# The write buffer no longer contains pending writes:
|
263
|
-
@pending = 0
|
264
|
-
|
265
|
-
begin
|
266
|
-
@io.write(@drain_buffer)
|
267
|
-
ensure
|
268
|
-
# If the write operation fails, we still need to clear this buffer, and the data is essentially lost.
|
269
|
-
@drain_buffer.clear
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
250
|
# Fills the buffer from the underlying stream.
|
275
251
|
def fill_read_buffer(size = @block_size)
|
276
252
|
# We impose a limit because the underlying `read` system call can fail if we request too much data in one go.
|
@@ -279,9 +255,7 @@ module Async
|
|
279
255
|
end
|
280
256
|
|
281
257
|
# This effectively ties the input and output stream together.
|
282
|
-
|
283
|
-
drain_write_buffer
|
284
|
-
end
|
258
|
+
flush
|
285
259
|
|
286
260
|
if @read_buffer.empty?
|
287
261
|
if @io.read_nonblock(size, @read_buffer, exception: false)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright,
|
3
|
+
# Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -20,33 +20,44 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
|
23
|
+
require_relative 'notification'
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
25
|
+
module Async
|
26
|
+
module IO
|
27
|
+
class Threads
|
28
|
+
def initialize(parent: nil)
|
29
|
+
@parent = parent
|
30
|
+
end
|
31
|
+
|
32
|
+
def async(parent: (@parent or Task.current))
|
33
|
+
parent.async do |task|
|
34
|
+
notification = Async::IO::Notification.new
|
35
|
+
|
36
|
+
thread = Thread.new do
|
37
|
+
yield
|
38
|
+
ensure
|
39
|
+
notification.signal
|
40
|
+
end
|
41
|
+
|
42
|
+
task.annotate "Waiting for thread to finish..."
|
43
|
+
|
44
|
+
notification.wait
|
45
|
+
|
46
|
+
thread.value
|
47
|
+
ensure
|
48
|
+
if thread&.alive?
|
49
|
+
thread.raise(Stop)
|
50
|
+
|
51
|
+
begin
|
52
|
+
thread.join
|
53
|
+
rescue Stop
|
54
|
+
# Ignore.
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
notification&.close
|
59
|
+
end
|
43
60
|
end
|
44
61
|
end
|
45
|
-
|
46
|
-
subject.trigger
|
47
|
-
|
48
|
-
waiting_task.wait
|
49
|
-
|
50
|
-
expect(trapped).to be_truthy
|
51
62
|
end
|
52
63
|
end
|
data/lib/async/io/trap.rb
CHANGED
@@ -36,6 +36,10 @@ module Async
|
|
36
36
|
@mutex = Mutex.new
|
37
37
|
end
|
38
38
|
|
39
|
+
def to_s
|
40
|
+
"\#<#{self.class} #{@name}>"
|
41
|
+
end
|
42
|
+
|
39
43
|
# Ignore the trap within the current process. Can be invoked before forking and/or invoking `install!` to assert default behaviour.
|
40
44
|
def ignore!
|
41
45
|
Signal.trap(@name, :IGNORE)
|
@@ -87,9 +91,10 @@ module Async
|
|
87
91
|
# Deprecated.
|
88
92
|
alias trap wait
|
89
93
|
|
90
|
-
|
91
|
-
|
92
|
-
|
94
|
+
# In order to avoid blocking the reactor, specify `transient: true` as an option.
|
95
|
+
def async(parent: Task.current, **options, &block)
|
96
|
+
parent.async(**options) do |task|
|
97
|
+
self.wait(task: task, &block)
|
93
98
|
end
|
94
99
|
end
|
95
100
|
|
data/lib/async/io/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.30.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: async-container
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.15'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.15'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: async-rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,21 +53,35 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '1.10'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: bake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
61
|
+
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: bake-bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bake-modernize
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
87
|
- - ">="
|
@@ -81,19 +109,19 @@ dependencies:
|
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
112
|
+
name: covered
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
|
-
- - "
|
115
|
+
- - ">="
|
88
116
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
117
|
+
version: '0'
|
90
118
|
type: :development
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
|
-
- - "
|
122
|
+
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
124
|
+
version: '0'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: rspec
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,36 +136,12 @@ dependencies:
|
|
108
136
|
- - "~>"
|
109
137
|
- !ruby/object:Gem::Version
|
110
138
|
version: '3.0'
|
111
|
-
description:
|
139
|
+
description:
|
112
140
|
email:
|
113
|
-
- samuel.williams@oriontransfer.co.nz
|
114
141
|
executables: []
|
115
142
|
extensions: []
|
116
143
|
extra_rdoc_files: []
|
117
144
|
files:
|
118
|
-
- ".editorconfig"
|
119
|
-
- ".gitignore"
|
120
|
-
- ".rspec"
|
121
|
-
- ".travis.yml"
|
122
|
-
- ".yardopts"
|
123
|
-
- Gemfile
|
124
|
-
- README.md
|
125
|
-
- async-io.gemspec
|
126
|
-
- examples/allocations/byteslice.rb
|
127
|
-
- examples/allocations/memory.rb
|
128
|
-
- examples/allocations/read_chunks.rb
|
129
|
-
- examples/chat/client.rb
|
130
|
-
- examples/chat/server.rb
|
131
|
-
- examples/defer/worker.rb
|
132
|
-
- examples/echo/client.rb
|
133
|
-
- examples/echo/server.rb
|
134
|
-
- examples/issues/broken_ssl.rb
|
135
|
-
- examples/issues/pipes.rb
|
136
|
-
- examples/millions/client.rb
|
137
|
-
- examples/millions/server.rb
|
138
|
-
- examples/udp/client.rb
|
139
|
-
- examples/udp/server.rb
|
140
|
-
- gems/nio4r-2.3.gemfile
|
141
145
|
- lib/async/io.rb
|
142
146
|
- lib/async/io/address.rb
|
143
147
|
- lib/async/io/address_endpoint.rb
|
@@ -160,86 +164,33 @@ files:
|
|
160
164
|
- lib/async/io/standard.rb
|
161
165
|
- lib/async/io/stream.rb
|
162
166
|
- lib/async/io/tcp_socket.rb
|
167
|
+
- lib/async/io/threads.rb
|
163
168
|
- lib/async/io/trap.rb
|
164
169
|
- lib/async/io/udp_socket.rb
|
165
170
|
- lib/async/io/unix_endpoint.rb
|
166
171
|
- lib/async/io/unix_socket.rb
|
167
172
|
- lib/async/io/version.rb
|
168
|
-
- spec/addrinfo.rb
|
169
|
-
- spec/async/io/buffer_spec.rb
|
170
|
-
- spec/async/io/c10k_spec.rb
|
171
|
-
- spec/async/io/echo_spec.rb
|
172
|
-
- spec/async/io/endpoint_spec.rb
|
173
|
-
- spec/async/io/generic_examples.rb
|
174
|
-
- spec/async/io/generic_spec.rb
|
175
|
-
- spec/async/io/notification_spec.rb
|
176
|
-
- spec/async/io/protocol/line_spec.rb
|
177
|
-
- spec/async/io/shared_endpoint/server_spec.rb
|
178
|
-
- spec/async/io/shared_endpoint_spec.rb
|
179
|
-
- spec/async/io/socket/tcp_spec.rb
|
180
|
-
- spec/async/io/socket/udp_spec.rb
|
181
|
-
- spec/async/io/socket_spec.rb
|
182
|
-
- spec/async/io/ssl_server_spec.rb
|
183
|
-
- spec/async/io/ssl_socket_spec.rb
|
184
|
-
- spec/async/io/standard_spec.rb
|
185
|
-
- spec/async/io/stream_context.rb
|
186
|
-
- spec/async/io/stream_spec.rb
|
187
|
-
- spec/async/io/tcp_socket_spec.rb
|
188
|
-
- spec/async/io/trap_spec.rb
|
189
|
-
- spec/async/io/udp_socket_spec.rb
|
190
|
-
- spec/async/io/unix_endpoint_spec.rb
|
191
|
-
- spec/async/io/unix_socket_spec.rb
|
192
|
-
- spec/async/io/wrap/http_rb_spec.rb
|
193
|
-
- spec/async/io/wrap/tcp_spec.rb
|
194
|
-
- spec/spec_helper.rb
|
195
173
|
homepage: https://github.com/socketry/async-io
|
196
174
|
licenses:
|
197
175
|
- MIT
|
198
176
|
metadata: {}
|
199
|
-
post_install_message:
|
177
|
+
post_install_message:
|
200
178
|
rdoc_options: []
|
201
179
|
require_paths:
|
202
180
|
- lib
|
203
181
|
required_ruby_version: !ruby/object:Gem::Requirement
|
204
182
|
requirements:
|
205
|
-
- - "
|
183
|
+
- - ">="
|
206
184
|
- !ruby/object:Gem::Version
|
207
|
-
version: '2.
|
185
|
+
version: '2.5'
|
208
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
187
|
requirements:
|
210
188
|
- - ">="
|
211
189
|
- !ruby/object:Gem::Version
|
212
190
|
version: '0'
|
213
191
|
requirements: []
|
214
|
-
rubygems_version: 3.
|
215
|
-
signing_key:
|
192
|
+
rubygems_version: 3.1.2
|
193
|
+
signing_key:
|
216
194
|
specification_version: 4
|
217
195
|
summary: Provides support for asynchonous TCP, UDP, UNIX and SSL sockets.
|
218
|
-
test_files:
|
219
|
-
- spec/addrinfo.rb
|
220
|
-
- spec/async/io/buffer_spec.rb
|
221
|
-
- spec/async/io/c10k_spec.rb
|
222
|
-
- spec/async/io/echo_spec.rb
|
223
|
-
- spec/async/io/endpoint_spec.rb
|
224
|
-
- spec/async/io/generic_examples.rb
|
225
|
-
- spec/async/io/generic_spec.rb
|
226
|
-
- spec/async/io/notification_spec.rb
|
227
|
-
- spec/async/io/protocol/line_spec.rb
|
228
|
-
- spec/async/io/shared_endpoint/server_spec.rb
|
229
|
-
- spec/async/io/shared_endpoint_spec.rb
|
230
|
-
- spec/async/io/socket/tcp_spec.rb
|
231
|
-
- spec/async/io/socket/udp_spec.rb
|
232
|
-
- spec/async/io/socket_spec.rb
|
233
|
-
- spec/async/io/ssl_server_spec.rb
|
234
|
-
- spec/async/io/ssl_socket_spec.rb
|
235
|
-
- spec/async/io/standard_spec.rb
|
236
|
-
- spec/async/io/stream_context.rb
|
237
|
-
- spec/async/io/stream_spec.rb
|
238
|
-
- spec/async/io/tcp_socket_spec.rb
|
239
|
-
- spec/async/io/trap_spec.rb
|
240
|
-
- spec/async/io/udp_socket_spec.rb
|
241
|
-
- spec/async/io/unix_endpoint_spec.rb
|
242
|
-
- spec/async/io/unix_socket_spec.rb
|
243
|
-
- spec/async/io/wrap/http_rb_spec.rb
|
244
|
-
- spec/async/io/wrap/tcp_spec.rb
|
245
|
-
- spec/spec_helper.rb
|
196
|
+
test_files: []
|