cool.io 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +1 -2
- data/CHANGES.md +7 -0
- data/README.md +0 -3
- data/lib/cool.io.rb +6 -2
- data/lib/cool.io/dns_resolver.rb +3 -8
- data/lib/cool.io/dsl.rb +6 -2
- data/lib/cool.io/http_client.rb +3 -0
- data/lib/cool.io/io.rb +35 -10
- data/lib/cool.io/loop.rb +3 -11
- data/lib/cool.io/meta.rb +1 -1
- data/lib/cool.io/version.rb +4 -2
- data/spec/async_watcher_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/tcp_server_spec.rb +1 -1
- data/spec/tcp_socket_spec.rb +27 -0
- data/spec/unix_listener_spec.rb +1 -1
- data/spec/unix_server_spec.rb +1 -1
- metadata +18 -30
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: edacf8d3fa674b299e42ade38405b993f5e89de3
|
4
|
+
data.tar.gz: d4d3745f78319c94a7a8780408bc636036315b67
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d870e50cec23dbcd03d8216b42c0b5cebfa4176d2d14b84d8b852478ad632d06464c87c3859c0e5838eeee7a44bceb03f4b79ee151a897b96d49fdbb8b680fc
|
7
|
+
data.tar.gz: 3f4bd75c9720813861d33fec20e26bee7adb421667de536b8d3aa5333372c35cf5c4afa94abb3a0740d412040f0a8dcb2b94d29ad7f81b73a07d4bb503f738e1
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -86,9 +86,6 @@ core socket classes are also provided. Among these are:
|
|
86
86
|
Cool.io::TCPSocket (or any subclass you wish to provide) whenever an incoming
|
87
87
|
connection is received.
|
88
88
|
|
89
|
-
* Cool.io::HttpClient - An HTTP/1.1 client with support for chunked encoding
|
90
|
-
and streaming response processing through asynchronous callbacks.
|
91
|
-
|
92
89
|
Example Program
|
93
90
|
---------------
|
94
91
|
|
data/lib/cool.io.rb
CHANGED
@@ -23,10 +23,14 @@ require "cool.io/http_client"
|
|
23
23
|
require "cool.io/dsl"
|
24
24
|
|
25
25
|
module Coolio
|
26
|
-
def self.inspect
|
26
|
+
def self.inspect
|
27
|
+
"Cool.io"
|
28
|
+
end
|
27
29
|
end
|
28
30
|
|
29
31
|
module Cool
|
30
32
|
# Allow Coolio module to be referenced as Cool.io
|
31
|
-
def self.io
|
33
|
+
def self.io
|
34
|
+
Coolio
|
35
|
+
end
|
32
36
|
end
|
data/lib/cool.io/dns_resolver.rb
CHANGED
@@ -17,6 +17,8 @@
|
|
17
17
|
#
|
18
18
|
#++
|
19
19
|
|
20
|
+
require 'resolv'
|
21
|
+
|
20
22
|
module Coolio
|
21
23
|
# A non-blocking DNS resolver. It provides interfaces for querying both
|
22
24
|
# /etc/hosts and nameserves listed in /etc/resolv.conf, or nameservers of
|
@@ -31,12 +33,6 @@ module Coolio
|
|
31
33
|
# again.
|
32
34
|
class DNSResolver < IOWatcher
|
33
35
|
#--
|
34
|
-
# TODO check if it's caching right
|
35
|
-
if RUBY_PLATFORM =~ /mingw|win32/
|
36
|
-
HOSTS = 'c:\WINDOWS\system32\drivers\etc\hosts'
|
37
|
-
else
|
38
|
-
HOSTS = '/etc/hosts'
|
39
|
-
end
|
40
36
|
DNS_PORT = 53
|
41
37
|
DATAGRAM_SIZE = 512
|
42
38
|
TIMEOUT = 3 # Retry timeout for each datagram sent
|
@@ -44,7 +40,7 @@ module Coolio
|
|
44
40
|
# so currently total is 12s before it will err due to timeouts
|
45
41
|
# if it errs due to inability to reach the DNS server [Errno::EHOSTUNREACH], same
|
46
42
|
# Query /etc/hosts (or the specified hostfile) for the given host
|
47
|
-
def self.hosts(host, hostfile =
|
43
|
+
def self.hosts(host, hostfile = Resolv::Hosts::DefaultFileName)
|
48
44
|
hosts = {}
|
49
45
|
File.open(hostfile) do |f|
|
50
46
|
f.each_line do |host_entry|
|
@@ -63,7 +59,6 @@ module Coolio
|
|
63
59
|
# use nameservers listed in /etc/resolv.conf
|
64
60
|
def initialize(hostname, *nameservers)
|
65
61
|
if nameservers.empty?
|
66
|
-
require 'resolv'
|
67
62
|
nameservers = Resolv::DNS::Config.default_config_hash[:nameserver]
|
68
63
|
raise RuntimeError, "no nameservers found" if nameservers.empty? # TODO just call resolve_failed, not raise [also handle Errno::ENOENT)]
|
69
64
|
end
|
data/lib/cool.io/dsl.rb
CHANGED
@@ -124,11 +124,15 @@ end
|
|
124
124
|
# The Cool module containing all our coolness
|
125
125
|
module Cool
|
126
126
|
module Coolness
|
127
|
-
def cool
|
127
|
+
def cool
|
128
|
+
Cool::IOThunk
|
129
|
+
end
|
128
130
|
end
|
129
131
|
|
130
132
|
module IOThunk
|
131
|
-
def self.io
|
133
|
+
def self.io
|
134
|
+
Coolio::DSL
|
135
|
+
end
|
132
136
|
end
|
133
137
|
end
|
134
138
|
|
data/lib/cool.io/http_client.rb
CHANGED
@@ -111,6 +111,9 @@ module Coolio
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
+
# HttpClient is tested on only CRuby. AFAIK, there is no HttpClient users.
|
115
|
+
# So HttpClient will not be maintained in the future.
|
116
|
+
|
114
117
|
# HTTP client class implemented as a subclass of Coolio::TCPSocket. Encodes
|
115
118
|
# requests and allows streaming consumption of the response. Response is
|
116
119
|
# parsed with a Ragel-generated whitelist parser which supports chunked
|
data/lib/cool.io/io.rb
CHANGED
@@ -31,25 +31,45 @@ module Coolio
|
|
31
31
|
#
|
32
32
|
|
33
33
|
# Attach to the event loop
|
34
|
-
def attach(loop)
|
34
|
+
def attach(loop)
|
35
|
+
@_read_watcher.attach(loop)
|
36
|
+
schedule_write if !@_write_buffer.empty?
|
37
|
+
self
|
38
|
+
end
|
35
39
|
|
36
40
|
# Detach from the event loop
|
37
|
-
def detach
|
41
|
+
def detach
|
42
|
+
# TODO should these detect write buffers, as well?
|
43
|
+
@_read_watcher.detach
|
44
|
+
self
|
45
|
+
end
|
38
46
|
|
39
47
|
# Enable the watcher
|
40
|
-
def enable
|
48
|
+
def enable
|
49
|
+
@_read_watcher.enable
|
50
|
+
self
|
51
|
+
end
|
41
52
|
|
42
53
|
# Disable the watcher
|
43
|
-
def disable
|
54
|
+
def disable
|
55
|
+
@_read_watcher.disable
|
56
|
+
self
|
57
|
+
end
|
44
58
|
|
45
59
|
# Is the watcher attached?
|
46
|
-
def attached
|
60
|
+
def attached?
|
61
|
+
@_read_watcher.attached?
|
62
|
+
end
|
47
63
|
|
48
64
|
# Is the watcher enabled?
|
49
|
-
def enabled
|
65
|
+
def enabled?
|
66
|
+
@_read_watcher.enabled?
|
67
|
+
end
|
50
68
|
|
51
69
|
# Obtain the event loop associated with this object
|
52
|
-
def evloop
|
70
|
+
def evloop
|
71
|
+
@_read_watcher.evloop
|
72
|
+
end
|
53
73
|
|
54
74
|
#
|
55
75
|
# Callbacks for asynchronous events
|
@@ -136,7 +156,7 @@ module Coolio
|
|
136
156
|
# Schedule a write to be performed when the IO object becomes writable
|
137
157
|
def schedule_write
|
138
158
|
return unless @_io # this would mean 'we are still pre DNS here'
|
139
|
-
return unless attached? # this would mean 'currently unattached' -- ie still pre DNS, or just plain not attached, which is ok
|
159
|
+
return unless @_read_watcher.attached? # this would mean 'currently unattached' -- ie still pre DNS, or just plain not attached, which is ok
|
140
160
|
begin
|
141
161
|
enable_write_watcher
|
142
162
|
rescue IOError
|
@@ -167,8 +187,13 @@ module Coolio
|
|
167
187
|
end
|
168
188
|
|
169
189
|
# Configure IOWatcher event callbacks to call the method passed to #initialize
|
170
|
-
def on_readable
|
171
|
-
|
190
|
+
def on_readable
|
191
|
+
@coolio_io.__send__(:on_readable)
|
192
|
+
end
|
193
|
+
|
194
|
+
def on_writable
|
195
|
+
@coolio_io.__send__(:on_writable)
|
196
|
+
end
|
172
197
|
end
|
173
198
|
end
|
174
199
|
end
|
data/lib/cool.io/loop.rb
CHANGED
@@ -15,17 +15,9 @@ end
|
|
15
15
|
|
16
16
|
module Coolio
|
17
17
|
class Loop
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
def self.default
|
22
|
-
Thread.current._coolio_loop
|
23
|
-
end
|
24
|
-
else
|
25
|
-
# Retrieve the default event loop
|
26
|
-
def self.default
|
27
|
-
@@_coolio_loop ||= Coolio::Loop.new
|
28
|
-
end
|
18
|
+
# Retrieve the default event loop for the current thread
|
19
|
+
def self.default
|
20
|
+
Thread.current._coolio_loop
|
29
21
|
end
|
30
22
|
|
31
23
|
# Create a new Coolio::Loop
|
data/lib/cool.io/meta.rb
CHANGED
@@ -11,7 +11,7 @@ module Coolio
|
|
11
11
|
# an event to occur before the current watcher can be used in earnest,
|
12
12
|
# such as making an outgoing TCP connection.
|
13
13
|
def watcher_delegate(proxy_var)
|
14
|
-
%w{attach detach enable disable}.each do |method|
|
14
|
+
%w{attach attached? detach enable disable}.each do |method|
|
15
15
|
module_eval <<-EOD
|
16
16
|
def #{method}(*args)
|
17
17
|
if defined? #{proxy_var} and #{proxy_var}
|
data/lib/cool.io/version.rb
CHANGED
data/spec/async_watcher_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require File.expand_path('../spec_helper', __FILE__)
|
|
2
2
|
require 'tempfile'
|
3
3
|
require 'fcntl'
|
4
4
|
|
5
|
-
describe Cool.io::AsyncWatcher, :env => :
|
5
|
+
describe Cool.io::AsyncWatcher, :env => :exclude_win do
|
6
6
|
|
7
7
|
it "does not signal on spurious wakeups" do
|
8
8
|
aw = Cool.io::AsyncWatcher.new
|
data/spec/spec_helper.rb
CHANGED
data/spec/tcp_server_spec.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Coolio::TCPSocket do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@server = TCPServer.new('127.0.0.1', 0)
|
7
|
+
@host = @server.addr[3]
|
8
|
+
@port = @server.addr[1]
|
9
|
+
end
|
10
|
+
|
11
|
+
after :each do
|
12
|
+
@server.close
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#close' do
|
16
|
+
|
17
|
+
it 'detaches all watchers on #close before loop#run' do
|
18
|
+
reactor = Coolio::Loop.new
|
19
|
+
client = Coolio::TCPSocket.connect(@host, @port)
|
20
|
+
reactor.attach(client)
|
21
|
+
client.close
|
22
|
+
reactor.watchers.size.should == 0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
data/spec/unix_listener_spec.rb
CHANGED
data/spec/unix_server_spec.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cool.io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
5
|
-
prerelease:
|
4
|
+
version: 1.2.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Tony Arcieri
|
@@ -10,54 +9,48 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2014-
|
12
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rake-compiler
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- - ~>
|
18
|
+
- - "~>"
|
21
19
|
- !ruby/object:Gem::Version
|
22
20
|
version: 0.8.3
|
23
21
|
type: :development
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- - ~>
|
25
|
+
- - "~>"
|
29
26
|
- !ruby/object:Gem::Version
|
30
27
|
version: 0.8.3
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: rspec
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- -
|
32
|
+
- - ">="
|
37
33
|
- !ruby/object:Gem::Version
|
38
34
|
version: 2.13.0
|
39
35
|
type: :development
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- -
|
39
|
+
- - ">="
|
45
40
|
- !ruby/object:Gem::Version
|
46
41
|
version: 2.13.0
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: rdoc
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
|
-
- -
|
46
|
+
- - ">="
|
53
47
|
- !ruby/object:Gem::Version
|
54
48
|
version: 3.6.0
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
|
-
- -
|
53
|
+
- - ">="
|
61
54
|
- !ruby/object:Gem::Version
|
62
55
|
version: 3.6.0
|
63
56
|
description: Cool.io provides a high performance event framework for Ruby which uses
|
@@ -72,9 +65,9 @@ extensions:
|
|
72
65
|
- ext/iobuffer/extconf.rb
|
73
66
|
extra_rdoc_files: []
|
74
67
|
files:
|
75
|
-
- .gitignore
|
76
|
-
- .rspec
|
77
|
-
- .travis.yml
|
68
|
+
- ".gitignore"
|
69
|
+
- ".rspec"
|
70
|
+
- ".travis.yml"
|
78
71
|
- CHANGES.md
|
79
72
|
- Gemfile
|
80
73
|
- LICENSE
|
@@ -149,38 +142,32 @@ files:
|
|
149
142
|
- spec/spec_helper.rb
|
150
143
|
- spec/stat_watcher_spec.rb
|
151
144
|
- spec/tcp_server_spec.rb
|
145
|
+
- spec/tcp_socket_spec.rb
|
152
146
|
- spec/timer_watcher_spec.rb
|
153
147
|
- spec/unix_listener_spec.rb
|
154
148
|
- spec/unix_server_spec.rb
|
155
149
|
homepage: http://coolio.github.com
|
156
150
|
licenses: []
|
151
|
+
metadata: {}
|
157
152
|
post_install_message:
|
158
153
|
rdoc_options: []
|
159
154
|
require_paths:
|
160
155
|
- lib
|
161
156
|
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
-
none: false
|
163
157
|
requirements:
|
164
|
-
- -
|
158
|
+
- - ">="
|
165
159
|
- !ruby/object:Gem::Version
|
166
160
|
version: '0'
|
167
|
-
segments:
|
168
|
-
- 0
|
169
|
-
hash: -2054079521512211321
|
170
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
-
none: false
|
172
162
|
requirements:
|
173
|
-
- -
|
163
|
+
- - ">="
|
174
164
|
- !ruby/object:Gem::Version
|
175
165
|
version: '0'
|
176
|
-
segments:
|
177
|
-
- 0
|
178
|
-
hash: -2054079521512211321
|
179
166
|
requirements: []
|
180
167
|
rubyforge_project:
|
181
|
-
rubygems_version:
|
168
|
+
rubygems_version: 2.2.2
|
182
169
|
signing_key:
|
183
|
-
specification_version:
|
170
|
+
specification_version: 4
|
184
171
|
summary: A cool framework for doing high performance I/O in Ruby
|
185
172
|
test_files:
|
186
173
|
- spec/async_watcher_spec.rb
|
@@ -188,6 +175,7 @@ test_files:
|
|
188
175
|
- spec/spec_helper.rb
|
189
176
|
- spec/stat_watcher_spec.rb
|
190
177
|
- spec/tcp_server_spec.rb
|
178
|
+
- spec/tcp_socket_spec.rb
|
191
179
|
- spec/timer_watcher_spec.rb
|
192
180
|
- spec/unix_listener_spec.rb
|
193
181
|
- spec/unix_server_spec.rb
|