celluloid-io 0.16.0.pre → 0.16.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +4 -3
- data/.travis.yml +3 -3
- data/CHANGES.md +4 -2
- data/lib/celluloid/io/dns_resolver.rb +10 -9
- data/lib/celluloid/io/reactor.rb +85 -12
- data/lib/celluloid/io/tcp_socket.rb +1 -1
- data/lib/celluloid/io/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2a7a8f3f757ee68efb8e2b599d2fb5d64ef17df
|
4
|
+
data.tar.gz: 30658a13260ae50f648c61faae35bfb157d84fb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a49e8683143d29b0ed3647ae1f65ec7c5c30272de50f45476d2e2204bc9b5f91074024939d2cce6971f650f0b029debf0417d01ded1d34e6a85812dd764bc38
|
7
|
+
data.tar.gz: f1f529f48d7c559721ad32a4f857bb35e04041892b021cdbd3578f2a55a87e8ba1ebb7960616b0bb2dc02bf0f24bab5ba40fe8dbc6578b6add2688385f395945
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
@@ -2,18 +2,18 @@ script: rake ci
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
|
-
- 2.1.
|
5
|
+
- 2.1.1
|
6
6
|
- ruby-head
|
7
7
|
- jruby
|
8
8
|
- jruby-head
|
9
|
-
- rbx
|
9
|
+
- rbx-2
|
10
10
|
|
11
11
|
matrix:
|
12
12
|
allow_failures:
|
13
13
|
- rvm: ruby-head
|
14
14
|
- rvm: jruby
|
15
15
|
- rvm: jruby-head
|
16
|
-
- rvm: rbx
|
16
|
+
- rvm: rbx-2
|
17
17
|
|
18
18
|
notifications:
|
19
19
|
irc: "irc.freenode.org#celluloid"
|
data/CHANGES.md
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
require 'ipaddr'
|
1
2
|
require 'resolv'
|
2
3
|
|
3
4
|
module Celluloid
|
4
5
|
module IO
|
5
6
|
# Asynchronous DNS resolver using Celluloid::IO::UDPSocket
|
6
7
|
class DNSResolver
|
7
|
-
|
8
|
-
|
8
|
+
# Maximum UDP packet we'll accept
|
9
|
+
MAX_PACKET_SIZE = 512
|
10
|
+
DNS_PORT = 53
|
9
11
|
|
10
12
|
@mutex = Mutex.new
|
11
13
|
@identifier = 1
|
@@ -14,19 +16,18 @@ module Celluloid
|
|
14
16
|
@mutex.synchronize { @identifier = (@identifier + 1) & 0xFFFF }
|
15
17
|
end
|
16
18
|
|
17
|
-
def self.nameservers
|
18
|
-
|
19
|
+
def self.nameservers
|
20
|
+
Resolv::DNS::Config.default_config_hash[:nameserver]
|
19
21
|
end
|
20
22
|
|
21
23
|
def initialize
|
22
24
|
@nameservers = self.class.nameservers
|
23
25
|
|
24
|
-
|
25
|
-
@server = @nameservers.first
|
26
|
+
@server = IPAddr.new(@nameservers.sample)
|
26
27
|
|
27
28
|
# The non-blocking secret sauce is here, as this is actually a
|
28
29
|
# Celluloid::IO::UDPSocket
|
29
|
-
@socket = UDPSocket.new
|
30
|
+
@socket = UDPSocket.new(@server.family)
|
30
31
|
end
|
31
32
|
|
32
33
|
def resolve(hostname)
|
@@ -38,8 +39,8 @@ module Celluloid
|
|
38
39
|
end
|
39
40
|
|
40
41
|
query = build_query(hostname)
|
41
|
-
@socket.send query.encode, 0, @server, DNS_PORT
|
42
|
-
data, _ = @socket.recvfrom(
|
42
|
+
@socket.send query.encode, 0, @server.to_s, DNS_PORT
|
43
|
+
data, _ = @socket.recvfrom(MAX_PACKET_SIZE)
|
43
44
|
response = Resolv::DNS::Message.decode(data)
|
44
45
|
|
45
46
|
addrs = []
|
data/lib/celluloid/io/reactor.rb
CHANGED
@@ -14,20 +14,25 @@ module Celluloid
|
|
14
14
|
|
15
15
|
def initialize
|
16
16
|
@selector = NIO::Selector.new
|
17
|
+
@monitors = {}
|
17
18
|
end
|
18
19
|
|
19
20
|
# Wait for the given IO object to become readable
|
20
21
|
def wait_readable(io)
|
21
|
-
wait io
|
22
|
+
wait io do |monitor|
|
23
|
+
monitor.wait_readable
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
# Wait for the given IO object to become writable
|
25
28
|
def wait_writable(io)
|
26
|
-
wait io
|
29
|
+
wait io do |monitor|
|
30
|
+
monitor.wait_writable
|
31
|
+
end
|
27
32
|
end
|
28
33
|
|
29
34
|
# Wait for the given IO operation to complete
|
30
|
-
def wait(io
|
35
|
+
def wait(io)
|
31
36
|
# zomg ugly type conversion :(
|
32
37
|
unless io.is_a?(::IO) or io.is_a?(OpenSSL::SSL::SSLSocket)
|
33
38
|
if io.respond_to? :to_io
|
@@ -39,21 +44,89 @@ module Celluloid
|
|
39
44
|
raise TypeError, "can't convert #{io.class} into IO" unless io.is_a?(::IO)
|
40
45
|
end
|
41
46
|
|
42
|
-
monitor = @
|
43
|
-
|
44
|
-
|
47
|
+
unless monitor = @monitors[io]
|
48
|
+
monitor = Monitor.new(@selector, io)
|
49
|
+
@monitors[io] = monitor
|
50
|
+
end
|
51
|
+
|
52
|
+
yield monitor
|
45
53
|
end
|
46
54
|
|
47
55
|
# Run the reactor, waiting for events or wakeup signal
|
48
56
|
def run_once(timeout = nil)
|
49
57
|
@selector.select(timeout) do |monitor|
|
50
|
-
|
51
|
-
|
58
|
+
monitor.value.resume
|
59
|
+
end
|
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)
|
52
123
|
|
53
|
-
if task
|
54
|
-
task.
|
55
|
-
|
56
|
-
|
124
|
+
if task
|
125
|
+
if task.running?
|
126
|
+
task.resume
|
127
|
+
else
|
128
|
+
raise "reactor attempted to resume a dead task"
|
129
|
+
end
|
57
130
|
end
|
58
131
|
end
|
59
132
|
end
|
@@ -8,7 +8,7 @@ module Celluloid
|
|
8
8
|
extend Forwardable
|
9
9
|
|
10
10
|
def_delegators :@socket, :read_nonblock, :write_nonblock, :close, :close_read, :close_write, :closed?
|
11
|
-
def_delegators :@socket, :addr, :peeraddr, :setsockopt
|
11
|
+
def_delegators :@socket, :addr, :peeraddr, :setsockopt, :getsockname
|
12
12
|
|
13
13
|
# Open a TCP socket, yielding it to the given block and closing it
|
14
14
|
# automatically when done (if a block is given)
|
data/lib/celluloid/io/version.rb
CHANGED
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.0.
|
4
|
+
version: 0.16.0.pre2
|
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-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
version: 1.3.1
|
185
185
|
requirements: []
|
186
186
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.2.
|
187
|
+
rubygems_version: 2.2.2
|
188
188
|
signing_key:
|
189
189
|
specification_version: 4
|
190
190
|
summary: Celluloid::IO allows you to monitor multiple IO objects within a Celluloid
|
@@ -206,3 +206,4 @@ test_files:
|
|
206
206
|
- spec/fixtures/server.crt
|
207
207
|
- spec/fixtures/server.key
|
208
208
|
- spec/spec_helper.rb
|
209
|
+
has_rdoc:
|