async-io 1.16.3 → 1.16.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 847e84fe9fda1ce17c764e6ae69db03ff9afea9bb6edd6a915840ba3cf123a3d
4
- data.tar.gz: 66efd170f4ef6f322f68cce22f362063b2b746a7fb283aa9fd84656ec62ab19d
3
+ metadata.gz: 964165da2ad0d5d46442afadfd7afda4d3ddc675cacaafdd73c3a411cee3d4b7
4
+ data.tar.gz: caece9fc620704475055cdc5df52748b2610c8880af5a4dd803161f16e4df9ef
5
5
  SHA512:
6
- metadata.gz: 43efad41877e3df3b846deddd7e5bf16248faec868796f41517b11ec0810d5d277ff3b370a6aae13252f8da0fc3ada9b2d2909d2ba60610d49c0a3bf7b331117
7
- data.tar.gz: fe90898d2ea0897f13c6456c2bb9d11dd6abc37b66355f63633d1c0294be25fcb4222b559dc709d0a8daef77f1f3e36ac714e66a14f7afe9fae35e3de5e3d8c4
6
+ metadata.gz: 4a0b330d6eec4f7354e1fd3d0aeba0ebb3711905bb47a0353ab8fc683261bb923508ad21eae9822ac8acc80a853877dbdeee0f11865240bb965e6dea724a87b1
7
+ data.tar.gz: efa6e3c135f4030bb8adafc298de93134bc9cad5ea6a58657657903bbce75b3c62904667c98c49ebb982dc7ac8977a368e8d55fad98a8b6a2f40ccf4136d7823
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.expand_path("../../lib", __dir__)
4
+
5
+ require 'async/reactor'
6
+ require 'async/io/host_endpoint'
7
+
8
+ require 'async/container'
9
+ require 'async/container/forked'
10
+
11
+ endpoint = Async::IO::Endpoint.parse(ARGV.pop || "tcp://localhost:7234")
12
+
13
+ CONNECTIONS = 1_000_000
14
+
15
+ CONCURRENCY = Async::Container.hardware_concurrency
16
+ TASKS = 16
17
+ REPEATS = (CONNECTIONS.to_f / (TASKS * CONCURRENCY)).ceil
18
+
19
+ puts "Starting #{CONCURRENCY} processes, running #{TASKS} tasks, making #{REPEATS} connections."
20
+ puts "Total number of connections: #{CONCURRENCY * TASKS * REPEATS}!"
21
+
22
+ begin
23
+ container = Async::Container::Forked.new(concurrency: CONCURRENCY) do
24
+ Async::Reactor.run do |task|
25
+ connections = []
26
+
27
+ TASKS.times do
28
+ task.async do
29
+ REPEATS.times do
30
+ $stdout.write "."
31
+ connections << endpoint.connect
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ container.wait
39
+ ensure
40
+ container.stop if container
41
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.expand_path("../../lib", __dir__)
4
+
5
+ require 'set'
6
+
7
+ require 'async/reactor'
8
+ require 'async/io/host_endpoint'
9
+ require 'async/io/protocol/line'
10
+
11
+ class Server
12
+ def initialize
13
+ @connections = []
14
+ end
15
+
16
+ def run(endpoint)
17
+ Async::Reactor.run do |task|
18
+ task.async do |subtask|
19
+ while true
20
+ subtask.sleep 10
21
+ puts "Connection count: #{@connections.count}"
22
+ end
23
+ end
24
+
25
+
26
+ endpoint.accept do |peer|
27
+ stream = Async::IO::Stream.new(peer)
28
+
29
+ @connections << stream
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ Async.logger.level = Logger::INFO
36
+ Async.logger.info("Starting server...")
37
+ server = Server.new
38
+
39
+ endpoint = Async::IO::Endpoint.parse(ARGV.pop || "tcp://localhost:7234")
40
+ server.run(endpoint)
@@ -128,13 +128,16 @@ module Async
128
128
  # @param remote_address [Addrinfo] The remote address to connect to.
129
129
  # @param local_address [Addrinfo] The local address to bind to before connecting.
130
130
  # @option protcol [Integer] The socket protocol to use.
131
- def self.connect(remote_address, local_address = nil, reuse_port: false, task: Task.current, **options)
131
+ def self.connect(remote_address, local_address = nil, reuse_port: nil, task: Task.current, **options)
132
132
  Async.logger.debug(self) {"Connecting to #{remote_address.inspect}"}
133
133
 
134
134
  task.annotate "connecting to #{remote_address.inspect}"
135
135
 
136
136
  wrapper = build(remote_address.afamily, remote_address.socktype, remote_address.protocol, **options) do |socket|
137
- socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, reuse_port)
137
+
138
+ if reuse_port
139
+ socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, 1)
140
+ end
138
141
 
139
142
  if local_address
140
143
  socket.bind(local_address.to_sockaddr)
@@ -166,12 +169,19 @@ module Async
166
169
  # @param local_address [Address] The local address to bind to.
167
170
  # @option protocol [Integer] The socket protocol to use.
168
171
  # @option reuse_port [Boolean] Allow this port to be bound in multiple processes.
169
- def self.bind(local_address, protocol: 0, reuse_port: false, task: Task.current, **options, &block)
172
+ def self.bind(local_address, protocol: 0, reuse_port: nil, reuse_address: true, task: Task.current, **options, &block)
170
173
  Async.logger.debug(self) {"Binding to #{local_address.inspect}"}
171
174
 
172
175
  wrapper = build(local_address.afamily, local_address.socktype, protocol, **options) do |socket|
173
- socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, true)
174
- socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEPORT, true) if reuse_port
176
+
177
+ if reuse_address
178
+ socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, 1)
179
+ end
180
+
181
+ if reuse_port
182
+ socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEPORT, 1)
183
+ end
184
+
175
185
  socket.bind(local_address.to_sockaddr)
176
186
  end
177
187
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module IO
23
- VERSION = "1.16.3"
23
+ VERSION = "1.16.4"
24
24
  end
25
25
  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.16.3
4
+ version: 1.16.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-02 00:00:00.000000000 Z
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -101,6 +101,8 @@ files:
101
101
  - examples/chat/client.rb
102
102
  - examples/chat/server.rb
103
103
  - examples/issues/broken_ssl.rb
104
+ - examples/millions/client.rb
105
+ - examples/millions/server.rb
104
106
  - lib/async/io.rb
105
107
  - lib/async/io/address.rb
106
108
  - lib/async/io/address_endpoint.rb