async-io 1.28.0 → 1.31.0

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/lib/async/io/host_endpoint.rb +1 -1
  3. data/lib/async/io/peer.rb +2 -2
  4. data/lib/async/io/socket.rb +2 -2
  5. data/lib/async/io/ssl_socket.rb +2 -4
  6. data/lib/async/io/stream.rb +2 -2
  7. data/lib/async/io/tcp_socket.rb +1 -1
  8. data/{spec/async/io/socket/udp_spec.rb → lib/async/io/threads.rb} +56 -36
  9. data/lib/async/io/trap.rb +8 -3
  10. data/lib/async/io/version.rb +1 -1
  11. metadata +45 -94
  12. data/.editorconfig +0 -6
  13. data/.gitignore +0 -13
  14. data/.rspec +0 -3
  15. data/.travis.yml +0 -26
  16. data/.yardopts +0 -2
  17. data/Gemfile +0 -13
  18. data/README.md +0 -171
  19. data/async-io.gemspec +0 -30
  20. data/examples/allocations/byteslice.rb +0 -29
  21. data/examples/allocations/memory.rb +0 -16
  22. data/examples/allocations/read_chunks.rb +0 -18
  23. data/examples/chat/client.rb +0 -58
  24. data/examples/chat/server.rb +0 -83
  25. data/examples/defer/worker.rb +0 -29
  26. data/examples/echo/client.rb +0 -23
  27. data/examples/echo/server.rb +0 -58
  28. data/examples/issues/broken_ssl.rb +0 -15
  29. data/examples/issues/pipes.rb +0 -34
  30. data/examples/millions/client.rb +0 -44
  31. data/examples/millions/server.rb +0 -41
  32. data/examples/udp/client.rb +0 -14
  33. data/examples/udp/server.rb +0 -16
  34. data/gems/nio4r-2.3.gemfile +0 -3
  35. data/spec/addrinfo.rb +0 -16
  36. data/spec/async/io/buffer_spec.rb +0 -48
  37. data/spec/async/io/c10k_spec.rb +0 -138
  38. data/spec/async/io/echo_spec.rb +0 -75
  39. data/spec/async/io/endpoint_spec.rb +0 -105
  40. data/spec/async/io/generic_examples.rb +0 -73
  41. data/spec/async/io/generic_spec.rb +0 -107
  42. data/spec/async/io/notification_spec.rb +0 -46
  43. data/spec/async/io/protocol/line_spec.rb +0 -81
  44. data/spec/async/io/shared_endpoint/server_spec.rb +0 -72
  45. data/spec/async/io/shared_endpoint_spec.rb +0 -65
  46. data/spec/async/io/socket/tcp_spec.rb +0 -101
  47. data/spec/async/io/socket_spec.rb +0 -149
  48. data/spec/async/io/ssl_server_spec.rb +0 -133
  49. data/spec/async/io/ssl_socket_spec.rb +0 -96
  50. data/spec/async/io/standard_spec.rb +0 -47
  51. data/spec/async/io/stream_context.rb +0 -30
  52. data/spec/async/io/stream_spec.rb +0 -337
  53. data/spec/async/io/tcp_socket_spec.rb +0 -84
  54. data/spec/async/io/trap_spec.rb +0 -52
  55. data/spec/async/io/udp_socket_spec.rb +0 -56
  56. data/spec/async/io/unix_endpoint_spec.rb +0 -106
  57. data/spec/async/io/unix_socket_spec.rb +0 -66
  58. data/spec/async/io/wrap/http_rb_spec.rb +0 -47
  59. data/spec/async/io/wrap/tcp_spec.rb +0 -79
  60. data/spec/spec_helper.rb +0 -15
@@ -1,75 +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
-
25
- RSpec.describe "echo client/server" do
26
- include_context Async::RSpec::Reactor
27
-
28
- let(:server_address) {Async::IO::Address.tcp('0.0.0.0', 9002)}
29
-
30
- def echo_server(server_address)
31
- Async do |task|
32
- # This is a synchronous block within the current task:
33
- Async::IO::Socket.accept(server_address) do |client|
34
- # This is an asynchronous block within the current reactor:
35
- data = client.read(512)
36
-
37
- # This produces out-of-order responses.
38
- task.sleep(rand * 0.01)
39
-
40
- client.write(data)
41
- end
42
- end
43
- end
44
-
45
- def echo_client(server_address, data, responses)
46
- Async do |task|
47
- Async::IO::Socket.connect(server_address) do |peer|
48
- result = peer.write(data)
49
- peer.close_write
50
-
51
- message = peer.read(data.bytesize)
52
-
53
- responses << message
54
- end
55
- end
56
- end
57
-
58
- let(:repeats) {10}
59
-
60
- it "should echo several messages" do
61
- server = echo_server(server_address)
62
- responses = []
63
-
64
- tasks = repeats.times.collect do |i|
65
- echo_client(server_address, "Hello World #{i}", responses)
66
- end
67
-
68
- # task.reactor.print_hierarchy
69
-
70
- tasks.each(&:wait)
71
- server.stop
72
-
73
- expect(responses.size).to be repeats
74
- end
75
- end
@@ -1,105 +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/endpoint'
24
-
25
- require 'async/io/tcp_socket'
26
- require 'async/io/socket_endpoint'
27
- require 'async/io/ssl_endpoint'
28
-
29
- RSpec.describe Async::IO::Endpoint do
30
- include_context Async::RSpec::Reactor
31
-
32
- describe Async::IO::Endpoint.ssl('0.0.0.0', 5234, hostname: "lolcathost") do
33
- it "should have hostname" do
34
- expect(subject.hostname).to be == "lolcathost"
35
- end
36
-
37
- it "shouldn't have a timeout duration" do
38
- expect(subject.timeout).to be_nil
39
- end
40
- end
41
-
42
- describe Async::IO::Endpoint.tcp('0.0.0.0', 5234, reuse_port: true, timeout: 10) do
43
- it "should be a tcp binding" do
44
- subject.bind do |server|
45
- expect(server.local_address.socktype).to be == ::Socket::SOCK_STREAM
46
- end
47
- end
48
-
49
- it "should have a timeout duration" do
50
- expect(subject.timeout).to be 10
51
- end
52
-
53
- it "should print nicely" do
54
- expect(subject.to_s).to include('0.0.0.0', '5234')
55
- end
56
-
57
- it "has options" do
58
- expect(subject.options[:reuse_port]).to be true
59
- end
60
-
61
- it "has hostname" do
62
- expect(subject.hostname).to be == '0.0.0.0'
63
- end
64
-
65
- it "has local address" do
66
- address = Async::IO::Address.tcp('127.0.0.1', 8080)
67
- expect(subject.with(local_address: address).local_address).to be == address
68
- end
69
-
70
- let(:message) {"Hello World!"}
71
-
72
- it "can connect to bound server" do
73
- server_task = reactor.async do
74
- subject.accept do |io|
75
- expect(io.timeout).to be == 10
76
- io.write message
77
- io.close
78
- end
79
- end
80
-
81
- io = subject.connect
82
- expect(io.timeout).to be == 10
83
- expect(io.read(message.bytesize)).to be == message
84
- io.close
85
-
86
- server_task.stop
87
- end
88
- end
89
-
90
- describe Async::IO::Endpoint.tcp('0.0.0.0', 0) do
91
- it "should be a tcp binding" do
92
- subject.bind do |server|
93
- expect(server.local_address.ip_port).to be > 10000
94
- end
95
- end
96
- end
97
-
98
- describe Async::IO::SocketEndpoint.new(TCPServer.new('0.0.0.0', 1234)) do
99
- it "should bind to given socket" do
100
- subject.bind do |server|
101
- expect(server).to be == subject.socket
102
- end
103
- end
104
- end
105
- end
@@ -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