celluloid-io 0.16.0 → 0.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/celluloid-io.gemspec +1 -1
- data/lib/celluloid/io/dns_resolver.rb +3 -1
- data/lib/celluloid/io/reactor.rb +12 -85
- data/lib/celluloid/io/ssl_socket.rb +1 -0
- data/lib/celluloid/io/tcp_server.rb +5 -1
- data/lib/celluloid/io/udp_socket.rb +1 -1
- data/lib/celluloid/io/version.rb +1 -1
- data/spec/celluloid/io/.dns_resolver_spec.rb.swp +0 -0
- data/spec/celluloid/io/dns_resolver_spec.rb +12 -2
- data/spec/celluloid/io/tcp_server_spec.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a14112c061df1e593c0c40f73f6bbafbb937419
|
4
|
+
data.tar.gz: 2fc0714e1b2064a425105db7779ce83bbdb85508
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0853eb2f8d75efb7287a95ae81d74a2c619d7a7f79cce162110faafda75f4e41049bbf1134615b6abba5c14361a3e9dff69847ae199a9fa3f1898cd024033661
|
7
|
+
data.tar.gz: a195890888ace5714d9781c4683a6b23c4a6f3208cedaf9619c92520cf34a0ef1ee57c9bd2457a36d018ae3f433c83b23e69e5105579208570906d9167edf081
|
data/CHANGES.md
CHANGED
data/celluloid-io.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_dependency 'nio4r', '>= 1.0.0'
|
21
21
|
|
22
22
|
gem.add_development_dependency 'rake'
|
23
|
-
gem.add_development_dependency 'rspec'
|
23
|
+
gem.add_development_dependency 'rspec', '~> 2.14.0'
|
24
24
|
gem.add_development_dependency 'benchmark_suite'
|
25
25
|
gem.add_development_dependency 'guard-rspec'
|
26
26
|
gem.add_development_dependency 'rb-fsevent', '~> 0.9.1' if RUBY_PLATFORM =~ /darwin/
|
@@ -21,7 +21,9 @@ module Celluloid
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def initialize
|
24
|
-
|
24
|
+
# early return for edge case when there are no nameservers configured
|
25
|
+
# but we still want to be able to static lookups using #resolve_hostname
|
26
|
+
@nameservers = self.class.nameservers or return
|
25
27
|
|
26
28
|
@server = IPAddr.new(@nameservers.sample)
|
27
29
|
|
data/lib/celluloid/io/reactor.rb
CHANGED
@@ -14,25 +14,20 @@ module Celluloid
|
|
14
14
|
|
15
15
|
def initialize
|
16
16
|
@selector = NIO::Selector.new
|
17
|
-
@monitors = {}
|
18
17
|
end
|
19
18
|
|
20
19
|
# Wait for the given IO object to become readable
|
21
20
|
def wait_readable(io)
|
22
|
-
wait io
|
23
|
-
monitor.wait_readable
|
24
|
-
end
|
21
|
+
wait io, :r
|
25
22
|
end
|
26
23
|
|
27
24
|
# Wait for the given IO object to become writable
|
28
25
|
def wait_writable(io)
|
29
|
-
wait io
|
30
|
-
monitor.wait_writable
|
31
|
-
end
|
26
|
+
wait io, :w
|
32
27
|
end
|
33
28
|
|
34
29
|
# Wait for the given IO operation to complete
|
35
|
-
def wait(io)
|
30
|
+
def wait(io, set)
|
36
31
|
# zomg ugly type conversion :(
|
37
32
|
unless io.is_a?(::IO) or io.is_a?(OpenSSL::SSL::SSLSocket)
|
38
33
|
if io.respond_to? :to_io
|
@@ -44,89 +39,21 @@ module Celluloid
|
|
44
39
|
raise TypeError, "can't convert #{io.class} into IO" unless io.is_a?(::IO)
|
45
40
|
end
|
46
41
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
yield monitor
|
42
|
+
monitor = @selector.register(io, set)
|
43
|
+
monitor.value = Task.current
|
44
|
+
Task.suspend :iowait
|
53
45
|
end
|
54
46
|
|
55
47
|
# Run the reactor, waiting for events or wakeup signal
|
56
48
|
def run_once(timeout = nil)
|
57
49
|
@selector.select(timeout) do |monitor|
|
58
|
-
monitor.value
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
class Monitor
|
63
|
-
def initialize(selector, io)
|
64
|
-
@selector = selector
|
65
|
-
@io = io
|
66
|
-
@interests = {}
|
67
|
-
end
|
68
|
-
|
69
|
-
def wait_readable
|
70
|
-
wait :r
|
71
|
-
end
|
72
|
-
|
73
|
-
def wait_writable
|
74
|
-
wait :w
|
75
|
-
end
|
76
|
-
|
77
|
-
def wait(interest)
|
78
|
-
raise "Already waiting for #{interest.inspect}" if @interests.include?(interest)
|
79
|
-
@interests[interest] = Task.current
|
80
|
-
reregister
|
81
|
-
Task.suspend :iowait
|
82
|
-
end
|
83
|
-
|
84
|
-
def reregister
|
85
|
-
if @monitor
|
86
|
-
@monitor.close
|
87
|
-
@monitor = nil
|
88
|
-
end
|
89
|
-
|
90
|
-
if interests_symbol
|
91
|
-
@monitor = @selector.register(@io, interests_symbol)
|
92
|
-
@monitor.value = self
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def interests_symbol
|
97
|
-
case @interests.keys
|
98
|
-
when [:r]
|
99
|
-
:r
|
100
|
-
when [:w]
|
101
|
-
:w
|
102
|
-
when [:r, :w]
|
103
|
-
:rw
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def resume
|
108
|
-
raise "No monitor" unless @monitor
|
109
|
-
|
110
|
-
if @monitor.readable?
|
111
|
-
resume_for :r
|
112
|
-
end
|
113
|
-
|
114
|
-
if @monitor.writable?
|
115
|
-
resume_for :w
|
116
|
-
end
|
117
|
-
|
118
|
-
reregister
|
119
|
-
end
|
120
|
-
|
121
|
-
def resume_for(interest)
|
122
|
-
task = @interests.delete(interest)
|
50
|
+
task = monitor.value
|
51
|
+
monitor.close
|
123
52
|
|
124
|
-
if task
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
raise "reactor attempted to resume a dead task"
|
129
|
-
end
|
53
|
+
if task.running?
|
54
|
+
task.resume
|
55
|
+
else
|
56
|
+
Logger.warn("reactor attempted to resume a dead task")
|
130
57
|
end
|
131
58
|
end
|
132
59
|
end
|
@@ -8,7 +8,11 @@ module Celluloid
|
|
8
8
|
def_delegators :@server, :listen, :sysaccept, :close, :closed?, :addr, :setsockopt
|
9
9
|
|
10
10
|
def initialize(hostname_or_port, port = nil)
|
11
|
-
|
11
|
+
if port.nil?
|
12
|
+
@server = ::TCPServer.new(hostname_or_port)
|
13
|
+
else
|
14
|
+
@server = ::TCPServer.new(hostname_or_port, port)
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
def accept
|
@@ -3,7 +3,7 @@ module Celluloid
|
|
3
3
|
# UDPSockets with combined blocking and evented support
|
4
4
|
class UDPSocket
|
5
5
|
extend Forwardable
|
6
|
-
def_delegators :@socket, :bind, :connect, :send, :recvfrom_nonblock, :close, :closed?
|
6
|
+
def_delegators :@socket, :addr, :bind, :connect, :send, :recvfrom_nonblock, :close, :closed?
|
7
7
|
|
8
8
|
def initialize(address_family = ::Socket::AF_INET)
|
9
9
|
@socket = ::UDPSocket.new(address_family)
|
data/lib/celluloid/io/version.rb
CHANGED
Binary file
|
@@ -2,14 +2,24 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Celluloid::IO::DNSResolver do
|
4
4
|
describe '#resolve' do
|
5
|
+
it 'resolves hostnames statically from hosts file without nameservers' do
|
6
|
+
# /etc/resolv.conf doesn't exist on Mac OSX when no networking is
|
7
|
+
# disabled, thus .nameservers would return nil
|
8
|
+
Celluloid::IO::DNSResolver.should_receive(:nameservers).at_most(:once) { nil }
|
9
|
+
resolver = Celluloid::IO::DNSResolver.new
|
10
|
+
resolver.resolve('localhost').should eq Resolv::IPv4.create("127.0.0.1")
|
11
|
+
end
|
12
|
+
|
5
13
|
it 'resolves hostnames' do
|
6
14
|
resolver = Celluloid::IO::DNSResolver.new
|
7
15
|
resolver.resolve('localhost').should eq Resolv::IPv4.create("127.0.0.1")
|
8
16
|
end
|
9
17
|
|
10
18
|
it "resolves domain names" do
|
11
|
-
resolver
|
12
|
-
resolver.resolve("celluloid.io")
|
19
|
+
resolver = Celluloid::IO::DNSResolver.new
|
20
|
+
nameservers = resolver.resolve("celluloid.io")
|
21
|
+
expect(nameservers).to include Resolv::IPv4.create("104.28.21.100")
|
22
|
+
expect(nameservers).to include Resolv::IPv4.create("104.28.20.100")
|
13
23
|
end
|
14
24
|
|
15
25
|
it "resolves CNAME responses" do
|
@@ -5,7 +5,7 @@ describe Celluloid::IO::TCPServer do
|
|
5
5
|
let(:payload) { 'ohai' }
|
6
6
|
|
7
7
|
it "can be initialized without a host" do
|
8
|
-
expect{
|
8
|
+
expect { Celluloid::IO::TCPServer.new(2000).close }.to_not raise_error
|
9
9
|
end
|
10
10
|
|
11
11
|
context "inside Celluloid::IO" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celluloid-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.14.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.14.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: benchmark_suite
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/celluloid/io/version.rb
|
147
147
|
- log/.gitignore
|
148
148
|
- logo.png
|
149
|
+
- spec/celluloid/io/.dns_resolver_spec.rb.swp
|
149
150
|
- spec/celluloid/io/actor_spec.rb
|
150
151
|
- spec/celluloid/io/dns_resolver_spec.rb
|
151
152
|
- spec/celluloid/io/mailbox_spec.rb
|
@@ -190,6 +191,7 @@ specification_version: 4
|
|
190
191
|
summary: Celluloid::IO allows you to monitor multiple IO objects within a Celluloid
|
191
192
|
actor
|
192
193
|
test_files:
|
194
|
+
- spec/celluloid/io/.dns_resolver_spec.rb.swp
|
193
195
|
- spec/celluloid/io/actor_spec.rb
|
194
196
|
- spec/celluloid/io/dns_resolver_spec.rb
|
195
197
|
- spec/celluloid/io/mailbox_spec.rb
|
@@ -206,4 +208,3 @@ test_files:
|
|
206
208
|
- spec/fixtures/server.crt
|
207
209
|
- spec/fixtures/server.key
|
208
210
|
- spec/spec_helper.rb
|
209
|
-
has_rdoc:
|