cool.io 1.4.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +29 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +13 -0
  5. data/CHANGES.md +229 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +20 -0
  8. data/README.md +166 -0
  9. data/Rakefile +79 -0
  10. data/cool.io.gemspec +29 -0
  11. data/examples/callbacked_echo_server.rb +24 -0
  12. data/examples/dslified_echo_client.rb +34 -0
  13. data/examples/dslified_echo_server.rb +24 -0
  14. data/examples/echo_client.rb +38 -0
  15. data/examples/echo_server.rb +27 -0
  16. data/examples/google.rb +9 -0
  17. data/ext/cool.io/.gitignore +5 -0
  18. data/ext/cool.io/cool.io.h +59 -0
  19. data/ext/cool.io/cool.io_ext.c +25 -0
  20. data/ext/cool.io/ev_wrap.h +10 -0
  21. data/ext/cool.io/extconf.rb +61 -0
  22. data/ext/cool.io/iowatcher.c +189 -0
  23. data/ext/cool.io/libev.c +8 -0
  24. data/ext/cool.io/loop.c +261 -0
  25. data/ext/cool.io/stat_watcher.c +269 -0
  26. data/ext/cool.io/timer_watcher.c +219 -0
  27. data/ext/cool.io/utils.c +122 -0
  28. data/ext/cool.io/watcher.c +264 -0
  29. data/ext/cool.io/watcher.h +71 -0
  30. data/ext/iobuffer/extconf.rb +9 -0
  31. data/ext/iobuffer/iobuffer.c +767 -0
  32. data/ext/libev/Changes +507 -0
  33. data/ext/libev/LICENSE +37 -0
  34. data/ext/libev/README +58 -0
  35. data/ext/libev/README.embed +3 -0
  36. data/ext/libev/ev.c +5054 -0
  37. data/ext/libev/ev.h +853 -0
  38. data/ext/libev/ev_epoll.c +282 -0
  39. data/ext/libev/ev_kqueue.c +214 -0
  40. data/ext/libev/ev_poll.c +148 -0
  41. data/ext/libev/ev_port.c +185 -0
  42. data/ext/libev/ev_select.c +362 -0
  43. data/ext/libev/ev_vars.h +204 -0
  44. data/ext/libev/ev_win32.c +163 -0
  45. data/ext/libev/ev_wrap.h +200 -0
  46. data/ext/libev/ruby_gil.patch +97 -0
  47. data/ext/libev/test_libev_win32.c +123 -0
  48. data/ext/libev/win_select.patch +115 -0
  49. data/lib/.gitignore +2 -0
  50. data/lib/cool.io.rb +34 -0
  51. data/lib/cool.io/async_watcher.rb +43 -0
  52. data/lib/cool.io/custom_require.rb +9 -0
  53. data/lib/cool.io/dns_resolver.rb +219 -0
  54. data/lib/cool.io/dsl.rb +139 -0
  55. data/lib/cool.io/io.rb +194 -0
  56. data/lib/cool.io/iowatcher.rb +17 -0
  57. data/lib/cool.io/listener.rb +99 -0
  58. data/lib/cool.io/loop.rb +122 -0
  59. data/lib/cool.io/meta.rb +49 -0
  60. data/lib/cool.io/server.rb +75 -0
  61. data/lib/cool.io/socket.rb +230 -0
  62. data/lib/cool.io/timer_watcher.rb +17 -0
  63. data/lib/cool.io/version.rb +7 -0
  64. data/lib/coolio.rb +2 -0
  65. data/spec/async_watcher_spec.rb +57 -0
  66. data/spec/dns_spec.rb +43 -0
  67. data/spec/iobuffer_spec.rb +147 -0
  68. data/spec/spec_helper.rb +19 -0
  69. data/spec/stat_watcher_spec.rb +77 -0
  70. data/spec/tcp_server_spec.rb +225 -0
  71. data/spec/tcp_socket_spec.rb +185 -0
  72. data/spec/timer_watcher_spec.rb +59 -0
  73. data/spec/udp_socket_spec.rb +58 -0
  74. data/spec/unix_listener_spec.rb +25 -0
  75. data/spec/unix_server_spec.rb +27 -0
  76. metadata +182 -0
@@ -0,0 +1,185 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Coolio::TCPSocket do
4
+ let :loop do
5
+ Coolio::Loop.new
6
+ end
7
+
8
+ before :each do
9
+ @echo = TCPServer.new("127.0.0.1", 0)
10
+ @host = @echo.addr[3]
11
+ @port = @echo.addr[1]
12
+ @running = true
13
+ @echo_thread = Thread.new do
14
+ socks = [@echo]
15
+ begin
16
+ serv socks
17
+ ensure
18
+ socks.each do |s|
19
+ s.close
20
+ end
21
+ end
22
+ Thread.pass
23
+ end
24
+ end
25
+
26
+ def serv(socks)
27
+ while @running
28
+ selected = select(socks, [], [], 0.1)
29
+ next if selected.nil?
30
+ selected[0].each do |s|
31
+ if s == @echo
32
+ socks.push s.accept
33
+ next
34
+ end
35
+ begin
36
+ unless s.eof?
37
+ s.write(s.read_nonblock 1)
38
+ end
39
+ rescue SystemCallError, EOFError, IOError, SocketError
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ def shutdown
46
+ if @running
47
+ @running = false
48
+ @echo_thread.join
49
+ end
50
+ end
51
+
52
+ after :each do
53
+ shutdown
54
+ end
55
+
56
+ context "#close" do
57
+ it "detaches all watchers on #close before loop#run" do
58
+ client = Coolio::TCPSocket.connect(@host, @port)
59
+ loop.attach client
60
+ client.close
61
+ expect(loop.watchers.size).to eq 0
62
+ end
63
+ end
64
+
65
+ context "#on_connect" do
66
+ class OnConnect < Cool.io::TCPSocket
67
+ attr :connected
68
+ def on_connect
69
+ @connected = true
70
+ end
71
+ end
72
+
73
+ it "connected client called on_connect" do
74
+ begin
75
+ c = OnConnect.connect(@host, @port)
76
+ loop.attach c
77
+ loop.run_once
78
+ expect(c.connected).to eq true
79
+ ensure
80
+ c.close
81
+ end
82
+ end
83
+ end
84
+
85
+ context "#on_connect_failed" do
86
+ class OnConnectFailed < Cool.io::TCPSocket
87
+ attr :connect_failed
88
+ def on_connect_failed
89
+ @connect_failed = true
90
+ end
91
+ end
92
+
93
+ it "try to connect dead host" do
94
+ serv = TCPServer.new(0)
95
+ dead_host = serv.addr[3]
96
+ dead_port = serv.addr[1]
97
+ serv.close
98
+
99
+ c = OnConnectFailed.connect(dead_host, dead_port)
100
+ loop.attach c
101
+ loop.run_once # on_connect_failed
102
+ expect(c.connect_failed).to eq true
103
+ end
104
+ end
105
+
106
+ context "#on_close" do
107
+ class Closed < StandardError; end
108
+ class OnClose < Cool.io::TCPSocket
109
+ def on_close
110
+ raise Closed
111
+ end
112
+ end
113
+
114
+ let :client do
115
+ OnClose.connect(@host, @port)
116
+ end
117
+
118
+ before :each do
119
+ loop.attach client
120
+ loop.run_once # on_connect
121
+ client.write "0"
122
+ end
123
+
124
+ it "disconnect from client" do
125
+ expect { client.close }.to raise_error(Closed)
126
+ end
127
+
128
+ it "disconnect from server" do
129
+ shutdown
130
+ expect { loop.run }.to raise_error(Closed)
131
+ end
132
+ end
133
+
134
+ context "#on_read" do
135
+ class Finished < StandardError; end
136
+ class OnRead < Cool.io::TCPSocket
137
+ attr :read_data, :times
138
+ def on_connect
139
+ @read_data = ""
140
+ @times = 0
141
+ end
142
+ def on_read(data)
143
+ @read_data += data
144
+ @times += 1
145
+ if @times < 5
146
+ write "#{@times}"
147
+ else
148
+ close
149
+ raise Finished
150
+ end
151
+ end
152
+ end
153
+
154
+ it "receive 5 times" do
155
+ c = OnRead.connect(@host, @port)
156
+ loop.attach c
157
+ loop.run_once # on_connect
158
+ c.write "0"
159
+ expect { loop.run }.to raise_error(Finished)
160
+
161
+ expect(c.times).to eq 5
162
+ expect(c.read_data).to eq "01234"
163
+ end
164
+ end
165
+
166
+ context "#on_write_complete" do
167
+ class WriteComplete < StandardError; end
168
+ class OnWriteComplete < Cool.io::TCPSocket
169
+ attr :called
170
+ def on_write_complete
171
+ @called = true
172
+ close
173
+ raise WriteComplete
174
+ end
175
+ end
176
+
177
+ it "on_write_complete is called" do
178
+ c = OnWriteComplete.connect(@host, @port)
179
+ loop.attach c
180
+ loop.run_once # on_connect
181
+ c.write "aaa"
182
+ expect { loop.run }.to raise_error(WriteComplete)
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Cool.io::TimerWatcher do
4
+
5
+ interval = 0.010
6
+
7
+ let :loop do
8
+ Cool.io::Loop.new
9
+ end
10
+
11
+ it "can have the on_timer callback defined after creation" do
12
+ @watcher = Cool.io::TimerWatcher.new(interval, true)
13
+ nr = '0'
14
+ expect(@watcher.on_timer { nr.succ! }).to be_nil
15
+ expect(@watcher.attach(loop)).to eq(@watcher)
16
+ expect(nr).to eq('0')
17
+ sleep interval
18
+ loop.run_once
19
+ expect(nr).to eq('1')
20
+ end
21
+
22
+ it "can be subclassed" do
23
+ class MyTimerWatcher < Cool.io::TimerWatcher
24
+ TMP = '0'
25
+
26
+ def on_timer
27
+ TMP.succ!
28
+ end
29
+ end
30
+ @watcher = MyTimerWatcher.new(interval, true)
31
+ expect(@watcher.attach(loop)).to eq(@watcher)
32
+ expect(MyTimerWatcher::TMP).to eq('0')
33
+ sleep interval
34
+ loop.run_once
35
+ expect(MyTimerWatcher::TMP).to eq('1')
36
+ end
37
+
38
+ it "can have the on_timer callback redefined between runs" do
39
+ @watcher = Cool.io::TimerWatcher.new(interval, true)
40
+ nr = '0'
41
+ expect(@watcher.on_timer { nr.succ! }).to be_nil
42
+ expect(@watcher.attach(loop)).to eq(@watcher)
43
+ expect(nr).to eq('0')
44
+ sleep interval
45
+ loop.run_once
46
+ expect(nr).to eq('1')
47
+ @watcher.detach
48
+ expect(@watcher.on_timer { nr = :foo }).to be_nil
49
+ expect(@watcher.attach(loop)).to eq(@watcher)
50
+ expect(nr).to eq('1')
51
+ sleep interval
52
+ loop.run_once
53
+ expect(nr).to eq(:foo)
54
+ end
55
+
56
+ after :each do
57
+ @watcher.detach if defined?(@watcher)
58
+ end
59
+ end
@@ -0,0 +1,58 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe "Coolio::UDPSocket" do
4
+ let :loop do
5
+ Coolio::Loop.new
6
+ end
7
+
8
+ before :each do
9
+ @echo = UDPSocket.open
10
+ @echo.bind nil, 0
11
+ @port = @echo.addr[1]
12
+
13
+ @running = true
14
+ @echo_thread = Thread.new do
15
+ while @running
16
+ begin
17
+ msg, sender = @echo.recvfrom_nonblock(3)
18
+ @echo.send(msg + "bbb", 0, sender[3], sender[1])
19
+ rescue IO::WaitReadable
20
+ end
21
+ Thread.pass
22
+ end
23
+ end
24
+ end
25
+
26
+ after :each do
27
+ @running = false
28
+ @echo_thread.join
29
+ @echo.close
30
+ end
31
+
32
+ class Readable < Cool.io::IOWatcher
33
+ attr :socket, :received
34
+ def initialize
35
+ @socket = UDPSocket.new
36
+ super(@socket)
37
+ end
38
+
39
+ def on_readable
40
+ @received = @socket.recvfrom_nonblock(6).first
41
+ end
42
+ end
43
+
44
+ it "receive message #on_readable 5 times" do
45
+ 5.times do
46
+ begin
47
+ r = Readable.new
48
+ r.socket.send "aaa", 0, "localhost", @port
49
+
50
+ loop.attach r
51
+ loop.run_once
52
+ expect(r.received).to eq "aaabbb"
53
+ ensure
54
+ r.detach
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'tempfile'
3
+
4
+ describe Cool.io::UNIXListener, :env => :exclude_win do
5
+
6
+ before :each do
7
+ @tmp = Tempfile.new('coolio_unix_listener_spec')
8
+ expect(File.unlink(@tmp.path)).to eq(1)
9
+ expect(File.exist?(@tmp.path)).to eq(false)
10
+ end
11
+
12
+ it "creates a new UNIXListener" do
13
+ listener = Cool.io::UNIXListener.new(@tmp.path)
14
+ expect(File.socket?(@tmp.path)).to eq(true)
15
+ end
16
+
17
+ it "builds off an existing UNIXServer" do
18
+ unix_server = UNIXServer.new(@tmp.path)
19
+ expect(File.socket?(@tmp.path)).to eq(true)
20
+ listener = Cool.io::UNIXListener.new(unix_server)
21
+ expect(File.socket?(@tmp.path)).to eq(true)
22
+ expect(listener.fileno).to eq(unix_server.fileno)
23
+ end
24
+
25
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'tempfile'
3
+
4
+ describe Cool.io::UNIXServer, :env => :exclude_win do
5
+
6
+ before :each do
7
+ @tmp = Tempfile.new('coolio_unix_server_spec')
8
+ expect(File.unlink(@tmp.path)).to eq(1)
9
+ expect(File.exist?(@tmp.path)).to eq(false)
10
+ end
11
+
12
+ it "creates a new Cool.io::UNIXServer" do
13
+ listener = Cool.io::UNIXListener.new(@tmp.path)
14
+ listener.listen(24)
15
+ expect(File.socket?(@tmp.path)).to eq(true)
16
+ end
17
+
18
+ it "builds off an existing ::UNIXServer" do
19
+ unix_server = ::UNIXServer.new(@tmp.path)
20
+ expect(File.socket?(@tmp.path)).to eq(true)
21
+ listener = Cool.io::UNIXServer.new(unix_server, Coolio::UNIXSocket)
22
+ listener.listen(24)
23
+ expect(File.socket?(@tmp.path)).to eq(true)
24
+ expect(listener.fileno).to eq(unix_server.fileno)
25
+ end
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cool.io
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.1
5
+ platform: x64-mingw32
6
+ authors:
7
+ - Tony Arcieri
8
+ - Masahiro Nakagawa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-10-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake-compiler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.9.5
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.9.5
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake-compiler-dock
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.4.3
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.4.3
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.13.0
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.13.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: rdoc
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.6.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 3.6.0
70
+ description: Cool.io provides a high performance event framework for Ruby which uses
71
+ the libev C library
72
+ email:
73
+ - tony.arcieri@gmail.com
74
+ - repeatedly@gmail.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".travis.yml"
82
+ - CHANGES.md
83
+ - Gemfile
84
+ - LICENSE
85
+ - README.md
86
+ - Rakefile
87
+ - cool.io.gemspec
88
+ - examples/callbacked_echo_server.rb
89
+ - examples/dslified_echo_client.rb
90
+ - examples/dslified_echo_server.rb
91
+ - examples/echo_client.rb
92
+ - examples/echo_server.rb
93
+ - examples/google.rb
94
+ - ext/cool.io/.gitignore
95
+ - ext/cool.io/cool.io.h
96
+ - ext/cool.io/cool.io_ext.c
97
+ - ext/cool.io/ev_wrap.h
98
+ - ext/cool.io/extconf.rb
99
+ - ext/cool.io/iowatcher.c
100
+ - ext/cool.io/libev.c
101
+ - ext/cool.io/loop.c
102
+ - ext/cool.io/stat_watcher.c
103
+ - ext/cool.io/timer_watcher.c
104
+ - ext/cool.io/utils.c
105
+ - ext/cool.io/watcher.c
106
+ - ext/cool.io/watcher.h
107
+ - ext/iobuffer/extconf.rb
108
+ - ext/iobuffer/iobuffer.c
109
+ - ext/libev/Changes
110
+ - ext/libev/LICENSE
111
+ - ext/libev/README
112
+ - ext/libev/README.embed
113
+ - ext/libev/ev.c
114
+ - ext/libev/ev.h
115
+ - ext/libev/ev_epoll.c
116
+ - ext/libev/ev_kqueue.c
117
+ - ext/libev/ev_poll.c
118
+ - ext/libev/ev_port.c
119
+ - ext/libev/ev_select.c
120
+ - ext/libev/ev_vars.h
121
+ - ext/libev/ev_win32.c
122
+ - ext/libev/ev_wrap.h
123
+ - ext/libev/ruby_gil.patch
124
+ - ext/libev/test_libev_win32.c
125
+ - ext/libev/win_select.patch
126
+ - lib/.gitignore
127
+ - lib/2.0/cool.io_ext.so
128
+ - lib/2.0/iobuffer_ext.so
129
+ - lib/2.1/cool.io_ext.so
130
+ - lib/2.1/iobuffer_ext.so
131
+ - lib/2.2/cool.io_ext.so
132
+ - lib/2.2/iobuffer_ext.so
133
+ - lib/cool.io.rb
134
+ - lib/cool.io/async_watcher.rb
135
+ - lib/cool.io/custom_require.rb
136
+ - lib/cool.io/dns_resolver.rb
137
+ - lib/cool.io/dsl.rb
138
+ - lib/cool.io/io.rb
139
+ - lib/cool.io/iowatcher.rb
140
+ - lib/cool.io/listener.rb
141
+ - lib/cool.io/loop.rb
142
+ - lib/cool.io/meta.rb
143
+ - lib/cool.io/server.rb
144
+ - lib/cool.io/socket.rb
145
+ - lib/cool.io/timer_watcher.rb
146
+ - lib/cool.io/version.rb
147
+ - lib/coolio.rb
148
+ - spec/async_watcher_spec.rb
149
+ - spec/dns_spec.rb
150
+ - spec/iobuffer_spec.rb
151
+ - spec/spec_helper.rb
152
+ - spec/stat_watcher_spec.rb
153
+ - spec/tcp_server_spec.rb
154
+ - spec/tcp_socket_spec.rb
155
+ - spec/timer_watcher_spec.rb
156
+ - spec/udp_socket_spec.rb
157
+ - spec/unix_listener_spec.rb
158
+ - spec/unix_server_spec.rb
159
+ homepage: http://coolio.github.com
160
+ licenses: []
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.4.8
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: A cool framework for doing high performance I/O in Ruby
182
+ test_files: []