async-io 1.29.0 → 1.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/lib/async/io/host_endpoint.rb +1 -1
  3. data/lib/async/io/peer.rb +2 -2
  4. data/lib/async/io/shared_endpoint.rb +4 -4
  5. data/lib/async/io/socket.rb +2 -2
  6. data/lib/async/io/ssl_socket.rb +2 -4
  7. data/lib/async/io/stream.rb +2 -2
  8. data/lib/async/io/tcp_socket.rb +1 -1
  9. data/lib/async/io/threads.rb +42 -20
  10. data/lib/async/io/trap.rb +8 -3
  11. data/lib/async/io/version.rb +1 -1
  12. metadata +43 -95
  13. data/.editorconfig +0 -6
  14. data/.github/workflows/development.yml +0 -55
  15. data/.gitignore +0 -13
  16. data/.rspec +0 -3
  17. data/.yardopts +0 -2
  18. data/Gemfile +0 -13
  19. data/README.md +0 -171
  20. data/async-io.gemspec +0 -30
  21. data/examples/allocations/byteslice.rb +0 -29
  22. data/examples/allocations/memory.rb +0 -16
  23. data/examples/allocations/read_chunks.rb +0 -18
  24. data/examples/chat/client.rb +0 -58
  25. data/examples/chat/server.rb +0 -83
  26. data/examples/defer/worker.rb +0 -29
  27. data/examples/echo/client.rb +0 -23
  28. data/examples/echo/server.rb +0 -58
  29. data/examples/issues/broken_ssl.rb +0 -15
  30. data/examples/issues/pipes.rb +0 -34
  31. data/examples/millions/client.rb +0 -44
  32. data/examples/millions/server.rb +0 -41
  33. data/examples/udp/client.rb +0 -14
  34. data/examples/udp/server.rb +0 -16
  35. data/gems/nio4r-2.3.gemfile +0 -3
  36. data/spec/addrinfo.rb +0 -16
  37. data/spec/async/io/buffer_spec.rb +0 -48
  38. data/spec/async/io/c10k_spec.rb +0 -138
  39. data/spec/async/io/echo_spec.rb +0 -75
  40. data/spec/async/io/endpoint_spec.rb +0 -105
  41. data/spec/async/io/generic_examples.rb +0 -73
  42. data/spec/async/io/generic_spec.rb +0 -107
  43. data/spec/async/io/notification_spec.rb +0 -46
  44. data/spec/async/io/protocol/line_spec.rb +0 -81
  45. data/spec/async/io/shared_endpoint/server_spec.rb +0 -72
  46. data/spec/async/io/shared_endpoint_spec.rb +0 -65
  47. data/spec/async/io/socket/tcp_spec.rb +0 -101
  48. data/spec/async/io/socket/udp_spec.rb +0 -65
  49. data/spec/async/io/socket_spec.rb +0 -149
  50. data/spec/async/io/ssl_server_spec.rb +0 -133
  51. data/spec/async/io/ssl_socket_spec.rb +0 -96
  52. data/spec/async/io/standard_spec.rb +0 -47
  53. data/spec/async/io/stream_context.rb +0 -30
  54. data/spec/async/io/stream_spec.rb +0 -337
  55. data/spec/async/io/tcp_socket_spec.rb +0 -84
  56. data/spec/async/io/threads_spec.rb +0 -59
  57. data/spec/async/io/trap_spec.rb +0 -52
  58. data/spec/async/io/udp_socket_spec.rb +0 -56
  59. data/spec/async/io/unix_endpoint_spec.rb +0 -106
  60. data/spec/async/io/unix_socket_spec.rb +0 -66
  61. data/spec/async/io/wrap/http_rb_spec.rb +0 -47
  62. data/spec/async/io/wrap/tcp_spec.rb +0 -79
  63. data/spec/spec_helper.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2244383314b8e20f44556404b4615c3ec41215a95fe823b43929e82aee8aa9a0
4
- data.tar.gz: dfd4bb8127fa72430e2155c8b22b69308a2f961f85fcb8230f5fc09c347a3db3
3
+ metadata.gz: 28c67d83e13a3537bb14d747c72bc256835037bd124c7f3d1a7d3d1bea352a21
4
+ data.tar.gz: 0bf69a853dd14ecb1523d2b2b2b228efcb04570483d005c02f9c10c6cf0b66db
5
5
  SHA512:
6
- metadata.gz: 2083fe88624d12833af765dd83bd4060a3b7b702d359a3efd08db72cd78f56fe33dbadaf31e98a6980cbcc50164b9557b1a258375d7fa58c9b259ecacf0494aa
7
- data.tar.gz: 4ac435276669ae721afec8b416dc793179467d73794f5f2f34c9276d1db62fc55713a7d4950d92d41bb482674aba051bfd60cddc51f94190a31eee43cfe50222
6
+ metadata.gz: ccbfdff02524ba1aacb471e178cbfbde88eedb0ea933a7a22b4dcac1af7294eb5b3c92107bb7f7202a5023f9d679253e58b3576eba862cdb9dded189f32c3624
7
+ data.tar.gz: e19b54ae9277073a71b1097bb8e7d287045a91dd9a1bcf0a27a399c3138f18f0511126e0d555d95c5486d16a42e03978b07baf7c3d8c8d96a034377f27bb456f
@@ -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
data/lib/async/io/peer.rb CHANGED
@@ -59,13 +59,13 @@ module Async
59
59
  when 0, IPPROTO_TCP
60
60
  self.setsockopt(IPPROTO_TCP, TCP_NODELAY, value ? 1 : 0)
61
61
  else
62
- Async.logger.warn(self) {"Unsure how to sync=#{value} for #{self.protocol}!"}
62
+ Console.logger.warn(self) {"Unsure how to sync=#{value} for #{self.protocol}!"}
63
63
  end
64
64
  rescue Errno::EINVAL
65
65
  # On Darwin, sometimes occurs when the connection is not yet fully formed. Empirically, TCP_NODELAY is enabled despite this result.
66
66
  rescue Errno::EOPNOTSUPP
67
67
  # Some platforms may simply not support the operation.
68
- # Async.logger.warn(self) {"Unable to set sync=#{value}!"}
68
+ # Console.logger.warn(self) {"Unable to set sync=#{value}!"}
69
69
  end
70
70
 
71
71
  def sync
@@ -27,10 +27,10 @@ module Async
27
27
  # Pre-connect and pre-bind sockets so that it can be used between processes.
28
28
  class SharedEndpoint < Endpoint
29
29
  # Create a new `SharedEndpoint` by binding to the given endpoint.
30
- def self.bound(endpoint, backlog = Socket::SOMAXCONN)
30
+ def self.bound(endpoint, backlog: Socket::SOMAXCONN, close_on_exec: false)
31
31
  wrappers = endpoint.bound do |server|
32
32
  server.listen(backlog)
33
- server.close_on_exec = false
33
+ server.close_on_exec = close_on_exec
34
34
  server.reactor = nil
35
35
  end
36
36
 
@@ -38,10 +38,10 @@ module Async
38
38
  end
39
39
 
40
40
  # Create a new `SharedEndpoint` by connecting to the given endpoint.
41
- def self.connected(endpoint)
41
+ def self.connected(endpoint, close_on_exec: false)
42
42
  wrapper = endpoint.connect
43
43
 
44
- wrapper.close_on_exec = false
44
+ wrapper.close_on_exec = close_on_exec
45
45
  wrapper.reactor = nil
46
46
 
47
47
  return self.new(endpoint, [wrapper])
@@ -116,7 +116,7 @@ module Async
116
116
  # @param remote_address [Address] The remote address to connect to.
117
117
  # @option local_address [Address] The local address to bind to before connecting.
118
118
  def self.connect(remote_address, local_address: nil, task: Task.current, **options)
119
- Async.logger.debug(self) {"Connecting to #{remote_address.inspect}"}
119
+ Console.logger.debug(self) {"Connecting to #{remote_address.inspect}"}
120
120
 
121
121
  task.annotate "connecting to #{remote_address.inspect}"
122
122
 
@@ -154,7 +154,7 @@ module Async
154
154
  # @param local_address [Address] The local address to bind to.
155
155
  # @option protocol [Integer] The socket protocol to use.
156
156
  def self.bind(local_address, protocol: 0, task: Task.current, **options, &block)
157
- Async.logger.debug(self) {"Binding to #{local_address.inspect}"}
157
+ Console.logger.debug(self) {"Binding to #{local_address.inspect}"}
158
158
 
159
159
  wrapper = build(local_address.afamily, local_address.socktype, protocol, **options) do |socket|
160
160
  socket.bind(local_address.to_sockaddr)
@@ -30,7 +30,7 @@ module Async
30
30
 
31
31
  # Asynchronous TCP socket wrapper.
32
32
  class SSLSocket < Generic
33
- wraps OpenSSL::SSL::SSLSocket, :alpn_protocol, :cert, :cipher, :client_ca, :context, :getsockopt, :hostname, :hostname=, :npn_protocol, :peer_cert, :peer_cert_chain, :pending, :post_connection_check, :setsockopt, :session, :session=, :session_reused?, :ssl_version, :state, :sync_close, :sync_close=, :sysclose, :verify_result, :tmp_key
33
+ wraps OpenSSL::SSL::SSLSocket, :alpn_protocol, :cert, :cipher, :client_ca, :context, :finished_message, :peer_finished_message, :getsockopt, :hostname, :hostname=, :npn_protocol, :peer_cert, :peer_cert_chain, :pending, :post_connection_check, :setsockopt, :session, :session=, :session_reused?, :ssl_version, :state, :sync_close, :sync_close=, :sysclose, :verify_result, :tmp_key
34
34
 
35
35
  wrap_blocking_method :accept, :accept_nonblock
36
36
  wrap_blocking_method :connect, :connect_nonblock
@@ -68,6 +68,7 @@ module Async
68
68
  super
69
69
  else
70
70
  io = self.class.wrapped_klass.new(socket.to_io, context)
71
+ super(io, socket.reactor)
71
72
 
72
73
  # We detach the socket from the reactor, otherwise it's possible to add the file descriptor to the selector twice, which is bad.
73
74
  socket.reactor = nil
@@ -75,10 +76,7 @@ module Async
75
76
  # This ensures that when the internal IO is closed, it also closes the internal socket:
76
77
  io.sync_close = true
77
78
 
78
- # Copy the timeout:
79
79
  @timeout = socket.timeout
80
-
81
- super(io, socket.reactor)
82
80
  end
83
81
  end
84
82
 
@@ -259,13 +259,13 @@ module Async
259
259
 
260
260
  if @read_buffer.empty?
261
261
  if @io.read_nonblock(size, @read_buffer, exception: false)
262
- # Async.logger.debug(self, name: "read") {@read_buffer.inspect}
262
+ # Console.logger.debug(self, name: "read") {@read_buffer.inspect}
263
263
  return true
264
264
  end
265
265
  else
266
266
  if chunk = @io.read_nonblock(size, @input_buffer, exception: false)
267
267
  @read_buffer << chunk
268
- # Async.logger.debug(self, name: "read") {@read_buffer.inspect}
268
+ # Console.logger.debug(self, name: "read") {@read_buffer.inspect}
269
269
 
270
270
  return true
271
271
  end
@@ -40,7 +40,7 @@ module Async
40
40
  # We do this unusual dance to avoid leaking an "open" socket instance.
41
41
  socket = Socket.connect(remote_address, local_address: local_address)
42
42
  fd = socket.fcntl(Fcntl::F_DUPFD)
43
- Async.logger.debug(self) {"Connected to #{remote_address.inspect}: #{fd}"}
43
+ Console.logger.debug(self) {"Connected to #{remote_address.inspect}: #{fd}"}
44
44
  socket.close
45
45
 
46
46
  super(::TCPSocket.for_fd(fd))
@@ -29,24 +29,18 @@ module Async
29
29
  @parent = parent
30
30
  end
31
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)
32
+ if Async::Scheduler.supported?
33
+ def async(parent: (@parent or Task.current))
34
+ parent.async do
35
+ thread = ::Thread.new do
36
+ yield
37
+ end
38
+
39
+ thread.join
40
+ rescue Stop
41
+ if thread&.alive?
42
+ thread.raise(Stop)
43
+ end
50
44
 
51
45
  begin
52
46
  thread.join
@@ -54,8 +48,36 @@ module Async
54
48
  # Ignore.
55
49
  end
56
50
  end
57
-
58
- notification&.close
51
+ end
52
+ else
53
+ def async(parent: (@parent or Task.current))
54
+ parent.async do |task|
55
+ notification = Async::IO::Notification.new
56
+
57
+ thread = ::Thread.new do
58
+ yield
59
+ ensure
60
+ notification.signal
61
+ end
62
+
63
+ task.annotate "Waiting for thread to finish..."
64
+
65
+ notification.wait
66
+
67
+ thread.value
68
+ ensure
69
+ if thread&.alive?
70
+ thread.raise(Stop)
71
+
72
+ begin
73
+ thread.join
74
+ rescue Stop
75
+ # Ignore.
76
+ end
77
+ end
78
+
79
+ notification&.close
80
+ end
59
81
  end
60
82
  end
61
83
  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
- def async(parent: Task.current, &block)
91
- parent.async do |task|
92
- self.trap(task: task, &block)
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
 
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Async
24
24
  module IO
25
- VERSION = "1.29.0"
25
+ VERSION = "1.32.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.29.0
4
+ version: 1.32.0
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-04-23 00:00:00.000000000 Z
11
+ date: 2021-05-28 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,7 +109,7 @@ dependencies:
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
- name: bake-bundler
112
+ name: covered
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - ">="
@@ -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
- - ".github/workflows/development.yml"
120
- - ".gitignore"
121
- - ".rspec"
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
@@ -166,45 +170,17 @@ files:
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/threads_spec.rb
190
- - spec/async/io/trap_spec.rb
191
- - spec/async/io/udp_socket_spec.rb
192
- - spec/async/io/unix_endpoint_spec.rb
193
- - spec/async/io/unix_socket_spec.rb
194
- - spec/async/io/wrap/http_rb_spec.rb
195
- - spec/async/io/wrap/tcp_spec.rb
196
- - spec/spec_helper.rb
197
173
  homepage: https://github.com/socketry/async-io
198
174
  licenses:
199
175
  - MIT
200
176
  metadata: {}
201
- post_install_message:
177
+ post_install_message:
202
178
  rdoc_options: []
203
179
  require_paths:
204
180
  - lib
205
181
  required_ruby_version: !ruby/object:Gem::Requirement
206
182
  requirements:
207
- - - "~>"
183
+ - - ">="
208
184
  - !ruby/object:Gem::Version
209
185
  version: '2.5'
210
186
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -214,35 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
190
  version: '0'
215
191
  requirements: []
216
192
  rubygems_version: 3.1.2
217
- signing_key:
193
+ signing_key:
218
194
  specification_version: 4
219
195
  summary: Provides support for asynchonous TCP, UDP, UNIX and SSL sockets.
220
- test_files:
221
- - spec/addrinfo.rb
222
- - spec/async/io/buffer_spec.rb
223
- - spec/async/io/c10k_spec.rb
224
- - spec/async/io/echo_spec.rb
225
- - spec/async/io/endpoint_spec.rb
226
- - spec/async/io/generic_examples.rb
227
- - spec/async/io/generic_spec.rb
228
- - spec/async/io/notification_spec.rb
229
- - spec/async/io/protocol/line_spec.rb
230
- - spec/async/io/shared_endpoint/server_spec.rb
231
- - spec/async/io/shared_endpoint_spec.rb
232
- - spec/async/io/socket/tcp_spec.rb
233
- - spec/async/io/socket/udp_spec.rb
234
- - spec/async/io/socket_spec.rb
235
- - spec/async/io/ssl_server_spec.rb
236
- - spec/async/io/ssl_socket_spec.rb
237
- - spec/async/io/standard_spec.rb
238
- - spec/async/io/stream_context.rb
239
- - spec/async/io/stream_spec.rb
240
- - spec/async/io/tcp_socket_spec.rb
241
- - spec/async/io/threads_spec.rb
242
- - spec/async/io/trap_spec.rb
243
- - spec/async/io/udp_socket_spec.rb
244
- - spec/async/io/unix_endpoint_spec.rb
245
- - spec/async/io/unix_socket_spec.rb
246
- - spec/async/io/wrap/http_rb_spec.rb
247
- - spec/async/io/wrap/tcp_spec.rb
248
- - spec/spec_helper.rb
196
+ test_files: []