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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/async/io/generic.rb +1 -1
  3. data/lib/async/io/host_endpoint.rb +1 -1
  4. data/lib/async/io/stream.rb +18 -32
  5. data/{spec/async/io/trap_spec.rb → lib/async/io/threads.rb} +37 -26
  6. data/lib/async/io/trap.rb +4 -3
  7. data/lib/async/io/version.rb +1 -1
  8. metadata +45 -95
  9. data/.editorconfig +0 -6
  10. data/.gitignore +0 -13
  11. data/.rspec +0 -3
  12. data/.travis.yml +0 -25
  13. data/.yardopts +0 -2
  14. data/Gemfile +0 -18
  15. data/README.md +0 -171
  16. data/Rakefile +0 -8
  17. data/async-io.gemspec +0 -30
  18. data/examples/allocations/byteslice.rb +0 -29
  19. data/examples/allocations/memory.rb +0 -16
  20. data/examples/allocations/read_chunks.rb +0 -18
  21. data/examples/chat/client.rb +0 -58
  22. data/examples/chat/server.rb +0 -83
  23. data/examples/defer/worker.rb +0 -29
  24. data/examples/echo/client.rb +0 -23
  25. data/examples/echo/server.rb +0 -58
  26. data/examples/issues/broken_ssl.rb +0 -15
  27. data/examples/issues/pipes.rb +0 -34
  28. data/examples/millions/client.rb +0 -44
  29. data/examples/millions/server.rb +0 -41
  30. data/examples/udp/client.rb +0 -14
  31. data/examples/udp/server.rb +0 -16
  32. data/gems/nio4r-2.3.gemfile +0 -3
  33. data/spec/addrinfo.rb +0 -16
  34. data/spec/async/io/buffer_spec.rb +0 -48
  35. data/spec/async/io/c10k_spec.rb +0 -138
  36. data/spec/async/io/echo_spec.rb +0 -75
  37. data/spec/async/io/endpoint_spec.rb +0 -105
  38. data/spec/async/io/generic_examples.rb +0 -73
  39. data/spec/async/io/generic_spec.rb +0 -107
  40. data/spec/async/io/notification_spec.rb +0 -46
  41. data/spec/async/io/protocol/line_spec.rb +0 -81
  42. data/spec/async/io/shared_endpoint/server_spec.rb +0 -72
  43. data/spec/async/io/shared_endpoint_spec.rb +0 -67
  44. data/spec/async/io/socket/tcp_spec.rb +0 -101
  45. data/spec/async/io/socket/udp_spec.rb +0 -65
  46. data/spec/async/io/socket_spec.rb +0 -149
  47. data/spec/async/io/ssl_server_spec.rb +0 -133
  48. data/spec/async/io/ssl_socket_spec.rb +0 -96
  49. data/spec/async/io/standard_spec.rb +0 -47
  50. data/spec/async/io/stream_context.rb +0 -30
  51. data/spec/async/io/stream_spec.rb +0 -318
  52. data/spec/async/io/tcp_socket_spec.rb +0 -84
  53. data/spec/async/io/udp_socket_spec.rb +0 -56
  54. data/spec/async/io/unix_endpoint_spec.rb +0 -106
  55. data/spec/async/io/unix_socket_spec.rb +0 -66
  56. data/spec/async/io/wrap/http_rb_spec.rb +0 -47
  57. data/spec/async/io/wrap/tcp_spec.rb +0 -79
  58. data/spec/spec_helper.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2aa645f59a002756ee40be3c903917fb8010d91d61f1984a863481cab364644c
4
- data.tar.gz: 8e4fc966f387cb76a7635923d4f3803a2cd91354ddf63fc4618431c97c1c89e9
3
+ metadata.gz: 23f8785195920d67cdc0497fd7cbbc4dd261a34722974eff69e49cab8a9bf070
4
+ data.tar.gz: 448e9628835ce82210974bb5c7537785022261e9d5468e5e423b48a11898202f
5
5
  SHA512:
6
- metadata.gz: 297100087ebdf7a49a147b3b29f7e1b1c9cceffcf8c2a68857bb12cf10dfde34e83e5f18c53a1060f2833bb630b17ba72f5532bbd3453e953d5362c30d4eaf2c
7
- data.tar.gz: 0dfb45ca2d1134185511c44a91bf2c02e8ded1cb7e31fc10cb71ac2de93444aa45a5dd44a5edb94f224a1b2800c1d63818ae23803a0607137de5a810486fa878
6
+ metadata.gz: dcbc8e9004a33571775ec58d946d6939ba1a1d9d296a94a1dac4a3d5cce77a2e9bea87154fffe59663f1f59bc8585ee5d3509e77f4257d3dedb7e8372af777d5
7
+ data.tar.gz: c3849305261631553ebbf4a6d2e92fabdbd7ef9d0c6ae94353efd5ad20e4001d4309cc21b1570194aa0a0028e008f6fe6f8f784038adea9f41d6e050494b700c
@@ -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 * 8).to_i
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).collect do |address|
80
+ Addrinfo.foreach(*@specification).map do |address|
81
81
  Socket.bind(address, **@options, &block)
82
82
  end
83
83
  end
@@ -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(deferred: @deferred)
151
- if deferred and task = Task.current?
152
- @pending += 1
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
- if @pending == 1
155
- task.yield
156
- drain_write_buffer unless @write_buffer.empty?
157
- @pending = 0
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
- drain_write_buffer unless @write_buffer.empty?
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
- drain_write_buffer unless @write_buffer.empty?
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
- if @pending > 0
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, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
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
- require 'async/io/trap'
23
+ require_relative 'notification'
24
24
 
25
- RSpec.describe Async::IO::Trap do
26
- include_context Async::RSpec::Reactor
27
-
28
- subject {described_class.new(:USR2)}
29
-
30
- it "can ignore signal" do
31
- subject.ignore!
32
-
33
- Process.kill(:USR2, Process.pid)
34
- end
35
-
36
- it "should wait for signal" do
37
- trapped = false
38
-
39
- waiting_task = reactor.async do
40
- subject.wait do
41
- trapped = true
42
- break
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
@@ -87,9 +87,10 @@ module Async
87
87
  # Deprecated.
88
88
  alias trap wait
89
89
 
90
- def async(parent: Task.current, &block)
91
- parent.async do |task|
92
- self.trap(task: task, &block)
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
 
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Async
24
24
  module IO
25
- VERSION = "1.27.5"
25
+ VERSION = "1.30.0"
26
26
  end
27
27
  end
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.27.5
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-03-21 00:00:00.000000000 Z
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: async-container
56
+ name: bake
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - "~>"
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '0.15'
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.15'
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: covered
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: rake
112
+ name: covered
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - "~>"
115
+ - - ">="
88
116
  - !ruby/object:Gem::Version
89
- version: '10.0'
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: '10.0'
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.4'
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: []