async-io 1.29.0 → 1.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/lib/async/io/host_endpoint.rb +1 -1
  3. data/lib/async/io/trap.rb +4 -3
  4. data/lib/async/io/version.rb +1 -1
  5. metadata +39 -91
  6. data/.editorconfig +0 -6
  7. data/.github/workflows/development.yml +0 -55
  8. data/.gitignore +0 -13
  9. data/.rspec +0 -3
  10. data/.yardopts +0 -2
  11. data/Gemfile +0 -13
  12. data/README.md +0 -171
  13. data/async-io.gemspec +0 -30
  14. data/examples/allocations/byteslice.rb +0 -29
  15. data/examples/allocations/memory.rb +0 -16
  16. data/examples/allocations/read_chunks.rb +0 -18
  17. data/examples/chat/client.rb +0 -58
  18. data/examples/chat/server.rb +0 -83
  19. data/examples/defer/worker.rb +0 -29
  20. data/examples/echo/client.rb +0 -23
  21. data/examples/echo/server.rb +0 -58
  22. data/examples/issues/broken_ssl.rb +0 -15
  23. data/examples/issues/pipes.rb +0 -34
  24. data/examples/millions/client.rb +0 -44
  25. data/examples/millions/server.rb +0 -41
  26. data/examples/udp/client.rb +0 -14
  27. data/examples/udp/server.rb +0 -16
  28. data/gems/nio4r-2.3.gemfile +0 -3
  29. data/spec/addrinfo.rb +0 -16
  30. data/spec/async/io/buffer_spec.rb +0 -48
  31. data/spec/async/io/c10k_spec.rb +0 -138
  32. data/spec/async/io/echo_spec.rb +0 -75
  33. data/spec/async/io/endpoint_spec.rb +0 -105
  34. data/spec/async/io/generic_examples.rb +0 -73
  35. data/spec/async/io/generic_spec.rb +0 -107
  36. data/spec/async/io/notification_spec.rb +0 -46
  37. data/spec/async/io/protocol/line_spec.rb +0 -81
  38. data/spec/async/io/shared_endpoint/server_spec.rb +0 -72
  39. data/spec/async/io/shared_endpoint_spec.rb +0 -65
  40. data/spec/async/io/socket/tcp_spec.rb +0 -101
  41. data/spec/async/io/socket/udp_spec.rb +0 -65
  42. data/spec/async/io/socket_spec.rb +0 -149
  43. data/spec/async/io/ssl_server_spec.rb +0 -133
  44. data/spec/async/io/ssl_socket_spec.rb +0 -96
  45. data/spec/async/io/standard_spec.rb +0 -47
  46. data/spec/async/io/stream_context.rb +0 -30
  47. data/spec/async/io/stream_spec.rb +0 -337
  48. data/spec/async/io/tcp_socket_spec.rb +0 -84
  49. data/spec/async/io/threads_spec.rb +0 -59
  50. data/spec/async/io/trap_spec.rb +0 -52
  51. data/spec/async/io/udp_socket_spec.rb +0 -56
  52. data/spec/async/io/unix_endpoint_spec.rb +0 -106
  53. data/spec/async/io/unix_socket_spec.rb +0 -66
  54. data/spec/async/io/wrap/http_rb_spec.rb +0 -47
  55. data/spec/async/io/wrap/tcp_spec.rb +0 -79
  56. data/spec/spec_helper.rb +0 -15
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright, 2019, 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.
22
-
23
- RSpec.shared_examples Async::IO::Generic do |ignore_methods|
24
- let(:instance_methods) {described_class.wrapped_klass.public_instance_methods(false) - (ignore_methods || [])}
25
- let(:wrapped_instance_methods) {described_class.public_instance_methods}
26
-
27
- it "should wrap a class" do
28
- expect(described_class.wrapped_klass).to_not be_nil
29
- end
30
-
31
- it "should wrap underlying instance methods" do
32
- expect(wrapped_instance_methods.sort).to include(*instance_methods.sort)
33
- end
34
-
35
- # This needs to be reviewed in more detail.
36
- #
37
- # let(:singleton_methods) {described_class.wrapped_klass.singleton_methods(false)}
38
- # let(:wrapped_singleton_methods) {described_class.singleton_methods(false)}
39
- #
40
- # it "should wrap underlying class methods" do
41
- # singleton_methods.each do |method|
42
- # expect(wrapped_singleton_methods).to include(method)
43
- # end
44
- # end
45
- end
46
-
47
- RSpec.shared_examples Async::IO do
48
- let(:data) {"Hello World!"}
49
-
50
- it "should read data" do
51
- io.write(data)
52
- expect(subject.read(data.bytesize)).to be == data
53
- end
54
-
55
- it "should read less than available data" do
56
- io.write(data)
57
- expect(subject.read(1)).to be == data[0]
58
- end
59
-
60
- it "should read all available data" do
61
- io.write(data)
62
- io.close_write
63
-
64
- expect(subject.read(data.bytesize * 2)).to be == data
65
- end
66
-
67
- it "should read all available data" do
68
- io.write(data)
69
- io.close_write
70
-
71
- expect(subject.read).to be == data
72
- end
73
- end
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
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.
22
-
23
- require 'async/io'
24
- require 'async/clock'
25
-
26
- require_relative 'generic_examples'
27
-
28
- RSpec.describe Async::IO::Generic do
29
- include_context Async::RSpec::Reactor
30
-
31
- CONSOLE_METHODS = [:beep, :cooked, :cooked!, :cursor, :cursor=, :echo=, :echo?,:getch, :getpass, :goto, :iflush, :ioflush, :noecho, :oflush,:pressed?, :raw, :raw!, :winsize, :winsize=]
32
- # On TruffleRuby, IO#encode_with needs to be defined for YAML.dump as a public method, allow it
33
- ignore = [:encode_with, :check_winsize_changed, :clear_screen, :console_mode, :console_mode=, :cursor_down, :cursor_left, :cursor_right, :cursor_up, :erase_line, :erase_screen, :goto_column, :scroll_backward, :scroll_forward]
34
-
35
- it_should_behave_like Async::IO::Generic, [
36
- :bytes, :chars, :codepoints, :each, :each_byte, :each_char, :each_codepoint, :each_line, :getbyte, :getc, :gets, :lineno, :lineno=, :lines, :print, :printf, :putc, :puts, :readbyte, :readchar, :readline, :readlines, :ungetbyte, :ungetc
37
- ] + CONSOLE_METHODS + ignore
38
-
39
- let(:message) {"Hello World!"}
40
-
41
- let(:pipe) {IO.pipe}
42
- let(:input) {Async::IO::Generic.new(pipe.first)}
43
- let(:output) {Async::IO::Generic.new(pipe.last)}
44
-
45
- it "should send and receive data within the same reactor" do
46
- received = nil
47
-
48
- output_task = reactor.async do
49
- received = input.read(1024)
50
- input.close
51
- end
52
-
53
- reactor.async do
54
- output.write(message)
55
- output.close
56
- end
57
-
58
- output_task.wait
59
- expect(received).to be == message
60
- end
61
-
62
- describe '#wait' do
63
- let(:wait_duration) {0.1}
64
-
65
- it "can wait for :read and :write" do
66
- reader = reactor.async do |task|
67
- duration = Async::Clock.measure do
68
- input.wait(1, :read)
69
- end
70
-
71
- expect(duration).to be_within(100).percent_of(wait_duration)
72
- expect(input.read(1024)).to be == message
73
-
74
- input.close
75
- end
76
-
77
- writer = reactor.async do |task|
78
- duration = Async::Clock.measure do
79
- output.wait(1, :write)
80
- end
81
-
82
- task.sleep(wait_duration)
83
-
84
- output.write(message)
85
- output.close
86
- end
87
-
88
- [reader, writer].each(&:wait)
89
- end
90
-
91
- it "can return nil when timeout is exceeded" do
92
- reader = reactor.async do |task|
93
- duration = Async::Clock.measure do
94
- expect(input.wait(wait_duration, :read)).to be_nil
95
- end
96
-
97
- expect(duration).to be_within(100).percent_of(wait_duration)
98
-
99
- input.close
100
- end
101
-
102
- [reader].each(&:wait)
103
-
104
- output.close
105
- end
106
- end
107
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
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.
22
-
23
- require 'async/io/notification'
24
-
25
- RSpec.describe Async::IO::Notification do
26
- include_context Async::RSpec::Reactor
27
-
28
- it "should wait for notification" do
29
- waiting_task = reactor.async do
30
- subject.wait
31
- end
32
-
33
- expect(waiting_task.status).to be :running
34
-
35
- signalling_task = reactor.async do
36
- subject.signal
37
- end
38
-
39
- signalling_task.wait
40
- waiting_task.wait
41
-
42
- expect(waiting_task.status).to be :complete
43
-
44
- subject.close
45
- end
46
- end
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
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.
22
-
23
- require 'async/io/protocol/line'
24
- require 'async/io/socket'
25
-
26
- RSpec.describe Async::IO::Protocol::Line do
27
- include_context Async::RSpec::Reactor
28
-
29
- let(:pipe) {@pipe = Async::IO::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)}
30
- let(:remote) {pipe.first}
31
- subject {described_class.new(Async::IO::Stream.new(pipe.last, deferred: true), "\n")}
32
-
33
- after(:each) {defined?(@pipe) && @pipe&.each(&:close)}
34
-
35
- context "default line ending" do
36
- subject {described_class.new(nil)}
37
-
38
- it "should have default eol terminator" do
39
- expect(subject.eol).to_not be_nil
40
- end
41
- end
42
-
43
- describe '#write_lines' do
44
- it "should write line" do
45
- subject.write_lines "Hello World"
46
- subject.close
47
-
48
- expect(remote.read).to be == "Hello World\n"
49
- end
50
- end
51
-
52
- describe '#read_line' do
53
- before(:each) do
54
- remote.write "Hello World\n"
55
- remote.close
56
- end
57
-
58
- it "should read one line" do
59
- expect(subject.read_line).to be == "Hello World"
60
- end
61
-
62
- it "should be binary encoding" do
63
- expect(subject.read_line.encoding).to be == Encoding::BINARY
64
- end
65
- end
66
-
67
- describe '#read_lines' do
68
- before(:each) do
69
- remote.write "Hello\nWorld\n"
70
- remote.close
71
- end
72
-
73
- it "should read multiple lines" do
74
- expect(subject.read_lines).to be == ["Hello", "World"]
75
- end
76
-
77
- it "should be binary encoding" do
78
- expect(subject.read_lines.first.encoding).to be == Encoding::BINARY
79
- end
80
- end
81
- end
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
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.
22
-
23
- require 'async/io/ssl_socket'
24
- require 'async/rspec/ssl'
25
-
26
- require 'async/io/host_endpoint'
27
- require 'async/io/shared_endpoint'
28
-
29
- require 'async/container'
30
-
31
- RSpec.shared_examples_for Async::IO::SharedEndpoint do |container_class|
32
- include_context Async::RSpec::SSL::VerifiedContexts
33
- include_context Async::RSpec::SSL::ValidCertificate
34
-
35
- let(:endpoint) {Async::IO::Endpoint.tcp("127.0.0.1", 6781, reuse_port: true)}
36
- let(:server_endpoint) {Async::IO::SSLEndpoint.new(endpoint, ssl_context: server_context)}
37
- let(:client_endpoint) {Async::IO::SSLEndpoint.new(endpoint, ssl_context: client_context)}
38
-
39
- let!(:bound_endpoint) do
40
- Async do
41
- Async::IO::SharedEndpoint.bound(server_endpoint)
42
- end.wait
43
- end
44
-
45
- let(:container) {container_class.new}
46
-
47
- it "can use bound endpoint in container" do
48
- container.async do
49
- bound_endpoint.accept do |peer|
50
- peer.write "Hello World"
51
- peer.close
52
- end
53
- end
54
-
55
- Async do
56
- client_endpoint.connect do |peer|
57
- expect(peer.read(11)).to eq "Hello World"
58
- end
59
- end
60
-
61
- container.stop
62
- bound_endpoint.close
63
- end
64
- end
65
-
66
- RSpec.describe Async::Container::Forked, if: Process.respond_to?(:fork) do
67
- it_behaves_like Async::IO::SharedEndpoint, described_class
68
- end
69
-
70
- RSpec.describe Async::Container::Threaded, if: RUBY_PLATFORM !~ /darwin/ do
71
- it_behaves_like Async::IO::SharedEndpoint, described_class
72
- end
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
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.
22
-
23
- require 'async/io/host_endpoint'
24
- require 'async/io/shared_endpoint'
25
-
26
- RSpec.describe Async::IO::SharedEndpoint do
27
- include_context Async::RSpec::Reactor
28
-
29
- describe '#bound' do
30
- let(:endpoint) {Async::IO::Endpoint.tcp("localhost", 5123, timeout: 10)}
31
-
32
- it "can bind to shared endpoint" do
33
- bound_endpoint = described_class.bound(endpoint)
34
- expect(bound_endpoint.wrappers).to_not be_empty
35
-
36
- wrapper = bound_endpoint.wrappers.first
37
- expect(wrapper).to be_a Async::IO::Socket
38
- expect(wrapper.timeout).to be == endpoint.timeout
39
-
40
- bound_endpoint.close
41
- end
42
- end
43
-
44
- describe '#connected' do
45
- let(:endpoint) {Async::IO::Endpoint.tcp("localhost", 5124, timeout: 10)}
46
-
47
- it "can connect to shared endpoint" do
48
- server_task = reactor.async do
49
- endpoint.accept do |io|
50
- io.close
51
- end
52
- end
53
-
54
- connected_endpoint = described_class.connected(endpoint)
55
- expect(connected_endpoint.wrappers).to_not be_empty
56
-
57
- wrapper = connected_endpoint.wrappers.first
58
- expect(wrapper).to be_a Async::IO::Socket
59
- expect(wrapper.timeout).to be == endpoint.timeout
60
-
61
- connected_endpoint.close
62
- server_task.stop
63
- end
64
- end
65
- end