cool.io 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +26 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +4 -0
  4. data/{CHANGES → CHANGES.md} +43 -79
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +32 -0
  7. data/{README.markdown → README.md} +0 -4
  8. data/Rakefile +31 -67
  9. data/cool.io.gemspec +25 -133
  10. data/ext/cool.io/extconf.rb +3 -0
  11. data/ext/cool.io/stat_watcher.c +99 -23
  12. data/ext/libev/Changes +24 -0
  13. data/ext/libev/ev.c +78 -32
  14. data/ext/libev/ev.h +11 -8
  15. data/ext/libev/ev_epoll.c +39 -7
  16. data/ext/libev/ev_kqueue.c +5 -5
  17. data/ext/libev/ev_poll.c +5 -5
  18. data/ext/libev/ev_port.c +26 -11
  19. data/ext/libev/ev_select.c +11 -8
  20. data/ext/libev/ev_vars.h +10 -4
  21. data/ext/libev/ev_win32.c +6 -6
  22. data/ext/libev/ev_wrap.h +10 -0
  23. data/lib/cool.io.rb +3 -3
  24. data/lib/cool.io/async_watcher.rb +1 -1
  25. data/lib/cool.io/dns_resolver.rb +14 -12
  26. data/lib/cool.io/dsl.rb +26 -26
  27. data/lib/cool.io/eventmachine.rb +18 -18
  28. data/lib/cool.io/http_client.rb +29 -22
  29. data/lib/cool.io/io.rb +18 -18
  30. data/lib/cool.io/iowatcher.rb +1 -1
  31. data/lib/cool.io/listener.rb +2 -2
  32. data/lib/cool.io/loop.rb +12 -12
  33. data/lib/cool.io/meta.rb +4 -4
  34. data/lib/cool.io/server.rb +3 -3
  35. data/lib/cool.io/socket.rb +36 -28
  36. data/lib/cool.io/timer_watcher.rb +1 -1
  37. data/lib/cool.io/version.rb +5 -0
  38. data/lib/coolio.rb +1 -1
  39. data/spec/stat_watcher_spec.rb +77 -0
  40. metadata +47 -56
  41. data/VERSION +0 -1
  42. data/lib/rev.rb +0 -4
  43. data/spec/possible_tests/schedules_other_threads.rb +0 -48
  44. data/spec/possible_tests/test_on_resolve_failed.rb +0 -9
  45. data/spec/possible_tests/test_resolves.rb +0 -27
  46. data/spec/possible_tests/test_write_during_resolve.rb +0 -27
  47. data/spec/possible_tests/works_straight.rb +0 -71
@@ -1,2 +1,2 @@
1
1
  # For those people who don't like the cool.io styling...
2
- require 'cool.io'
2
+ require 'cool.io'
@@ -0,0 +1,77 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ TEMP_FILE_PATH = "./test.txt"
4
+
5
+ INTERVAL = 0.010
6
+
7
+ class MyStatWatcher < Cool.io::StatWatcher
8
+ attr_accessor :accessed, :previous, :current
9
+
10
+ def initialize(path)
11
+ super path, INTERVAL
12
+ end
13
+
14
+ def on_change(previous, current)
15
+ self.accessed = true
16
+ self.previous = previous
17
+ self.current = current
18
+ end
19
+ end
20
+
21
+ def run_with_file_change(path)
22
+ reactor = Cool.io::Loop.new
23
+
24
+ sw = MyStatWatcher.new(path)
25
+ sw.attach(reactor)
26
+
27
+ tw = Cool.io::TimerWatcher.new(INTERVAL, true)
28
+ tw.on_timer do
29
+ reactor.stop if sw.accessed
30
+ write_file(path)
31
+ end
32
+ tw.attach(reactor)
33
+
34
+ reactor.run
35
+
36
+ tw.detach
37
+ sw.detach
38
+
39
+ sw
40
+ end
41
+
42
+ def write_file(path)
43
+ File.open(path, "w+") { |f| f.write(rand.to_s) }
44
+ end
45
+
46
+ def delete_file(path)
47
+ File.delete(TEMP_FILE_PATH)
48
+ end
49
+
50
+ describe Cool.io::StatWatcher do
51
+
52
+ let :watcher do
53
+ run_with_file_change(TEMP_FILE_PATH)
54
+ end
55
+
56
+ before :each do
57
+ write_file(TEMP_FILE_PATH)
58
+ end
59
+
60
+ after :each do
61
+ delete_file(TEMP_FILE_PATH)
62
+ end
63
+
64
+ it "fire on_change when the file it is watching is modified" do
65
+ watcher.accessed.should eql(true)
66
+ end
67
+
68
+ it "should pass previous and current file stat info given a stat watcher" do
69
+ watcher.previous.ino.should eql(watcher.current.ino)
70
+ end
71
+
72
+ it "should raise when the handler does not take 2 parameters" do
73
+ class MyStatWatcher < Cool.io::StatWatcher; def on_change; end; end
74
+ lambda { watcher.accessed }.should raise_error(ArgumentError)
75
+ end
76
+
77
+ end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cool.io
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
4
+ prerelease:
5
+ version: 1.1.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Tony Arcieri
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2010-12-13 00:00:00 -07:00
13
+ date: 2011-08-10 00:00:00 -07:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,46 +21,62 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 29
30
- segments:
31
- - 0
32
- - 1
33
- - 3
34
- version: 0.1.3
24
+ version: 1.0.0
35
25
  type: :runtime
36
26
  version_requirements: *id001
37
27
  - !ruby/object:Gem::Dependency
38
- name: rspec
28
+ name: rake-compiler
39
29
  prerelease: false
40
30
  requirement: &id002 !ruby/object:Gem::Requirement
41
31
  none: false
42
32
  requirements:
43
- - - ">="
33
+ - - ~>
44
34
  - !ruby/object:Gem::Version
45
- hash: 11
46
- segments:
47
- - 2
48
- - 1
49
- - 0
50
- version: 2.1.0
35
+ version: 0.7.9
51
36
  type: :development
52
37
  version_requirements: *id002
53
- description: A Ruby wrapper around the libev high performance event library
54
- email: tony@medioh.com
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.6.0
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rdoc
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 3.6.0
58
+ type: :development
59
+ version_requirements: *id004
60
+ description: Cool.io provides a high performance event framework for Ruby which uses the libev C library
61
+ email:
62
+ - tony.arcieri@gmail.com
55
63
  executables: []
56
64
 
57
65
  extensions:
58
66
  - ext/cool.io/extconf.rb
59
67
  - ext/http11_client/extconf.rb
60
- extra_rdoc_files:
61
- - LICENSE
62
- - README.markdown
68
+ extra_rdoc_files: []
69
+
63
70
  files:
64
- - CHANGES
71
+ - .gitignore
72
+ - .rspec
73
+ - .travis.yml
74
+ - CHANGES.md
75
+ - Gemfile
76
+ - Gemfile.lock
65
77
  - LICENSE
66
- - README.markdown
78
+ - README.md
67
79
  - Rakefile
68
- - VERSION
69
80
  - cool.io.gemspec
70
81
  - examples/dslified_echo_client.rb
71
82
  - examples/dslified_echo_server.rb
@@ -124,21 +135,17 @@ files:
124
135
  - lib/cool.io/server.rb
125
136
  - lib/cool.io/socket.rb
126
137
  - lib/cool.io/timer_watcher.rb
138
+ - lib/cool.io/version.rb
127
139
  - lib/coolio.rb
128
- - lib/rev.rb
129
140
  - spec/async_watcher_spec.rb
130
141
  - spec/dns_spec.rb
131
- - spec/possible_tests/schedules_other_threads.rb
132
- - spec/possible_tests/test_on_resolve_failed.rb
133
- - spec/possible_tests/test_resolves.rb
134
- - spec/possible_tests/test_write_during_resolve.rb
135
- - spec/possible_tests/works_straight.rb
136
142
  - spec/spec_helper.rb
143
+ - spec/stat_watcher_spec.rb
137
144
  - spec/timer_watcher_spec.rb
138
145
  - spec/unix_listener_spec.rb
139
146
  - spec/unix_server_spec.rb
140
147
  has_rdoc: true
141
- homepage: http://github.com/tarcieri/cool.io
148
+ homepage: http://coolio.github.com
142
149
  licenses: []
143
150
 
144
151
  post_install_message:
@@ -151,41 +158,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
158
  requirements:
152
159
  - - ">="
153
160
  - !ruby/object:Gem::Version
154
- hash: 3
155
- segments:
156
- - 0
157
161
  version: "0"
158
162
  required_rubygems_version: !ruby/object:Gem::Requirement
159
163
  none: false
160
164
  requirements:
161
165
  - - ">="
162
166
  - !ruby/object:Gem::Version
163
- hash: 3
164
- segments:
165
- - 0
166
167
  version: "0"
167
168
  requirements: []
168
169
 
169
170
  rubyforge_project:
170
- rubygems_version: 1.3.7
171
+ rubygems_version: 1.6.2
171
172
  signing_key:
172
173
  specification_version: 3
173
- summary: The cool event framework for Ruby
174
+ summary: A cool framework for doing high performance I/O in Ruby
174
175
  test_files:
175
- - examples/dslified_echo_client.rb
176
- - examples/dslified_echo_server.rb
177
- - examples/echo_client.rb
178
- - examples/echo_server.rb
179
- - examples/google.rb
180
- - examples/httpclient.rb
181
176
  - spec/async_watcher_spec.rb
182
177
  - spec/dns_spec.rb
183
- - spec/possible_tests/schedules_other_threads.rb
184
- - spec/possible_tests/test_on_resolve_failed.rb
185
- - spec/possible_tests/test_resolves.rb
186
- - spec/possible_tests/test_write_during_resolve.rb
187
- - spec/possible_tests/works_straight.rb
188
178
  - spec/spec_helper.rb
179
+ - spec/stat_watcher_spec.rb
189
180
  - spec/timer_watcher_spec.rb
190
181
  - spec/unix_listener_spec.rb
191
182
  - spec/unix_server_spec.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.0
data/lib/rev.rb DELETED
@@ -1,4 +0,0 @@
1
- STDERR.puts "*** DEPRECATION WARNING: require 'rev' and the Rev constant are deprecated. Please use require 'cool.io' and the Coolio constant instead"
2
-
3
- require 'cool.io'
4
- Rev = Coolio
@@ -1,48 +0,0 @@
1
- require File.dirname(__FILE__) + '/../lib/rev'
2
- def dbg
3
- require 'rubygems'
4
- require 'ruby-debug'
5
- debugger
6
- end
7
- Thread.abort_on_exception=true
8
-
9
- require 'socket'
10
-
11
- describe Rev::TCPSocket do
12
- HOST = '127.0.0.1'
13
- PORT = 4321
14
- before :each do
15
- @server = Rev::TCPServer.new(HOST, PORT) do |c|
16
- c.on_connect { puts "#{remote_addr}:#{remote_port} connected" }
17
- c.on_close { puts "#{remote_addr}:#{remote_port} disconnected" }
18
- #c.on_read { |data| write data }
19
- end
20
-
21
- end
22
-
23
- after :each do
24
- @server.close
25
- end
26
-
27
- def sleep_until(seconds = 1, interval = 0.1)
28
- raise unless block_given?
29
- start_time=Time.now
30
- sleep interval until ((Time.now - start_time) > seconds) or yield
31
- end
32
-
33
- it "should stop" do
34
- loop = Rev::Loop.default
35
- stopped = false;
36
- @server.attach(loop)
37
- Thread.new {
38
- loop.run
39
- stopped = true
40
- }
41
- sleep 0
42
- stopped.should == false
43
- loop.stop
44
- sleep_until(3) { stopped == true }
45
- stopped.should == true
46
- end
47
- end
48
-
@@ -1,9 +0,0 @@
1
- require '../rev'
2
- class Tester < Rev::TCPSocket
3
- def on_resolve_failed
4
- print "resolved failed! that's good!"
5
- end
6
- end
7
- a = Tester.connect('asdfgoogle.com', 80)
8
- a.attach Rev::Loop.default
9
- Rev::Loop.default.run
@@ -1,27 +0,0 @@
1
- require File.dirname(__FILE__) + '/../rev'
2
-
3
- ADDR = 'wilkboardonline.com'
4
- PORT = 80
5
-
6
- class ClientConnection < Rev::TCPSocket
7
- def on_connect
8
- puts "#{remote_addr}:#{remote_port} connected"
9
- write ("GET / HTTP/1.1\r\nhost:wilkboardonline.com:80\r\nconnection:close\r\n\r\n")
10
- end
11
-
12
- def on_close
13
- puts "#{remote_addr}:#{remote_port} disconnected"
14
- end
15
-
16
- def on_read(data)
17
- print "got #{data}"
18
- close
19
- end
20
-
21
- end
22
-
23
- event_loop = Rev::Loop.default
24
- client = ClientConnection.connect(ADDR, PORT)
25
- client.attach(event_loop)
26
- puts "Echo client started to #{ADDR}:#{PORT}"
27
- event_loop.run
@@ -1,27 +0,0 @@
1
- require File.dirname(__FILE__) + '/../rev'
2
-
3
- ADDR = 'wilkboardonline.com'
4
- PORT = 80
5
-
6
- class ClientConnection < Rev::TCPSocket
7
- def on_connect
8
- puts "#{remote_addr}:#{remote_port} connected"
9
- end
10
-
11
- def on_close
12
- puts "#{remote_addr}:#{remote_port} disconnected"
13
- end
14
-
15
- def on_read(data)
16
- print "got #{data}"
17
- close
18
- end
19
-
20
- end
21
-
22
- event_loop = Rev::Loop.default
23
- client = ClientConnection.connect(ADDR, PORT)
24
- client.write ("GET / HTTP/1.1\r\nhost:wilkboardonline.com:80\r\nconnection:close\r\n\r\n")
25
- client.attach(event_loop)
26
- puts "Echo client started to #{ADDR}:#{PORT}"
27
- event_loop.run
@@ -1,71 +0,0 @@
1
- require File.dirname(__FILE__) + '/../lib/rev'
2
- def dbg
3
- require 'rubygems'
4
- require 'ruby-debug'
5
- debugger
6
- end
7
- Thread.abort_on_exception=true
8
-
9
- require 'socket'
10
-
11
- describe Rev::TCPSocket do
12
- HOST = '127.0.0.1'
13
- PORT = 4321
14
- before :each do
15
- @server = Rev::TCPServer.new(HOST, PORT) do |c|
16
- c.on_connect { puts "#{remote_addr}:#{remote_port} connected" }
17
- c.on_close { puts "#{remote_addr}:#{remote_port} disconnected" }
18
- #c.on_read { |data| write data }
19
- end
20
-
21
- end
22
-
23
- after :each do
24
- @server.close
25
- end
26
-
27
- def sleep_until(seconds = 1, interval = 0.1)
28
- raise unless block_given?
29
- start_time=Time.now
30
- sleep interval until ((Time.now - start_time) > seconds) or yield
31
- end
32
-
33
- it "should stop" do
34
- loop = Rev::Loop.default
35
- stopped = false;
36
- @server.attach(loop)
37
- Thread.new {
38
- loop.run_nonblock_over_and_over_again
39
- stopped = true
40
- }
41
- sleep 0
42
- stopped.should == false
43
- loop.stop
44
-
45
- sleep_until { stopped == true }
46
- stopped.should == true
47
- end
48
-
49
- it "should auto bind on 1.8.6" do
50
- @server.close
51
- loop = Rev::Loop.default
52
- server = Rev::TCPServer.new(HOST, PORT) do |c|
53
- #c.on_connect { puts "#{remote_addr}:#{remote_port} connected" }
54
- #c.on_close { puts "#{remote_addr}:#{remote_port} disconnected" }
55
- print "CREATING\n"
56
- c.on_read { |conn, data| print "WITHIN MYINE"; conn.write data; conn.close; loop.stop }
57
- end
58
-
59
- server.attach(loop)
60
-
61
- Thread.new { loop.run_nonblock_over_and_over_again }
62
- puts "Echo server listening on #{HOST}:#{PORT}"
63
- # now connect and write -- it should close
64
- connector = TCPSocket.new HOST, PORT
65
- connector.write "yup"
66
- connector.read.should == 'yup'
67
- sleep 0
68
- loop.running?.should != true
69
- connector.closed?.should == true # it should close me, too
70
- end
71
- end