async-io 1.30.1 → 1.43.2

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.
@@ -1,27 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2017-2024, by Samuel Williams.
22
5
 
23
6
  module Async
24
7
  module IO
25
- VERSION = "1.30.1"
8
+ VERSION = "1.43.2"
26
9
  end
27
10
  end
data/lib/async/io.rb CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2017-2024, by Samuel Williams.
22
5
 
23
6
  require 'async'
24
7
 
@@ -28,11 +11,16 @@ require_relative "io/version"
28
11
 
29
12
  require_relative "io/endpoint"
30
13
  require_relative "io/endpoint/each"
14
+ require_relative "io/shared_endpoint"
31
15
 
32
16
  module Async
33
17
  module IO
34
18
  def self.file_descriptor_limit
35
19
  Process.getrlimit(Process::RLIMIT_NOFILE).first
36
20
  end
21
+
22
+ def self.buffer?
23
+ ::IO.const_defined?(:Buffer)
24
+ end
37
25
  end
38
26
  end
data/license.md ADDED
@@ -0,0 +1,33 @@
1
+ # MIT License
2
+
3
+ Copyright, 2017-2024, by Samuel Williams.
4
+ Copyright, 2017-2023, by Olle Jonsson.
5
+ Copyright, 2018, by Janko Marohnić.
6
+ Copyright, 2018, by Jiang Jinyang.
7
+ Copyright, 2018, by Thibaut Girka.
8
+ Copyright, 2019-2020, by Benoit Daloze.
9
+ Copyright, 2020, by Cyril Roelandt.
10
+ Copyright, 2020, by Bruno Sutic.
11
+ Copyright, 2021, by Aurora Nockert.
12
+ Copyright, 2022-2023, by Hal Brodigan.
13
+ Copyright, 2023, by Hasan Kumar.
14
+ Copyright, 2023, by Maruth Goyal.
15
+ Copyright, 2023, by Patrik Wenger.
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ of this software and associated documentation files (the "Software"), to deal
19
+ in the Software without restriction, including without limitation the rights
20
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ copies of the Software, and to permit persons to whom the Software is
22
+ furnished to do so, subject to the following conditions:
23
+
24
+ The above copyright notice and this permission notice shall be included in all
25
+ copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,152 @@
1
+ # Async::IO
2
+
3
+ Async::IO provides builds on [async](https://github.com/socketry/async) and provides asynchronous wrappers for `IO`, `Socket`, and related classes.
4
+
5
+ [![Development Status](https://github.com/socketry/async-io/workflows/Test/badge.svg)](https://github.com/socketry/async-io/actions?workflow=Test)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ``` ruby
12
+ gem 'async-io'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install async-io
22
+
23
+ ## Usage
24
+
25
+ Basic echo server (from `spec/async/io/echo_spec.rb`):
26
+
27
+ ``` ruby
28
+ require 'async/io'
29
+
30
+ def echo_server(endpoint)
31
+ Async do |task|
32
+ # This is a synchronous block within the current task:
33
+ endpoint.accept do |client|
34
+ # This is an asynchronous block within the current reactor:
35
+ data = client.read
36
+
37
+ # This produces out-of-order responses.
38
+ task.sleep(rand * 0.01)
39
+
40
+ client.write(data.reverse)
41
+ client.close_write
42
+ end
43
+ end
44
+ end
45
+
46
+ def echo_client(endpoint, data)
47
+ Async do |task|
48
+ endpoint.connect do |peer|
49
+ peer.write(data)
50
+ peer.close_write
51
+
52
+ message = peer.read
53
+
54
+ puts "Sent #{data}, got response: #{message}"
55
+ end
56
+ end
57
+ end
58
+
59
+ Async do
60
+ endpoint = Async::IO::Endpoint.tcp('0.0.0.0', 9000)
61
+
62
+ server = echo_server(endpoint)
63
+
64
+ 5.times.map do |i|
65
+ echo_client(endpoint, "Hello World #{i}")
66
+ end.each(&:wait)
67
+
68
+ server.stop
69
+ end
70
+ ```
71
+
72
+ ### Timeouts
73
+
74
+ Timeouts add a temporal limit to the execution of your code. If the IO doesn't respond in time, it will fail. Timeouts are high level concerns and you generally shouldn't use them except at the very highest level of your program.
75
+
76
+ ``` ruby
77
+ message = task.with_timeout(5) do
78
+ begin
79
+ peer.read
80
+ rescue Async::TimeoutError
81
+ nil # The timeout was triggered.
82
+ end
83
+ end
84
+ ```
85
+
86
+ Any `yield` operation can cause a timeout to trigger. Non-`async` functions might not timeout because they are outside the scope of `async`.
87
+
88
+ #### Wrapper Timeouts
89
+
90
+ Asynchronous operations may block forever. You can assign a per-wrapper operation timeout duration. All asynchronous operations will be bounded by this timeout.
91
+
92
+ ``` ruby
93
+ peer.timeout = 1
94
+ peer.read # If this takes more than 1 second, Async::TimeoutError will be raised.
95
+ ```
96
+
97
+ The benefit of this approach is that it applies to all operations. Typically, this would be configured by the user, and set to something pretty high, e.g. 120 seconds.
98
+
99
+ ### Reading Characters
100
+
101
+ This example shows how to read one character at a time as the user presses it on the keyboard, and echos it back out as uppercase:
102
+
103
+ ``` ruby
104
+ require 'async'
105
+ require 'async/io/stream'
106
+ require 'io/console'
107
+
108
+ $stdin.raw!
109
+ $stdin.echo = false
110
+
111
+ Async do |task|
112
+ stdin = Async::IO::Stream.new(
113
+ Async::IO::Generic.new($stdin)
114
+ )
115
+
116
+ while character = stdin.read(1)
117
+ $stdout.write character.upcase
118
+ end
119
+ end
120
+ ```
121
+
122
+ ### Deferred Buffering
123
+
124
+ `Async::IO::Stream.new(..., deferred:true)` creates a deferred stream which increases latency slightly, but reduces the number of total packets sent. It does this by combining all calls `Stream#flush` within a single iteration of the reactor. This is typically more useful on the client side, but can also be useful on the server side when individual packets have high latency. It should be preferable to send one 100 byte packet than 10x 10 byte packets.
125
+
126
+ Servers typically only deal with one request per iteartion of the reactor so it's less useful. Clients which make multiple requests can benefit significantly e.g. HTTP/2 clients can merge many requests into a single packet. Because HTTP/2 recommends disabling Nagle's algorithm, this is often beneficial.
127
+
128
+ ## Contributing
129
+
130
+ We welcome contributions to this project.
131
+
132
+ 1. Fork it.
133
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
134
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
135
+ 4. Push to the branch (`git push origin my-new-feature`).
136
+ 5. Create new Pull Request.
137
+
138
+ ### Developer Certificate of Origin
139
+
140
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
141
+
142
+ ### Contributor Covenant
143
+
144
+ This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
145
+
146
+ ## See Also
147
+
148
+ - [async](https://github.com/socketry/async) — Asynchronous event-driven reactor.
149
+ - [async-process](https://github.com/socketry/async-process) — Asynchronous process spawning/waiting.
150
+ - [async-websocket](https://github.com/socketry/async-websocket) — Asynchronous client and server websockets.
151
+ - [async-dns](https://github.com/socketry/async-dns) — Asynchronous DNS resolver and server.
152
+ - [async-rspec](https://github.com/socketry/async-rspec) — Shared contexts for running async specs.
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,141 +1,70 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.30.1
4
+ version: 1.43.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Olle Jonsson
9
+ - Benoit Daloze
10
+ - Thibaut Girka
11
+ - Hal Brodigan
12
+ - Janko Marohnić
13
+ - Aurora Nockert
14
+ - Bruno Sutic
15
+ - Cyril Roelandt
16
+ - Hasan Kumar
17
+ - Jiang Jinyang
18
+ - Maruth Goyal
19
+ - Patrik Wenger
8
20
  autorequire:
9
21
  bindir: bin
10
- cert_chain: []
11
- date: 2020-09-18 00:00:00.000000000 Z
22
+ cert_chain:
23
+ - |
24
+ -----BEGIN CERTIFICATE-----
25
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
26
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
27
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
28
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
29
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
30
+ bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
31
+ igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
32
+ 9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
33
+ sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
34
+ e5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qG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
50
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
51
+ -----END CERTIFICATE-----
52
+ date: 2024-04-23 00:00:00.000000000 Z
12
53
  dependencies:
13
54
  - !ruby/object:Gem::Dependency
14
55
  name: async
15
56
  requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.14'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
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'
41
- - !ruby/object:Gem::Dependency
42
- name: async-rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.10'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.10'
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
57
  requirements:
80
58
  - - ">="
81
59
  - !ruby/object:Gem::Version
82
60
  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
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: covered
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
61
+ type: :runtime
119
62
  prerelease: false
120
63
  version_requirements: !ruby/object:Gem::Requirement
121
64
  requirements:
122
65
  - - ">="
123
66
  - !ruby/object:Gem::Version
124
67
  version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: rspec
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '3.0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '3.0'
139
68
  description:
140
69
  email:
141
70
  executables: []
@@ -147,6 +76,7 @@ files:
147
76
  - lib/async/io/address_endpoint.rb
148
77
  - lib/async/io/binary_string.rb
149
78
  - lib/async/io/buffer.rb
79
+ - lib/async/io/composite_endpoint.rb
150
80
  - lib/async/io/endpoint.rb
151
81
  - lib/async/io/endpoint/each.rb
152
82
  - lib/async/io/generic.rb
@@ -170,10 +100,14 @@ files:
170
100
  - lib/async/io/unix_endpoint.rb
171
101
  - lib/async/io/unix_socket.rb
172
102
  - lib/async/io/version.rb
103
+ - license.md
104
+ - readme.md
173
105
  homepage: https://github.com/socketry/async-io
174
106
  licenses:
175
107
  - MIT
176
- metadata: {}
108
+ metadata:
109
+ documentation_uri: https://socketry.github.io/async-io/
110
+ source_code_uri: https://github.com/socketry/async-io.git
177
111
  post_install_message:
178
112
  rdoc_options: []
179
113
  require_paths:
@@ -189,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
123
  - !ruby/object:Gem::Version
190
124
  version: '0'
191
125
  requirements: []
192
- rubygems_version: 3.1.2
126
+ rubygems_version: 3.5.3
193
127
  signing_key:
194
128
  specification_version: 4
195
129
  summary: Provides support for asynchonous TCP, UDP, UNIX and SSL sockets.
metadata.gz.sig ADDED
Binary file