async-io 1.30.0 → 1.32.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23f8785195920d67cdc0497fd7cbbc4dd261a34722974eff69e49cab8a9bf070
4
- data.tar.gz: 448e9628835ce82210974bb5c7537785022261e9d5468e5e423b48a11898202f
3
+ metadata.gz: 0eedd48282062fbeed1ef84ec609fc2f380c122ebf33f9035af7a9bbe21fee5e
4
+ data.tar.gz: 83a33c4964ffd1777ca948dce4c20a3e62cc575793268e70e517f0f2858f9cdf
5
5
  SHA512:
6
- metadata.gz: dcbc8e9004a33571775ec58d946d6939ba1a1d9d296a94a1dac4a3d5cce77a2e9bea87154fffe59663f1f59bc8585ee5d3509e77f4257d3dedb7e8372af777d5
7
- data.tar.gz: c3849305261631553ebbf4a6d2e92fabdbd7ef9d0c6ae94353efd5ad20e4001d4309cc21b1570194aa0a0028e008f6fe6f8f784038adea9f41d6e050494b700c
6
+ metadata.gz: c4eb398ef67e38c31feaee2da4d7c2e9b7e8dd49350082d01615c914c2d483ab36e52d42db0b32e4a80adc5a8683e06805bc5814a4a7c9a7a60b9c4aab983522
7
+ data.tar.gz: 3dc2b05cc064e479da2528860370d51cbff0f332bdef4f3819c8b8ebf92ff59e3f04e737a371b99e74c9d324637903213d56808dab2e3fa2783061086b593a33
@@ -116,7 +116,7 @@ module Async
116
116
  end
117
117
 
118
118
  if length
119
- return "" if length <= 0
119
+ return String.new(encoding: Encoding::BINARY) if length <= 0
120
120
 
121
121
  # Fast path:
122
122
  if buffer = self.sysread(length, buffer)
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
 
@@ -72,7 +72,7 @@ module Async
72
72
 
73
73
  # Reads `size` bytes from the stream. If size is not specified, read until end of file.
74
74
  def read(size = nil)
75
- return '' if size == 0
75
+ return String.new(encoding: Encoding::BINARY) if size == 0
76
76
 
77
77
  if size
78
78
  until @eof or @read_buffer.bytesize >= size
@@ -93,7 +93,7 @@ module Async
93
93
 
94
94
  # Read at most `size` bytes from the stream. Will avoid reading from the underlying stream if possible.
95
95
  def read_partial(size = nil)
96
- return '' if size == 0
96
+ return String.new(encoding: Encoding::BINARY) if size == 0
97
97
 
98
98
  if !@eof and @read_buffer.empty?
99
99
  fill_read_buffer
@@ -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)
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Async
24
24
  module IO
25
- VERSION = "1.30.0"
25
+ VERSION = "1.32.1"
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.30.0
4
+ version: 1.32.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-06-02 00:00:00.000000000 Z
11
+ date: 2021-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -53,49 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.10'
55
55
  - !ruby/object:Gem::Dependency
56
- name: bake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
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
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: bundler
56
+ name: covered
99
57
  requirement: !ruby/object:Gem::Requirement
100
58
  requirements:
101
59
  - - ">="
@@ -109,7 +67,7 @@ dependencies:
109
67
  - !ruby/object:Gem::Version
110
68
  version: '0'
111
69
  - !ruby/object:Gem::Dependency
112
- name: covered
70
+ name: rack-test
113
71
  requirement: !ruby/object:Gem::Requirement
114
72
  requirements:
115
73
  - - ">="
@@ -128,16 +86,16 @@ dependencies:
128
86
  requirements:
129
87
  - - "~>"
130
88
  - !ruby/object:Gem::Version
131
- version: '3.0'
89
+ version: '3.6'
132
90
  type: :development
133
91
  prerelease: false
134
92
  version_requirements: !ruby/object:Gem::Requirement
135
93
  requirements:
136
94
  - - "~>"
137
95
  - !ruby/object:Gem::Version
138
- version: '3.0'
139
- description:
140
- email:
96
+ version: '3.6'
97
+ description:
98
+ email:
141
99
  executables: []
142
100
  extensions: []
143
101
  extra_rdoc_files: []
@@ -174,13 +132,13 @@ homepage: https://github.com/socketry/async-io
174
132
  licenses:
175
133
  - MIT
176
134
  metadata: {}
177
- post_install_message:
135
+ post_install_message:
178
136
  rdoc_options: []
179
137
  require_paths:
180
138
  - lib
181
139
  required_ruby_version: !ruby/object:Gem::Requirement
182
140
  requirements:
183
- - - "~>"
141
+ - - ">="
184
142
  - !ruby/object:Gem::Version
185
143
  version: '2.5'
186
144
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -190,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
148
  version: '0'
191
149
  requirements: []
192
150
  rubygems_version: 3.1.2
193
- signing_key:
151
+ signing_key:
194
152
  specification_version: 4
195
153
  summary: Provides support for asynchonous TCP, UDP, UNIX and SSL sockets.
196
154
  test_files: []