celluloid-io 0.12.1 → 0.13.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +6 -5
- data/CHANGES.md +5 -3
- data/Gemfile +1 -1
- data/Guardfile +5 -0
- data/README.md +32 -0
- data/benchmarks/actor.rb +25 -5
- data/celluloid-io.gemspec +4 -2
- data/examples/echo_server.rb +1 -1
- data/examples/echo_unix_client.rb +28 -0
- data/examples/echo_unix_server.rb +43 -0
- data/lib/celluloid/io/common_methods.rb +13 -9
- data/lib/celluloid/io/mailbox.rb +3 -3
- data/lib/celluloid/io/reactor.rb +2 -2
- data/lib/celluloid/io/ssl_server.rb +36 -0
- data/lib/celluloid/io/ssl_socket.rb +39 -0
- data/lib/celluloid/io/tcp_server.rb +10 -3
- data/lib/celluloid/io/tcp_socket.rb +0 -2
- data/lib/celluloid/io/udp_socket.rb +1 -1
- data/lib/celluloid/io/unix_server.rb +44 -0
- data/lib/celluloid/io/unix_socket.rb +40 -0
- data/lib/celluloid/io/version.rb +1 -1
- data/lib/celluloid/io.rb +6 -1
- data/log/.gitignore +1 -0
- data/spec/celluloid/io/ssl_server_spec.rb +91 -0
- data/spec/celluloid/io/ssl_socket_spec.rb +189 -0
- data/spec/celluloid/io/tcp_server_spec.rb +1 -1
- data/spec/celluloid/io/tcp_socket_spec.rb +66 -3
- data/spec/celluloid/io/udp_socket_spec.rb +1 -1
- data/spec/celluloid/io/unix_server_spec.rb +70 -0
- data/spec/celluloid/io/unix_socket_spec.rb +140 -0
- data/spec/fixtures/client.crt +22 -0
- data/spec/fixtures/client.key +27 -0
- data/spec/fixtures/server.crt +22 -0
- data/spec/fixtures/server.key +27 -0
- data/spec/spec_helper.rb +41 -4
- metadata +106 -54
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Celluloid::IO::SSLServer do
|
4
|
+
let(:client_cert) { OpenSSL::X509::Certificate.new fixture_dir.join("client.crt").read }
|
5
|
+
let(:client_key) { OpenSSL::PKey::RSA.new fixture_dir.join("client.key").read }
|
6
|
+
let(:client_context) do
|
7
|
+
OpenSSL::SSL::SSLContext.new.tap do |context|
|
8
|
+
context.cert = client_cert
|
9
|
+
context.key = client_key
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:server_cert) { OpenSSL::X509::Certificate.new fixture_dir.join("server.crt").read }
|
14
|
+
let(:server_key) { OpenSSL::PKey::RSA.new fixture_dir.join("server.key").read }
|
15
|
+
let(:server_context) do
|
16
|
+
OpenSSL::SSL::SSLContext.new.tap do |context|
|
17
|
+
context.cert = server_cert
|
18
|
+
context.key = server_key
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#accept" do
|
23
|
+
let(:payload) { 'ohai' }
|
24
|
+
|
25
|
+
context "inside Celluloid::IO" do
|
26
|
+
it "should be evented" do
|
27
|
+
with_ssl_server do |subject|
|
28
|
+
within_io_actor { subject.evented? }.should be_true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "accepts a connection and returns a Celluloid::IO::SSLSocket" do
|
33
|
+
with_ssl_server do |subject|
|
34
|
+
thread = Thread.new do
|
35
|
+
raw = TCPSocket.new(example_addr, example_ssl_port)
|
36
|
+
ssl = OpenSSL::SSL::SSLSocket.new(raw, client_context).connect
|
37
|
+
end
|
38
|
+
peer = within_io_actor { subject.accept }
|
39
|
+
peer.should be_a Celluloid::IO::SSLSocket
|
40
|
+
|
41
|
+
client = thread.value
|
42
|
+
client.write payload
|
43
|
+
peer.read(payload.size).should eq payload
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "outside Celluloid::IO" do
|
49
|
+
it "should be blocking" do
|
50
|
+
with_ssl_server do |subject|
|
51
|
+
subject.should_not be_evented
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "accepts a connection and returns a Celluloid::IO::SSLSocket" do
|
56
|
+
with_ssl_server do |subject|
|
57
|
+
thread = Thread.new do
|
58
|
+
raw = TCPSocket.new(example_addr, example_ssl_port)
|
59
|
+
ssl = OpenSSL::SSL::SSLSocket.new(raw, client_context).connect
|
60
|
+
end
|
61
|
+
peer = subject.accept
|
62
|
+
peer.should be_a Celluloid::IO::SSLSocket
|
63
|
+
|
64
|
+
client = thread.value
|
65
|
+
client.write payload
|
66
|
+
peer.read(payload.size).should eq payload
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#initialize" do
|
73
|
+
it "should auto-wrap a raw ::TCPServer" do
|
74
|
+
raw_server = ::TCPServer.new(example_addr, example_ssl_port)
|
75
|
+
with_ssl_server(raw_server) do |ssl_server|
|
76
|
+
ssl_server.tcp_server.class.should == Celluloid::IO::TCPServer
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def with_ssl_server(raw_server = nil)
|
82
|
+
raw_server ||= Celluloid::IO::TCPServer.new(example_addr, example_ssl_port)
|
83
|
+
server = Celluloid::IO::SSLServer.new(raw_server, server_context)
|
84
|
+
begin
|
85
|
+
yield server
|
86
|
+
ensure
|
87
|
+
server.close
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,189 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
describe Celluloid::IO::SSLSocket do
|
5
|
+
let(:request) { 'ping' }
|
6
|
+
let(:response) { 'pong' }
|
7
|
+
|
8
|
+
let(:client_cert) { OpenSSL::X509::Certificate.new fixture_dir.join("client.crt").read }
|
9
|
+
let(:client_key) { OpenSSL::PKey::RSA.new fixture_dir.join("client.key").read }
|
10
|
+
let(:client_context) do
|
11
|
+
OpenSSL::SSL::SSLContext.new.tap do |context|
|
12
|
+
context.cert = client_cert
|
13
|
+
context.key = client_key
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:client) { TCPSocket.new example_addr, example_ssl_port }
|
18
|
+
let(:ssl_client) { Celluloid::IO::SSLSocket.new client, client_context }
|
19
|
+
|
20
|
+
let(:server_cert) { OpenSSL::X509::Certificate.new fixture_dir.join("server.crt").read }
|
21
|
+
let(:server_key) { OpenSSL::PKey::RSA.new fixture_dir.join("server.key").read }
|
22
|
+
let(:server_context) do
|
23
|
+
OpenSSL::SSL::SSLContext.new.tap do |context|
|
24
|
+
context.cert = server_cert
|
25
|
+
context.key = server_key
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:server) { TCPServer.new example_addr, example_ssl_port }
|
30
|
+
let(:ssl_server) { OpenSSL::SSL::SSLServer.new server, server_context }
|
31
|
+
let(:server_thread) do
|
32
|
+
Thread.new { ssl_server.accept }.tap do |thread|
|
33
|
+
Thread.pass while thread.status && thread.status != "sleep"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:celluloid_server) { Celluloid::IO::TCPServer.new example_addr, example_ssl_port }
|
38
|
+
let(:raw_server_thread) do
|
39
|
+
Thread.new { celluloid_server.accept }.tap do |thread|
|
40
|
+
Thread.pass while thread.status && thread.status != "sleep"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "inside Celluloid::IO" do
|
45
|
+
it "connects to SSL servers over TCP" do
|
46
|
+
with_ssl_sockets do |ssl_client, ssl_peer|
|
47
|
+
within_io_actor do
|
48
|
+
ssl_peer << request
|
49
|
+
ssl_client.read(request.size).should == request
|
50
|
+
|
51
|
+
ssl_client << response
|
52
|
+
ssl_peer.read(response.size).should == response
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "starts SSL on a connected TCP socket" do
|
58
|
+
with_raw_sockets do |client, peer|
|
59
|
+
within_io_actor do
|
60
|
+
peer << request
|
61
|
+
client.read(request.size).should == request
|
62
|
+
|
63
|
+
client << response
|
64
|
+
peer.read(response.size).should == response
|
65
|
+
|
66
|
+
# now that we've written bytes, upgrade to SSL
|
67
|
+
client_thread = Thread.new { OpenSSL::SSL::SSLSocket.new(client).connect }
|
68
|
+
ssl_peer = Celluloid::IO::SSLSocket.new peer, server_context
|
69
|
+
ssl_peer.should == ssl_peer.accept
|
70
|
+
ssl_client = client_thread.value
|
71
|
+
|
72
|
+
ssl_peer << request
|
73
|
+
ssl_client.read(request.size).should == request
|
74
|
+
|
75
|
+
ssl_client << response
|
76
|
+
ssl_peer.read(response.size).should == response
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "outside Celluloid::IO" do
|
83
|
+
it "connects to SSL servers over TCP" do
|
84
|
+
with_ssl_sockets do |ssl_client, ssl_peer|
|
85
|
+
ssl_peer << request
|
86
|
+
ssl_client.read(request.size).should == request
|
87
|
+
|
88
|
+
ssl_client << response
|
89
|
+
ssl_peer.read(response.size).should == response
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "starts SSL on a connected TCP socket" do
|
94
|
+
with_raw_sockets do |client, peer|
|
95
|
+
peer << request
|
96
|
+
client.read(request.size).should == request
|
97
|
+
|
98
|
+
client << response
|
99
|
+
peer.read(response.size).should == response
|
100
|
+
|
101
|
+
# now that we've written bytes, upgrade to SSL
|
102
|
+
client_thread = Thread.new { OpenSSL::SSL::SSLSocket.new(client).connect }
|
103
|
+
ssl_peer = Celluloid::IO::SSLSocket.new peer, server_context
|
104
|
+
ssl_peer.should == ssl_peer.accept
|
105
|
+
ssl_client = client_thread.value
|
106
|
+
|
107
|
+
ssl_peer << request
|
108
|
+
ssl_client.read(request.size).should == request
|
109
|
+
|
110
|
+
ssl_client << response
|
111
|
+
ssl_peer.read(response.size).should == response
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it "knows its cert" do
|
117
|
+
# FIXME: seems bad? o_O
|
118
|
+
pending "wtf is wrong with this on JRuby" if defined? JRUBY_VERSION
|
119
|
+
with_ssl_sockets do |ssl_client|
|
120
|
+
ssl_client.cert.to_der.should == client_cert.to_der
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
it "knows its peer_cert" do
|
125
|
+
with_ssl_sockets do |ssl_client|
|
126
|
+
ssl_client.peer_cert.to_der.should == ssl_client.to_io.peer_cert.to_der
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it "knows its peer_cert_chain" do
|
131
|
+
with_ssl_sockets do |ssl_client|
|
132
|
+
ssl_client.peer_cert_chain.zip(ssl_client.to_io.peer_cert_chain).map do |c1, c2|
|
133
|
+
c1.to_der == c2.to_der
|
134
|
+
end.should be_all
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it "knows its cipher" do
|
139
|
+
with_ssl_sockets do |ssl_client|
|
140
|
+
ssl_client.cipher.should == ssl_client.to_io.cipher
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
it "knows its client_ca" do
|
145
|
+
# jruby-openssl does not implement this method
|
146
|
+
pending "jruby-openssl support" if defined? JRUBY_VERSION
|
147
|
+
|
148
|
+
with_ssl_sockets do |ssl_client|
|
149
|
+
ssl_client.client_ca.should == ssl_client.to_io.client_ca
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
it "verifies peer certificates" do
|
154
|
+
# FIXME: JRuby seems to be giving the wrong result here o_O
|
155
|
+
pending "jruby-openssl support" if defined? JRUBY_VERSION
|
156
|
+
|
157
|
+
with_ssl_sockets do |ssl_client, ssl_peer|
|
158
|
+
ssl_client.verify_result.should == OpenSSL::X509::V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def with_ssl_sockets
|
163
|
+
thread = server_thread
|
164
|
+
ssl_client.connect
|
165
|
+
|
166
|
+
begin
|
167
|
+
ssl_peer = thread.value
|
168
|
+
yield ssl_client, ssl_peer
|
169
|
+
ensure
|
170
|
+
ssl_server.close
|
171
|
+
ssl_client.close
|
172
|
+
ssl_peer.close
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def with_raw_sockets
|
177
|
+
server_thread = raw_server_thread
|
178
|
+
raw_client = client
|
179
|
+
|
180
|
+
begin
|
181
|
+
raw_peer = server_thread.value
|
182
|
+
yield raw_client, raw_peer
|
183
|
+
ensure
|
184
|
+
celluloid_server.close
|
185
|
+
raw_client.close
|
186
|
+
raw_peer.close
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -25,14 +25,14 @@ describe Celluloid::IO::TCPSocket do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "read complete payload when nil size is given to #read" do
|
28
|
-
|
28
|
+
with_connected_sockets do |subject, peer|
|
29
29
|
peer << payload
|
30
30
|
within_io_actor { subject.read(nil) }.should eq payload
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
it "read complete payload when no size is given to #read" do
|
35
|
-
|
35
|
+
with_connected_sockets do |subject, peer|
|
36
36
|
peer << payload
|
37
37
|
within_io_actor { subject.read }.should eq payload
|
38
38
|
end
|
@@ -45,6 +45,13 @@ describe Celluloid::IO::TCPSocket do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
it "reads data in ASCII-8BIT encoding" do
|
49
|
+
with_connected_sockets do |subject, peer|
|
50
|
+
peer << payload
|
51
|
+
within_io_actor { subject.read(payload.size).encoding }.should eq Encoding::ASCII_8BIT
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
48
55
|
it "reads partial data" do
|
49
56
|
with_connected_sockets do |subject, peer|
|
50
57
|
peer << payload * 2
|
@@ -52,15 +59,71 @@ describe Celluloid::IO::TCPSocket do
|
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
62
|
+
it "reads partial data in ASCII-8BIT encoding" do
|
63
|
+
with_connected_sockets do |subject, peer|
|
64
|
+
peer << payload * 2
|
65
|
+
within_io_actor { subject.readpartial(payload.size).encoding }.should eq Encoding::ASCII_8BIT
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
55
69
|
it "writes data" do
|
56
70
|
with_connected_sockets do |subject, peer|
|
57
71
|
within_io_actor { subject << payload }
|
58
72
|
peer.read(payload.size).should eq payload
|
59
73
|
end
|
60
74
|
end
|
75
|
+
|
76
|
+
it "raises Errno::ECONNREFUSED when the connection is refused" do
|
77
|
+
expect {
|
78
|
+
within_io_actor { ::TCPSocket.new(example_addr, example_port) }
|
79
|
+
}.to raise_error(Errno::ECONNREFUSED)
|
80
|
+
end
|
81
|
+
|
82
|
+
context "readpartial" do
|
83
|
+
it "raises EOFError when reading from a closed socket" do
|
84
|
+
with_connected_sockets do |subject, peer|
|
85
|
+
peer.close
|
86
|
+
expect {
|
87
|
+
within_io_actor { subject.readpartial(payload.size) }
|
88
|
+
}.to raise_error(EOFError)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "raises IOError when active sockets are closed across threads" do
|
93
|
+
pending "not implemented :("
|
94
|
+
|
95
|
+
with_connected_sockets do |subject, peer|
|
96
|
+
actor = ExampleActor.new
|
97
|
+
begin
|
98
|
+
read_future = actor.future.wrap do
|
99
|
+
subject.readpartial(payload.size)
|
100
|
+
end
|
101
|
+
sleep 0.1
|
102
|
+
subject.close
|
103
|
+
expect { read_future.value 0.25 }.to raise_error(IOError)
|
104
|
+
ensure
|
105
|
+
actor.terminate if actor.alive?
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "raises IOError when partial reading from a socket the peer closed" do
|
111
|
+
with_connected_sockets do |subject, peer|
|
112
|
+
actor = ExampleActor.new
|
113
|
+
begin
|
114
|
+
actor.async.wrap { sleep 0.01; peer.close }
|
115
|
+
expect do
|
116
|
+
within_io_actor { subject.readpartial(payload.size) }
|
117
|
+
end.to raise_error(IOError)
|
118
|
+
ensure
|
119
|
+
actor.terminate if actor.alive?
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
61
124
|
end
|
62
125
|
|
63
|
-
context "
|
126
|
+
context "outside Celluloid::IO" do
|
64
127
|
it "connects to TCP servers" do
|
65
128
|
server = ::TCPServer.new example_addr, example_port
|
66
129
|
thread = Thread.new { server.accept }
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Celluloid::IO::UNIXServer do
|
4
|
+
describe "#accept" do
|
5
|
+
before do
|
6
|
+
pending "JRuby support" if defined?(JRUBY_VERSION)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:payload) { 'ohai' }
|
10
|
+
|
11
|
+
context "inside Celluloid::IO" do
|
12
|
+
it "should be evented" do
|
13
|
+
with_unix_server do |subject|
|
14
|
+
within_io_actor { subject.evented? }.should be_true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "accepts a connection and returns a Celluloid::IO::UNIXSocket" do
|
19
|
+
with_unix_server do |subject|
|
20
|
+
thread = Thread.new { UNIXSocket.new(example_unix_sock) }
|
21
|
+
peer = within_io_actor { subject.accept }
|
22
|
+
peer.should be_a Celluloid::IO::UNIXSocket
|
23
|
+
|
24
|
+
client = thread.value
|
25
|
+
client.write payload
|
26
|
+
peer.read(payload.size).should eq payload
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raises if server already up" do
|
31
|
+
with_unix_server do |subject|
|
32
|
+
within_io_actor do
|
33
|
+
expect {
|
34
|
+
Celluloid::IO::UNIXServer.open(example_unix_sock)
|
35
|
+
}.to raise_error(Errno::EADDRINUSE)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "outside Celluloid::IO" do
|
41
|
+
it "should be blocking" do
|
42
|
+
with_unix_server do |subject|
|
43
|
+
subject.should_not be_evented
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "accepts a connection and returns a Celluloid::IO::UNIXSocket" do
|
48
|
+
with_unix_server do |subject|
|
49
|
+
thread = Thread.new { UNIXSocket.new(example_unix_sock) }
|
50
|
+
peer = subject.accept
|
51
|
+
peer.should be_a Celluloid::IO::UNIXSocket
|
52
|
+
|
53
|
+
client = thread.value
|
54
|
+
client.write payload
|
55
|
+
peer.read(payload.size).should eq payload
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "raises if server already up" do
|
60
|
+
with_unix_server do |subject|
|
61
|
+
expect {
|
62
|
+
Celluloid::IO::UNIXServer.open(example_unix_sock)
|
63
|
+
}.to raise_error(Errno::EADDRINUSE)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Celluloid::IO::UNIXSocket do
|
4
|
+
before do
|
5
|
+
pending "JRuby support" if defined?(JRUBY_VERSION)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:payload) { 'ohai' }
|
9
|
+
|
10
|
+
context "inside Celluloid::IO" do
|
11
|
+
it "connects to UNIX servers" do
|
12
|
+
server = ::UNIXServer.open example_unix_sock
|
13
|
+
thread = Thread.new { server.accept }
|
14
|
+
socket = within_io_actor { Celluloid::IO::UNIXSocket.open example_unix_sock }
|
15
|
+
peer = thread.value
|
16
|
+
|
17
|
+
peer << payload
|
18
|
+
within_io_actor { socket.read(payload.size) }.should eq payload
|
19
|
+
|
20
|
+
server.close
|
21
|
+
socket.close
|
22
|
+
peer.close
|
23
|
+
File.delete(example_unix_sock)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be evented" do
|
27
|
+
with_connected_unix_sockets do |subject|
|
28
|
+
within_io_actor { subject.evented? }.should be_true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "read complete payload when nil size is given to #read" do
|
33
|
+
with_connected_unix_sockets do |subject, peer|
|
34
|
+
peer << payload
|
35
|
+
within_io_actor { subject.read(nil) }.should eq payload
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "read complete payload when no size is given to #read" do
|
40
|
+
with_connected_unix_sockets do |subject, peer|
|
41
|
+
peer << payload
|
42
|
+
within_io_actor { subject.read }.should eq payload
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "reads data" do
|
47
|
+
with_connected_unix_sockets do |subject, peer|
|
48
|
+
peer << payload
|
49
|
+
within_io_actor { subject.read(payload.size) }.should eq payload
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "reads data in ASCII-8BIT encoding" do
|
54
|
+
with_connected_unix_sockets do |subject, peer|
|
55
|
+
peer << payload
|
56
|
+
within_io_actor { subject.read(payload.size).encoding }.should eq Encoding::ASCII_8BIT
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "reads partial data" do
|
61
|
+
with_connected_unix_sockets do |subject, peer|
|
62
|
+
peer << payload * 2
|
63
|
+
within_io_actor { subject.readpartial(payload.size) }.should eq payload
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "reads partial data in ASCII-8BIT encoding" do
|
68
|
+
with_connected_unix_sockets do |subject, peer|
|
69
|
+
peer << payload * 2
|
70
|
+
within_io_actor { subject.readpartial(payload.size).encoding }.should eq Encoding::ASCII_8BIT
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it "writes data" do
|
75
|
+
with_connected_unix_sockets do |subject, peer|
|
76
|
+
within_io_actor { subject << payload }
|
77
|
+
peer.read(payload.size).should eq payload
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "raises Errno::ENOENT when the connection is refused" do
|
82
|
+
expect {
|
83
|
+
within_io_actor { Celluloid::IO::UNIXSocket.open(example_unix_sock) }
|
84
|
+
}.to raise_error(Errno::ENOENT)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "raises EOFError when partial reading from a closed socket" do
|
88
|
+
with_connected_unix_sockets do |subject, peer|
|
89
|
+
peer.close
|
90
|
+
expect {
|
91
|
+
within_io_actor { subject.readpartial(payload.size) }
|
92
|
+
}.to raise_error(EOFError)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "outside Celluloid::IO" do
|
98
|
+
it "connects to UNIX servers" do
|
99
|
+
server = ::UNIXServer.new example_unix_sock
|
100
|
+
thread = Thread.new { server.accept }
|
101
|
+
socket = Celluloid::IO::UNIXSocket.open example_unix_sock
|
102
|
+
peer = thread.value
|
103
|
+
|
104
|
+
peer << payload
|
105
|
+
socket.read(payload.size).should eq payload
|
106
|
+
|
107
|
+
server.close
|
108
|
+
socket.close
|
109
|
+
peer.close
|
110
|
+
File.delete example_unix_sock
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should be blocking" do
|
114
|
+
with_connected_unix_sockets do |subject|
|
115
|
+
subject.should_not be_evented
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it "reads data" do
|
120
|
+
with_connected_unix_sockets do |subject, peer|
|
121
|
+
peer << payload
|
122
|
+
subject.read(payload.size).should eq payload
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "reads partial data" do
|
127
|
+
with_connected_unix_sockets do |subject, peer|
|
128
|
+
peer << payload * 2
|
129
|
+
subject.readpartial(payload.size).should eq payload
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
it "writes data" do
|
134
|
+
with_connected_unix_sockets do |subject, peer|
|
135
|
+
subject << payload
|
136
|
+
peer.read(payload.size).should eq payload
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDmjCCAoICCQDwZ8yE/0n4PjANBgkqhkiG9w0BAQUFADCBjjELMAkGA1UEBhMC
|
3
|
+
VVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28x
|
4
|
+
EjAQBgNVBAoTCUNlbGx1bG9pZDEbMBkGA1UEAxMSY2xpZW50LmV4YW1wbGUuY29t
|
5
|
+
MSEwHwY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