async-io 1.24.0 → 1.25.0

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: c0614be3c203f3e9b8de82215fdacbe3a9bccdcd9b82784af349aa3149d63419
4
- data.tar.gz: da66baf1cea7ee3ba1411eee6c09a7eeef5faef39e40ce6459fcd8002df2437b
3
+ metadata.gz: 8e01be4ac327bd569ca94ab2dee892e146d09dcba53d07602b01b77362c2601d
4
+ data.tar.gz: cef6ce9421a1f1d8ce9848390e998c251d2972de5915ed47459f8c5352620aca
5
5
  SHA512:
6
- metadata.gz: 3624d5fe1177e65b87cb75fdec5eaeac9ef25543d423a66333c6de3b2826f656d0e7acdf5742741b2a7744518baa482f987584829aa6f2ebf140339161bf13be
7
- data.tar.gz: d12bdfe724ba95f6f39cbc68bf21b7df0c16537f1c5dd689e70f102609ce6c75502d2cc41478546c9704d42bfdcdafbdc9e63a5cc5cc300ccf08610d4c533f96
6
+ metadata.gz: d3d5506e50c9d3ea3259a87a90943565071317f11d277b08608bbfc35ce5b85441e0521950716cd37f20d56a2591544a376624e9bf8d029c338ce748ecef6c9b
7
+ data.tar.gz: 45114022177aba3e1caf2680cb49754b1ad511487a4327f66851c30fca4a832255545169c275c1dd387aff6c7c241a3286a5241f77de6d4c89b759fc50ec264e
@@ -14,6 +14,11 @@ matrix:
14
14
  - rvm: jruby-head
15
15
  env: JRUBY_OPTS="--debug -X+O"
16
16
  - rvm: ruby-head
17
+ - rvm: 2.6
18
+ os: osx
19
+ - rvm: 2.6
20
+ os: osx
21
+ gemfile: gems/nio4r-2.3.gemfile
17
22
  allow_failures:
18
23
  - rvm: ruby-head
19
24
  - rvm: truffleruby
@@ -18,7 +18,7 @@ class Server
18
18
  task.async do |subtask|
19
19
  while true
20
20
  subtask.sleep 10
21
- puts "Connection count: #{@connections.count}"
21
+ puts "Connection count: #{@connections.size}"
22
22
  end
23
23
  end
24
24
 
@@ -0,0 +1,3 @@
1
+ eval_gemfile("../Gemfile")
2
+
3
+ gem "nio4r", "~> 2.3.0"
@@ -38,6 +38,10 @@ module Async
38
38
  end
39
39
  end
40
40
 
41
+ def self.pipe
42
+ ::IO.pipe.map(&Generic.method(:new))
43
+ end
44
+
41
45
  # Represents an asynchronous IO within a reactor.
42
46
  class Generic < Wrapper
43
47
  extend Forwardable
@@ -86,7 +86,7 @@ module Async
86
86
  peer = peer.dup
87
87
 
88
88
  task.async do |task|
89
- task.annotate "connected to #{peer.inspect}"
89
+ task.annotate "connected to #{peer.inspect} [#{peer.fileno}]"
90
90
 
91
91
  begin
92
92
  yield peer, task
@@ -104,7 +104,7 @@ module Async
104
104
  end
105
105
 
106
106
  def to_s
107
- "\#<#{self.class} #{@wrappers.count} descriptors for #{@endpoint}>"
107
+ "\#<#{self.class} #{@wrappers.size} descriptors for #{@endpoint}>"
108
108
  end
109
109
  end
110
110
  end
@@ -93,7 +93,7 @@ module Async
93
93
 
94
94
  module Server
95
95
  def accept_each(timeout: nil, task: Task.current)
96
- task.annotate "accepting connections #{self.local_address.inspect}"
96
+ task.annotate "accepting connections #{self.local_address.inspect} [fd=#{self.fileno}]"
97
97
 
98
98
  callback = lambda do |io, address|
99
99
  yield io, address, task: task
@@ -131,7 +131,7 @@ module Async
131
131
  return wrapper, address unless block_given?
132
132
 
133
133
  task.async do |task|
134
- task.annotate "incoming connection #{address.inspect}"
134
+ task.annotate "incoming connection #{address.inspect} [fd=#{wrapper.fileno}]"
135
135
 
136
136
  begin
137
137
  yield wrapper, address
@@ -197,7 +197,7 @@ module Async
197
197
 
198
198
  begin
199
199
  wrapper.connect(remote_address.to_sockaddr)
200
- task.annotate "connected to #{remote_address.inspect}"
200
+ task.annotate "connected to #{remote_address.inspect} [fd=#{wrapper.fileno}]"
201
201
  rescue Exception
202
202
  wrapper.close
203
203
  raise
@@ -111,6 +111,10 @@ module Async
111
111
  @context = context
112
112
  end
113
113
 
114
+ def fileno
115
+ @server.fileno
116
+ end
117
+
114
118
  def dup
115
119
  self.class.new(@server.dup, @context)
116
120
  end
@@ -82,13 +82,9 @@ module Async
82
82
  # Read at most `size` bytes from the stream. Will avoid reading from the underlying stream if possible.
83
83
  def read_partial(size = nil)
84
84
  return '' if size == 0
85
-
86
- unless @eof
87
- if size and @read_buffer.bytesize < size
88
- fill_read_buffer(size > @block_size ? size : @block_size)
89
- elsif @read_buffer.empty?
90
- fill_read_buffer
91
- end
85
+
86
+ if !@eof and @read_buffer.empty?
87
+ fill_read_buffer
92
88
  end
93
89
 
94
90
  return consume_read_buffer(size)
@@ -215,9 +211,13 @@ module Async
215
211
 
216
212
  # Returns true if the stream is at file which means there is no more data to be read.
217
213
  def eof?
218
- fill_read_buffer if !@eof && @read_buffer.empty?
214
+ return false unless @read_buffer.empty?
215
+
216
+ if !@eof
217
+ fill_read_buffer
218
+ end
219
219
 
220
- return @eof && @read_buffer.empty?
220
+ return @eof
221
221
  end
222
222
 
223
223
  alias eof eof?
@@ -238,16 +238,20 @@ module Async
238
238
  size = @maximum_read_size
239
239
  end
240
240
 
241
- if @read_buffer.empty? and @io.read_nonblock(size, @read_buffer, exception: false)
242
- return true
243
- elsif chunk = @io.read_nonblock(size, @input_buffer, exception: false)
244
- @read_buffer << chunk
245
- return true
241
+ if @read_buffer.empty?
242
+ if @io.read_nonblock(size, @read_buffer, exception: false)
243
+ return true
244
+ end
246
245
  else
247
- # We didn't read anything, so we must be at eof:
248
- @eof = true
249
- return false
246
+ if chunk = @io.read_nonblock(size, @input_buffer, exception: false)
247
+ @read_buffer << chunk
248
+ return true
249
+ end
250
250
  end
251
+
252
+ # else for both cases above:
253
+ @eof = true
254
+ return false
251
255
  end
252
256
 
253
257
  # Consumes at most `size` bytes from the buffer.
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module IO
23
- VERSION = "1.24.0"
23
+ VERSION = "1.25.0"
24
24
  end
25
25
  end
@@ -51,13 +51,13 @@ RSpec.describe "echo client/server", if: Process.respond_to?(:fork) do
51
51
  Async::IO::Socket.bind(server_address) do |server|
52
52
  server.listen(Socket::SOMAXCONN)
53
53
 
54
- while connections.count < repeats
54
+ while connections.size < repeats
55
55
  peer, address = server.accept
56
56
  connections << peer
57
57
  end
58
58
  end.wait
59
59
 
60
- puts "Releasing #{connections.count} connections..."
60
+ puts "Releasing #{connections.size} connections..."
61
61
 
62
62
  while connection = connections.pop
63
63
  connection.write(".")
@@ -124,7 +124,7 @@ RSpec.describe "echo client/server", if: Process.respond_to?(:fork) do
124
124
 
125
125
  tasks.each(&:wait)
126
126
 
127
- expect(responses.count).to be repeats
127
+ expect(responses.size).to be repeats
128
128
  end
129
129
 
130
130
  # ensure
@@ -68,6 +68,6 @@ RSpec.describe "echo client/server" do
68
68
  tasks.each(&:wait)
69
69
  server.stop
70
70
 
71
- expect(responses.count).to be repeats
71
+ expect(responses.size).to be repeats
72
72
  end
73
73
  end
@@ -68,4 +68,4 @@ RSpec.shared_examples Async::IO do
68
68
 
69
69
  expect(subject.read).to be == data
70
70
  end
71
- end
71
+ end
@@ -66,7 +66,7 @@ RSpec.describe Async::IO::Generic do
66
66
  input.wait(1, :read)
67
67
  end
68
68
 
69
- expect(duration).to be_within(50).percent_of(wait_duration)
69
+ expect(duration).to be_within(100).percent_of(wait_duration)
70
70
  expect(input.read(1024)).to be == message
71
71
 
72
72
  input.close
@@ -92,7 +92,7 @@ RSpec.describe Async::IO::Generic do
92
92
  expect(input.wait(wait_duration, :read)).to be_nil
93
93
  end
94
94
 
95
- expect(duration).to be_within(50).percent_of(wait_duration)
95
+ expect(duration).to be_within(100).percent_of(wait_duration)
96
96
 
97
97
  input.close
98
98
  end
@@ -19,6 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require 'async/io/ssl_socket'
22
+ require 'async/io/ssl_endpoint'
22
23
 
23
24
  require 'async/rspec/ssl'
24
25
  require_relative 'generic_examples'
@@ -98,7 +98,7 @@ RSpec.describe Async::IO::Stream do
98
98
  data = nil
99
99
 
100
100
  duration = Async::Clock.measure do
101
- data = stream.read(4*1024**3)
101
+ data = stream.read(1024**3)
102
102
  end
103
103
 
104
104
  size = data.bytesize / 1024**2
@@ -106,7 +106,7 @@ RSpec.describe Async::IO::Stream do
106
106
 
107
107
  example.reporter.message "Read #{size.round(2)}MB of data at #{rate.round(2)}MB/s."
108
108
 
109
- expect(rate).to be > 512
109
+ expect(rate).to be > 128
110
110
  end
111
111
  end
112
112
 
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.24.0
4
+ version: 1.25.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: 2019-07-13 00:00:00.000000000 Z
11
+ date: 2019-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -135,6 +135,7 @@ files:
135
135
  - examples/millions/server.rb
136
136
  - examples/udp/client.rb
137
137
  - examples/udp/server.rb
138
+ - gems/nio4r-2.3.gemfile
138
139
  - lib/async/io.rb
139
140
  - lib/async/io/address.rb
140
141
  - lib/async/io/address_endpoint.rb