async-io 1.27.5 → 1.30.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/lib/async/io/generic.rb +1 -1
- data/lib/async/io/host_endpoint.rb +1 -1
- data/lib/async/io/stream.rb +18 -32
- data/{spec/async/io/trap_spec.rb → lib/async/io/threads.rb} +37 -26
- data/lib/async/io/trap.rb +4 -3
- data/lib/async/io/version.rb +1 -1
- metadata +45 -95
- data/.editorconfig +0 -6
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.travis.yml +0 -25
- data/.yardopts +0 -2
- data/Gemfile +0 -18
- data/README.md +0 -171
- data/Rakefile +0 -8
- 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 -318
- 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: 23f8785195920d67cdc0497fd7cbbc4dd261a34722974eff69e49cab8a9bf070
|
4
|
+
data.tar.gz: 448e9628835ce82210974bb5c7537785022261e9d5468e5e423b48a11898202f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcbc8e9004a33571775ec58d946d6939ba1a1d9d296a94a1dac4a3d5cce77a2e9bea87154fffe59663f1f59bc8585ee5d3509e77f4257d3dedb7e8372af777d5
|
7
|
+
data.tar.gz: c3849305261631553ebbf4a6d2e92fabdbd7ef9d0c6ae94353efd5ad20e4001d4309cc21b1570194aa0a0028e008f6fe6f8f784038adea9f41d6e050494b700c
|
data/lib/async/io/generic.rb
CHANGED
@@ -29,7 +29,7 @@ module Async
|
|
29
29
|
BLOCK_SIZE = ENV.fetch('ASYNC_IO_BLOCK_SIZE', 1024*64).to_i
|
30
30
|
|
31
31
|
# The maximum read size when appending to IO buffers. Defaults to 8MB.
|
32
|
-
MAXIMUM_READ_SIZE = ENV.fetch('ASYNC_IO_MAXIMUM_READ_SIZE', BLOCK_SIZE * 128
|
32
|
+
MAXIMUM_READ_SIZE = ENV.fetch('ASYNC_IO_MAXIMUM_READ_SIZE', BLOCK_SIZE * 128).to_i
|
33
33
|
|
34
34
|
# Convert a Ruby ::IO object to a wrapped instance:
|
35
35
|
def self.try_convert(io, &block)
|
@@ -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,10 @@ 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
|
52
|
+
|
51
53
|
@writing = Async::Semaphore.new(1)
|
52
54
|
|
53
55
|
# We don't want Ruby to do any IO buffering.
|
@@ -147,17 +149,19 @@ module Async
|
|
147
149
|
end
|
148
150
|
|
149
151
|
# Flushes buffered data to the stream.
|
150
|
-
def flush
|
151
|
-
if
|
152
|
-
|
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
|
153
158
|
|
154
|
-
|
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,23 +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
|
249
|
-
if @pending > 0
|
250
|
-
"Draining #{@pending} writes (#{@write_buffer.bytesize} bytes)..."
|
251
|
-
else
|
252
|
-
"Draining immediate write (#{@write_buffer.bytesize} bytes)..."
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
@write_buffer, @drain_buffer = @drain_buffer, @write_buffer
|
257
|
-
|
258
|
-
@io.write(@drain_buffer)
|
259
|
-
@drain_buffer.clear
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
250
|
# Fills the buffer from the underlying stream.
|
264
251
|
def fill_read_buffer(size = @block_size)
|
265
252
|
# We impose a limit because the underlying `read` system call can fail if we request too much data in one go.
|
@@ -268,9 +255,7 @@ module Async
|
|
268
255
|
end
|
269
256
|
|
270
257
|
# This effectively ties the input and output stream together.
|
271
|
-
|
272
|
-
drain_write_buffer
|
273
|
-
end
|
258
|
+
flush
|
274
259
|
|
275
260
|
if @read_buffer.empty?
|
276
261
|
if @io.read_nonblock(size, @read_buffer, exception: false)
|
@@ -281,6 +266,7 @@ module Async
|
|
281
266
|
if chunk = @io.read_nonblock(size, @input_buffer, exception: false)
|
282
267
|
@read_buffer << chunk
|
283
268
|
# Async.logger.debug(self, name: "read") {@read_buffer.inspect}
|
269
|
+
|
284
270
|
return true
|
285
271
|
end
|
286
272
|
end
|
@@ -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
@@ -87,9 +87,10 @@ module Async
|
|
87
87
|
# Deprecated.
|
88
88
|
alias trap wait
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
# In order to avoid blocking the reactor, specify `transient: true` as an option.
|
91
|
+
def async(parent: Task.current, **options, &block)
|
92
|
+
parent.async(**options) do |task|
|
93
|
+
self.wait(task: task, &block)
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-02 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
|
@@ -109,36 +137,11 @@ dependencies:
|
|
109
137
|
- !ruby/object:Gem::Version
|
110
138
|
version: '3.0'
|
111
139
|
description:
|
112
|
-
email:
|
113
|
-
- samuel.williams@oriontransfer.co.nz
|
140
|
+
email:
|
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
|
-
- Rakefile
|
126
|
-
- async-io.gemspec
|
127
|
-
- examples/allocations/byteslice.rb
|
128
|
-
- examples/allocations/memory.rb
|
129
|
-
- examples/allocations/read_chunks.rb
|
130
|
-
- examples/chat/client.rb
|
131
|
-
- examples/chat/server.rb
|
132
|
-
- examples/defer/worker.rb
|
133
|
-
- examples/echo/client.rb
|
134
|
-
- examples/echo/server.rb
|
135
|
-
- examples/issues/broken_ssl.rb
|
136
|
-
- examples/issues/pipes.rb
|
137
|
-
- examples/millions/client.rb
|
138
|
-
- examples/millions/server.rb
|
139
|
-
- examples/udp/client.rb
|
140
|
-
- examples/udp/server.rb
|
141
|
-
- gems/nio4r-2.3.gemfile
|
142
145
|
- lib/async/io.rb
|
143
146
|
- lib/async/io/address.rb
|
144
147
|
- lib/async/io/address_endpoint.rb
|
@@ -161,38 +164,12 @@ files:
|
|
161
164
|
- lib/async/io/standard.rb
|
162
165
|
- lib/async/io/stream.rb
|
163
166
|
- lib/async/io/tcp_socket.rb
|
167
|
+
- lib/async/io/threads.rb
|
164
168
|
- lib/async/io/trap.rb
|
165
169
|
- lib/async/io/udp_socket.rb
|
166
170
|
- lib/async/io/unix_endpoint.rb
|
167
171
|
- lib/async/io/unix_socket.rb
|
168
172
|
- lib/async/io/version.rb
|
169
|
-
- spec/addrinfo.rb
|
170
|
-
- spec/async/io/buffer_spec.rb
|
171
|
-
- spec/async/io/c10k_spec.rb
|
172
|
-
- spec/async/io/echo_spec.rb
|
173
|
-
- spec/async/io/endpoint_spec.rb
|
174
|
-
- spec/async/io/generic_examples.rb
|
175
|
-
- spec/async/io/generic_spec.rb
|
176
|
-
- spec/async/io/notification_spec.rb
|
177
|
-
- spec/async/io/protocol/line_spec.rb
|
178
|
-
- spec/async/io/shared_endpoint/server_spec.rb
|
179
|
-
- spec/async/io/shared_endpoint_spec.rb
|
180
|
-
- spec/async/io/socket/tcp_spec.rb
|
181
|
-
- spec/async/io/socket/udp_spec.rb
|
182
|
-
- spec/async/io/socket_spec.rb
|
183
|
-
- spec/async/io/ssl_server_spec.rb
|
184
|
-
- spec/async/io/ssl_socket_spec.rb
|
185
|
-
- spec/async/io/standard_spec.rb
|
186
|
-
- spec/async/io/stream_context.rb
|
187
|
-
- spec/async/io/stream_spec.rb
|
188
|
-
- spec/async/io/tcp_socket_spec.rb
|
189
|
-
- spec/async/io/trap_spec.rb
|
190
|
-
- spec/async/io/udp_socket_spec.rb
|
191
|
-
- spec/async/io/unix_endpoint_spec.rb
|
192
|
-
- spec/async/io/unix_socket_spec.rb
|
193
|
-
- spec/async/io/wrap/http_rb_spec.rb
|
194
|
-
- spec/async/io/wrap/tcp_spec.rb
|
195
|
-
- spec/spec_helper.rb
|
196
173
|
homepage: https://github.com/socketry/async-io
|
197
174
|
licenses:
|
198
175
|
- MIT
|
@@ -205,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
205
182
|
requirements:
|
206
183
|
- - "~>"
|
207
184
|
- !ruby/object:Gem::Version
|
208
|
-
version: '2.
|
185
|
+
version: '2.5'
|
209
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
187
|
requirements:
|
211
188
|
- - ">="
|
@@ -216,31 +193,4 @@ rubygems_version: 3.1.2
|
|
216
193
|
signing_key:
|
217
194
|
specification_version: 4
|
218
195
|
summary: Provides support for asynchonous TCP, UDP, UNIX and SSL sockets.
|
219
|
-
test_files:
|
220
|
-
- spec/addrinfo.rb
|
221
|
-
- spec/async/io/buffer_spec.rb
|
222
|
-
- spec/async/io/c10k_spec.rb
|
223
|
-
- spec/async/io/echo_spec.rb
|
224
|
-
- spec/async/io/endpoint_spec.rb
|
225
|
-
- spec/async/io/generic_examples.rb
|
226
|
-
- spec/async/io/generic_spec.rb
|
227
|
-
- spec/async/io/notification_spec.rb
|
228
|
-
- spec/async/io/protocol/line_spec.rb
|
229
|
-
- spec/async/io/shared_endpoint/server_spec.rb
|
230
|
-
- spec/async/io/shared_endpoint_spec.rb
|
231
|
-
- spec/async/io/socket/tcp_spec.rb
|
232
|
-
- spec/async/io/socket/udp_spec.rb
|
233
|
-
- spec/async/io/socket_spec.rb
|
234
|
-
- spec/async/io/ssl_server_spec.rb
|
235
|
-
- spec/async/io/ssl_socket_spec.rb
|
236
|
-
- spec/async/io/standard_spec.rb
|
237
|
-
- spec/async/io/stream_context.rb
|
238
|
-
- spec/async/io/stream_spec.rb
|
239
|
-
- spec/async/io/tcp_socket_spec.rb
|
240
|
-
- spec/async/io/trap_spec.rb
|
241
|
-
- spec/async/io/udp_socket_spec.rb
|
242
|
-
- spec/async/io/unix_endpoint_spec.rb
|
243
|
-
- spec/async/io/unix_socket_spec.rb
|
244
|
-
- spec/async/io/wrap/http_rb_spec.rb
|
245
|
-
- spec/async/io/wrap/tcp_spec.rb
|
246
|
-
- spec/spec_helper.rb
|
196
|
+
test_files: []
|