rubysl-socket 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +70 -16
- data/lib/rubysl/socket.rb +201 -1396
- data/lib/rubysl/socket/ancillary_data.rb +56 -0
- data/lib/rubysl/socket/bsd.rb +28 -0
- data/lib/rubysl/socket/error.rb +67 -0
- data/lib/rubysl/socket/foreign.rb +324 -0
- data/lib/rubysl/socket/foreign/addrinfo.rb +10 -0
- data/lib/rubysl/socket/foreign/hostent.rb +36 -0
- data/lib/rubysl/socket/foreign/ifaddrs.rb +129 -0
- data/lib/rubysl/socket/foreign/iovec.rb +18 -0
- data/lib/rubysl/socket/foreign/linger.rb +41 -0
- data/lib/rubysl/socket/foreign/msghdr.rb +41 -0
- data/lib/rubysl/socket/foreign/servent.rb +17 -0
- data/lib/rubysl/socket/foreign/sockaddr.rb +21 -0
- data/lib/rubysl/socket/foreign/sockaddr_in.rb +25 -0
- data/lib/rubysl/socket/foreign/sockaddr_in6.rb +25 -0
- data/lib/rubysl/socket/foreign/sockaddr_un.rb +29 -0
- data/lib/rubysl/socket/ipv6.rb +38 -0
- data/lib/rubysl/socket/linux.rb +16 -0
- data/lib/rubysl/socket/socket_options.rb +84 -0
- data/lib/rubysl/socket/version.rb +1 -1
- data/lib/socket.rb +45 -1
- data/lib/socket/addrinfo.rb +453 -0
- data/lib/socket/ancillary_data.rb +114 -0
- data/lib/socket/basic_socket.rb +295 -0
- data/lib/socket/constants.rb +41 -0
- data/lib/socket/ifaddr.rb +29 -0
- data/lib/socket/ip_socket.rb +37 -0
- data/lib/socket/mri.rb +928 -0
- data/lib/socket/option.rb +96 -0
- data/lib/socket/socket.rb +353 -0
- data/lib/socket/socket_error.rb +2 -0
- data/lib/socket/tcp_server.rb +78 -0
- data/lib/socket/tcp_socket.rb +109 -0
- data/lib/socket/udp_socket.rb +73 -0
- data/lib/socket/unix_server.rb +35 -0
- data/lib/socket/unix_socket.rb +78 -0
- data/rubysl-socket.gemspec +15 -10
- metadata +78 -293
- data/.gitignore +0 -17
- data/.travis.yml +0 -9
- data/Gemfile +0 -4
- data/Rakefile +0 -1
- data/spec/addrinfo/afamily_spec.rb +0 -5
- data/spec/addrinfo/bind_spec.rb +0 -5
- data/spec/addrinfo/canonname_spec.rb +0 -5
- data/spec/addrinfo/connect_from_spec.rb +0 -5
- data/spec/addrinfo/connect_spec.rb +0 -5
- data/spec/addrinfo/connect_to_spec.rb +0 -5
- data/spec/addrinfo/family_addrinfo_spec.rb +0 -5
- data/spec/addrinfo/foreach_spec.rb +0 -5
- data/spec/addrinfo/getaddrinfo_spec.rb +0 -5
- data/spec/addrinfo/getnameinfo_spec.rb +0 -5
- data/spec/addrinfo/inspect_sockaddr_spec.rb +0 -5
- data/spec/addrinfo/inspect_spec.rb +0 -5
- data/spec/addrinfo/ip_address_spec.rb +0 -5
- data/spec/addrinfo/ip_port_spec.rb +0 -5
- data/spec/addrinfo/ip_spec.rb +0 -9
- data/spec/addrinfo/ip_unpack_spec.rb +0 -5
- data/spec/addrinfo/ipv4_loopback_spec.rb +0 -5
- data/spec/addrinfo/ipv4_multicast_spec.rb +0 -5
- data/spec/addrinfo/ipv4_private_spec.rb +0 -5
- data/spec/addrinfo/ipv4_spec.rb +0 -5
- data/spec/addrinfo/ipv6_linklocal_spec.rb +0 -5
- data/spec/addrinfo/ipv6_loopback_spec.rb +0 -5
- data/spec/addrinfo/ipv6_mc_global_spec.rb +0 -5
- data/spec/addrinfo/ipv6_mc_linklocal_spec.rb +0 -5
- data/spec/addrinfo/ipv6_mc_nodelocal_spec.rb +0 -5
- data/spec/addrinfo/ipv6_mc_orglocal_spec.rb +0 -5
- data/spec/addrinfo/ipv6_mc_sitelocal_spec.rb +0 -5
- data/spec/addrinfo/ipv6_multicast_spec.rb +0 -5
- data/spec/addrinfo/ipv6_sitelocal_spec.rb +0 -5
- data/spec/addrinfo/ipv6_spec.rb +0 -5
- data/spec/addrinfo/ipv6_to_ipv4_spec.rb +0 -5
- data/spec/addrinfo/ipv6_unspecified_spec.rb +0 -5
- data/spec/addrinfo/ipv6_v4compat_spec.rb +0 -5
- data/spec/addrinfo/ipv6_v4mapped_spec.rb +0 -5
- data/spec/addrinfo/listen_spec.rb +0 -5
- data/spec/addrinfo/marshal_dump_spec.rb +0 -5
- data/spec/addrinfo/marshal_load_spec.rb +0 -5
- data/spec/addrinfo/pfamily_spec.rb +0 -5
- data/spec/addrinfo/protocol_spec.rb +0 -5
- data/spec/addrinfo/socktype_spec.rb +0 -5
- data/spec/addrinfo/tcp_spec.rb +0 -5
- data/spec/addrinfo/to_s_spec.rb +0 -5
- data/spec/addrinfo/to_sockaddr_spec.rb +0 -5
- data/spec/addrinfo/udp_spec.rb +0 -5
- data/spec/addrinfo/unix_path_spec.rb +0 -5
- data/spec/addrinfo/unix_spec.rb +0 -9
- data/spec/basicsocket/close_read_spec.rb +0 -42
- data/spec/basicsocket/close_write_spec.rb +0 -42
- data/spec/basicsocket/do_not_reverse_lookup_spec.rb +0 -78
- data/spec/basicsocket/for_fd_spec.rb +0 -37
- data/spec/basicsocket/getpeername_spec.rb +0 -24
- data/spec/basicsocket/getsockname_spec.rb +0 -27
- data/spec/basicsocket/getsockopt_spec.rb +0 -54
- data/spec/basicsocket/ioctl_spec.rb +0 -22
- data/spec/basicsocket/recv_nonblock_spec.rb +0 -6
- data/spec/basicsocket/recv_spec.rb +0 -76
- data/spec/basicsocket/send_spec.rb +0 -81
- data/spec/basicsocket/setsockopt_spec.rb +0 -333
- data/spec/basicsocket/shutdown_spec.rb +0 -5
- data/spec/constants/constants_spec.rb +0 -63
- data/spec/fixtures/classes.rb +0 -174
- data/spec/fixtures/send_io.txt +0 -1
- data/spec/ipsocket/addr_spec.rb +0 -72
- data/spec/ipsocket/getaddress_spec.rb +0 -26
- data/spec/ipsocket/peeraddr_spec.rb +0 -79
- data/spec/ipsocket/recvfrom_spec.rb +0 -64
- data/spec/option/int_spec.rb +0 -27
- data/spec/option/linger_spec.rb +0 -52
- data/spec/option/new_spec.rb +0 -32
- data/spec/shared/pack_sockaddr.rb +0 -26
- data/spec/shared/partially_closable_sockets.rb +0 -13
- data/spec/shared/recv_nonblock.rb +0 -33
- data/spec/shared/socketpair.rb +0 -35
- data/spec/socket/accept_nonblock_spec.rb +0 -27
- data/spec/socket/accept_spec.rb +0 -1
- data/spec/socket/bind_spec.rb +0 -80
- data/spec/socket/connect_nonblock_spec.rb +0 -62
- data/spec/socket/connect_spec.rb +0 -1
- data/spec/socket/for_fd_spec.rb +0 -29
- data/spec/socket/getaddrinfo_spec.rb +0 -120
- data/spec/socket/gethostbyaddr_spec.rb +0 -1
- data/spec/socket/gethostbyname_spec.rb +0 -26
- data/spec/socket/gethostname_spec.rb +0 -9
- data/spec/socket/getnameinfo_spec.rb +0 -57
- data/spec/socket/getservbyname_spec.rb +0 -24
- data/spec/socket/listen_spec.rb +0 -21
- data/spec/socket/new_spec.rb +0 -109
- data/spec/socket/pack_sockaddr_in_spec.rb +0 -6
- data/spec/socket/pack_sockaddr_un_spec.rb +0 -6
- data/spec/socket/pair_spec.rb +0 -6
- data/spec/socket/recvfrom_nonblock_spec.rb +0 -1
- data/spec/socket/recvfrom_spec.rb +0 -1
- data/spec/socket/sockaddr_in_spec.rb +0 -6
- data/spec/socket/sockaddr_un_spec.rb +0 -6
- data/spec/socket/socket_spec.rb +0 -37
- data/spec/socket/socketpair_spec.rb +0 -6
- data/spec/socket/sysaccept_spec.rb +0 -1
- data/spec/socket/unpack_sockaddr_in_spec.rb +0 -16
- data/spec/socket/unpack_sockaddr_un_spec.rb +0 -2
- data/spec/tcpserver/accept_nonblock_spec.rb +0 -30
- data/spec/tcpserver/accept_spec.rb +0 -60
- data/spec/tcpserver/gets_spec.rb +0 -17
- data/spec/tcpserver/listen_spec.rb +0 -1
- data/spec/tcpserver/new_spec.rb +0 -88
- data/spec/tcpserver/output_spec.rb +0 -8
- data/spec/tcpserver/readpartial_spec.rb +0 -8
- data/spec/tcpserver/sysaccept_spec.rb +0 -1
- data/spec/tcpsocket/gethostbyname_spec.rb +0 -62
- data/spec/tcpsocket/new_spec.rb +0 -5
- data/spec/tcpsocket/open_spec.rb +0 -5
- data/spec/tcpsocket/partially_closable_spec.rb +0 -20
- data/spec/tcpsocket/recv_nonblock_spec.rb +0 -31
- data/spec/tcpsocket/setsockopt_spec.rb +0 -49
- data/spec/tcpsocket/shared/new.rb +0 -85
- data/spec/udpsocket/bind_spec.rb +0 -33
- data/spec/udpsocket/connect_spec.rb +0 -1
- data/spec/udpsocket/new_spec.rb +0 -1
- data/spec/udpsocket/open_spec.rb +0 -12
- data/spec/udpsocket/recvfrom_nonblock_spec.rb +0 -1
- data/spec/udpsocket/send_spec.rb +0 -57
- data/spec/unixserver/accept_nonblock_spec.rb +0 -33
- data/spec/unixserver/accept_spec.rb +0 -64
- data/spec/unixserver/for_fd_spec.rb +0 -32
- data/spec/unixserver/new_spec.rb +0 -5
- data/spec/unixserver/open_spec.rb +0 -25
- data/spec/unixserver/shared/new.rb +0 -23
- data/spec/unixsocket/addr_spec.rb +0 -37
- data/spec/unixsocket/new_spec.rb +0 -5
- data/spec/unixsocket/open_spec.rb +0 -26
- data/spec/unixsocket/pair_spec.rb +0 -38
- data/spec/unixsocket/partially_closable_spec.rb +0 -25
- data/spec/unixsocket/path_spec.rb +0 -29
- data/spec/unixsocket/peeraddr_spec.rb +0 -29
- data/spec/unixsocket/recv_io_spec.rb +0 -40
- data/spec/unixsocket/recvfrom_spec.rb +0 -48
- data/spec/unixsocket/send_io_spec.rb +0 -30
- data/spec/unixsocket/shared/new.rb +0 -25
@@ -1 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
data/spec/udpsocket/send_spec.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
describe "UDPSocket.send" do
|
4
|
-
before :each do
|
5
|
-
@ready = false
|
6
|
-
@server_thread = Thread.new do
|
7
|
-
@server = UDPSocket.open
|
8
|
-
@server.bind(nil, SocketSpecs.port)
|
9
|
-
@ready = true
|
10
|
-
begin
|
11
|
-
@msg = @server.recvfrom_nonblock(64)
|
12
|
-
rescue Errno::EAGAIN
|
13
|
-
IO.select([@server])
|
14
|
-
retry
|
15
|
-
end
|
16
|
-
@server.close
|
17
|
-
end
|
18
|
-
Thread.pass while @server_thread.status and !@ready
|
19
|
-
end
|
20
|
-
|
21
|
-
it "sends data in ad hoc mode" do
|
22
|
-
@socket = UDPSocket.open
|
23
|
-
@socket.send("ad hoc", 0, SocketSpecs.hostname,SocketSpecs.port)
|
24
|
-
@socket.close
|
25
|
-
@server_thread.join
|
26
|
-
|
27
|
-
@msg[0].should == "ad hoc"
|
28
|
-
@msg[1][0].should == "AF_INET"
|
29
|
-
@msg[1][1].should be_kind_of(Fixnum)
|
30
|
-
@msg[1][3].should == "127.0.0.1"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "sends data in ad hoc mode (with port given as a String)" do
|
34
|
-
@socket = UDPSocket.open
|
35
|
-
@socket.send("ad hoc", 0, SocketSpecs.hostname,SocketSpecs.str_port)
|
36
|
-
@socket.close
|
37
|
-
@server_thread.join
|
38
|
-
|
39
|
-
@msg[0].should == "ad hoc"
|
40
|
-
@msg[1][0].should == "AF_INET"
|
41
|
-
@msg[1][1].should be_kind_of(Fixnum)
|
42
|
-
@msg[1][3].should == "127.0.0.1"
|
43
|
-
end
|
44
|
-
|
45
|
-
it "sends data in connection mode" do
|
46
|
-
@socket = UDPSocket.open
|
47
|
-
@socket.connect(SocketSpecs.hostname,SocketSpecs.port)
|
48
|
-
@socket.send("connection-based", 0)
|
49
|
-
@socket.close
|
50
|
-
@server_thread.join
|
51
|
-
|
52
|
-
@msg[0].should == "connection-based"
|
53
|
-
@msg[1][0].should == "AF_INET"
|
54
|
-
@msg[1][1].should be_kind_of(Fixnum)
|
55
|
-
@msg[1][3].should == "127.0.0.1"
|
56
|
-
end
|
57
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
describe "UNIXServer#accept_nonblock" do
|
4
|
-
|
5
|
-
platform_is_not :windows do
|
6
|
-
before :each do
|
7
|
-
@path = SocketSpecs.socket_path
|
8
|
-
rm_r @path
|
9
|
-
|
10
|
-
@server = UNIXServer.open(@path)
|
11
|
-
@client = UNIXSocket.open(@path)
|
12
|
-
|
13
|
-
@socket = @server.accept_nonblock
|
14
|
-
@client.send("foobar", 0)
|
15
|
-
end
|
16
|
-
|
17
|
-
after :each do
|
18
|
-
@socket.close
|
19
|
-
@client.close
|
20
|
-
@server.close
|
21
|
-
rm_r @path
|
22
|
-
end
|
23
|
-
|
24
|
-
it "accepts a connection in a non-blocking way" do
|
25
|
-
data = @socket.recvfrom(6).first
|
26
|
-
data.should == "foobar"
|
27
|
-
end
|
28
|
-
|
29
|
-
it "returns a UNIXSocket" do
|
30
|
-
@socket.should be_kind_of(UNIXSocket)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
platform_is_not :windows do
|
4
|
-
describe "UNIXServer#accept" do
|
5
|
-
before :each do
|
6
|
-
@path = SocketSpecs.socket_path
|
7
|
-
rm_r @path
|
8
|
-
end
|
9
|
-
|
10
|
-
after :each do
|
11
|
-
rm_r @path
|
12
|
-
end
|
13
|
-
|
14
|
-
it "accepts what is written by the client" do
|
15
|
-
server = UNIXServer.open(SocketSpecs.socket_path)
|
16
|
-
client = UNIXSocket.open(SocketSpecs.socket_path)
|
17
|
-
|
18
|
-
client.send('hello', 0)
|
19
|
-
|
20
|
-
sock = server.accept
|
21
|
-
data, info = sock.recvfrom(5)
|
22
|
-
|
23
|
-
data.should == 'hello'
|
24
|
-
|
25
|
-
server.close
|
26
|
-
client.close
|
27
|
-
sock.close
|
28
|
-
end
|
29
|
-
|
30
|
-
it "can be interrupted by Thread#kill" do
|
31
|
-
server = UNIXServer.new(@path)
|
32
|
-
t = Thread.new {
|
33
|
-
server.accept
|
34
|
-
}
|
35
|
-
Thread.pass while t.status and t.status != "sleep"
|
36
|
-
|
37
|
-
# kill thread, ensure it dies in a reasonable amount of time
|
38
|
-
t.kill
|
39
|
-
a = 1
|
40
|
-
while a < 2000
|
41
|
-
break unless t.alive?
|
42
|
-
Thread.pass
|
43
|
-
sleep 0.2
|
44
|
-
a += 1
|
45
|
-
end
|
46
|
-
a.should < 2000
|
47
|
-
server.close
|
48
|
-
end
|
49
|
-
|
50
|
-
it "can be interrupted by Thread#raise" do
|
51
|
-
server = UNIXServer.new(@path)
|
52
|
-
t = Thread.new {
|
53
|
-
server.accept
|
54
|
-
}
|
55
|
-
Thread.pass while t.status and t.status != "sleep"
|
56
|
-
|
57
|
-
# raise in thread, ensure the raise happens
|
58
|
-
ex = Exception.new
|
59
|
-
t.raise ex
|
60
|
-
lambda { t.join }.should raise_error(Exception)
|
61
|
-
server.close
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
describe "UNIXServer#for_fd" do
|
4
|
-
before :each do
|
5
|
-
@unix_path = tmp("unix_socket")
|
6
|
-
@unix = UNIXServer.new(@unix_path)
|
7
|
-
end
|
8
|
-
|
9
|
-
after :each do
|
10
|
-
# UG. We can't use the new_fd helper, because we need fds that are
|
11
|
-
# associated with sockets. But for_fd has the same issue as IO#new, it
|
12
|
-
# creates a fd aliasing issue with closing, causing EBADF errors.
|
13
|
-
#
|
14
|
-
# Thusly, the rescue for EBADF here. I'd love a better solution, but
|
15
|
-
# I'm not aware of one.
|
16
|
-
|
17
|
-
begin
|
18
|
-
@unix.close unless @unix.closed?
|
19
|
-
rescue Errno::EBADF
|
20
|
-
# I hate this API too
|
21
|
-
end
|
22
|
-
|
23
|
-
rm_r @unix_path
|
24
|
-
end
|
25
|
-
|
26
|
-
it "can calculate the path" do
|
27
|
-
b = UNIXServer.for_fd(@unix.fileno)
|
28
|
-
|
29
|
-
b.path.should == @unix_path
|
30
|
-
b.close
|
31
|
-
end
|
32
|
-
end
|
data/spec/unixserver/new_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.expand_path('../shared/new', __FILE__)
|
2
|
-
|
3
|
-
describe "UNIXServer.open" do
|
4
|
-
it_behaves_like :unixserver_new, :open
|
5
|
-
|
6
|
-
platform_is_not :windows do
|
7
|
-
before :each do
|
8
|
-
@path = tmp("unixserver_spec")
|
9
|
-
rm_r @path
|
10
|
-
end
|
11
|
-
|
12
|
-
after :each do
|
13
|
-
@server.close if @server
|
14
|
-
@server = nil
|
15
|
-
rm_r @path
|
16
|
-
end
|
17
|
-
|
18
|
-
it "yields the new UNIXServer object to the block, if given" do
|
19
|
-
UNIXServer.open(@path) do |unix|
|
20
|
-
unix.path.should == @path
|
21
|
-
unix.addr.should == ["AF_UNIX", @path]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../fixtures/classes', __FILE__)
|
2
|
-
require 'tempfile'
|
3
|
-
|
4
|
-
describe :unixserver_new, :shared => true do
|
5
|
-
platform_is_not :windows do
|
6
|
-
before :each do
|
7
|
-
@path = tmp("unixserver_spec")
|
8
|
-
rm_r @path
|
9
|
-
end
|
10
|
-
|
11
|
-
after :each do
|
12
|
-
@server.close if @server
|
13
|
-
@server = nil
|
14
|
-
rm_r @path
|
15
|
-
end
|
16
|
-
|
17
|
-
it "creates a new UNIXServer" do
|
18
|
-
@server = UNIXServer.send(@method, @path)
|
19
|
-
@server.path.should == @path
|
20
|
-
@server.addr.should == ["AF_UNIX", @path]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
describe "UNIXSocket#addr" do
|
4
|
-
|
5
|
-
platform_is_not :windows do
|
6
|
-
before :each do
|
7
|
-
@path = SocketSpecs.socket_path
|
8
|
-
rm_r @path
|
9
|
-
|
10
|
-
@server = UNIXServer.open(@path)
|
11
|
-
@client = UNIXSocket.open(@path)
|
12
|
-
end
|
13
|
-
|
14
|
-
after :each do
|
15
|
-
@client.close
|
16
|
-
@server.close
|
17
|
-
rm_r @path
|
18
|
-
end
|
19
|
-
|
20
|
-
it "returns the address family of this socket in an array" do
|
21
|
-
@client.addr[0].should == "AF_UNIX"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "returns the path of the socket in an array if it's a server" do
|
25
|
-
@server.addr[1].should == @path
|
26
|
-
end
|
27
|
-
|
28
|
-
it "returns an empty string for path if it's a client" do
|
29
|
-
@client.addr[1].should == ""
|
30
|
-
end
|
31
|
-
|
32
|
-
it "returns an array" do
|
33
|
-
@client.addr.should be_kind_of(Array)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
data/spec/unixsocket/new_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require File.expand_path('../shared/new', __FILE__)
|
2
|
-
|
3
|
-
describe "UNIXSocket.open" do
|
4
|
-
it_behaves_like :unixsocket_new, :open
|
5
|
-
|
6
|
-
platform_is_not :windows do
|
7
|
-
before :each do
|
8
|
-
@path = SocketSpecs.socket_path
|
9
|
-
rm_r @path
|
10
|
-
|
11
|
-
@server = UNIXServer.open(@path)
|
12
|
-
end
|
13
|
-
|
14
|
-
after :each do
|
15
|
-
@server.close
|
16
|
-
rm_r @path
|
17
|
-
end
|
18
|
-
|
19
|
-
it "opens a unix socket on the specified file and yields it to the block" do
|
20
|
-
UNIXSocket.send(@method, @path) do |client|
|
21
|
-
client.addr[0].should == "AF_UNIX"
|
22
|
-
client.closed?.should == false
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
require File.expand_path('../../shared/partially_closable_sockets', __FILE__)
|
3
|
-
|
4
|
-
describe "UNIXSocket#pair" do
|
5
|
-
platform_is_not :windows do
|
6
|
-
|
7
|
-
it_should_behave_like "partially closable sockets"
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
@s1, @s2 = UNIXSocket.pair
|
11
|
-
end
|
12
|
-
|
13
|
-
after :each do
|
14
|
-
@s1.close
|
15
|
-
@s2.close
|
16
|
-
end
|
17
|
-
|
18
|
-
it "returns a pair of connected sockets" do
|
19
|
-
@s1.puts "foo"
|
20
|
-
@s2.gets.should == "foo\n"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns sockets with no name" do
|
24
|
-
@s1.path.should == @s2.path
|
25
|
-
@s1.path.should == ""
|
26
|
-
end
|
27
|
-
|
28
|
-
it "returns sockets with no address" do
|
29
|
-
@s1.addr.should == ["AF_UNIX", ""]
|
30
|
-
@s2.addr.should == ["AF_UNIX", ""]
|
31
|
-
end
|
32
|
-
|
33
|
-
it "returns sockets with no peeraddr" do
|
34
|
-
@s1.peeraddr.should == ["AF_UNIX", ""]
|
35
|
-
@s2.peeraddr.should == ["AF_UNIX", ""]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
require File.expand_path('../../shared/partially_closable_sockets', __FILE__)
|
3
|
-
|
4
|
-
platform_is_not :windows do
|
5
|
-
describe "UNIXSocket partial closability" do
|
6
|
-
|
7
|
-
before :each do
|
8
|
-
@path = SocketSpecs.socket_path
|
9
|
-
rm_r @path
|
10
|
-
@server = UNIXServer.open(@path)
|
11
|
-
@s1 = UNIXSocket.new(@path)
|
12
|
-
@s2 = @server.accept
|
13
|
-
end
|
14
|
-
|
15
|
-
after :each do
|
16
|
-
@server.close
|
17
|
-
@s1.close
|
18
|
-
@s2.close
|
19
|
-
rm_r @path
|
20
|
-
end
|
21
|
-
|
22
|
-
it_should_behave_like "partially closable sockets"
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
describe "UNIXSocket#path" do
|
4
|
-
|
5
|
-
platform_is_not :windows do
|
6
|
-
before :each do
|
7
|
-
@path = SocketSpecs.socket_path
|
8
|
-
rm_r @path
|
9
|
-
|
10
|
-
@server = UNIXServer.open(@path)
|
11
|
-
@client = UNIXSocket.open(@path)
|
12
|
-
end
|
13
|
-
|
14
|
-
after :each do
|
15
|
-
@client.close
|
16
|
-
@server.close
|
17
|
-
rm_r @path
|
18
|
-
end
|
19
|
-
|
20
|
-
it "returns the path of the socket if it's a server" do
|
21
|
-
@server.path.should == @path
|
22
|
-
end
|
23
|
-
|
24
|
-
it "returns an empty string for path if it's a client" do
|
25
|
-
@client.path.should == ""
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
describe "UNIXSocket#peeraddr" do
|
4
|
-
|
5
|
-
platform_is_not :windows do
|
6
|
-
before :each do
|
7
|
-
@path = SocketSpecs.socket_path
|
8
|
-
rm_r @path
|
9
|
-
|
10
|
-
@server = UNIXServer.open(@path)
|
11
|
-
@client = UNIXSocket.open(@path)
|
12
|
-
end
|
13
|
-
|
14
|
-
after :each do
|
15
|
-
@client.close
|
16
|
-
@server.close
|
17
|
-
rm_r @path
|
18
|
-
end
|
19
|
-
|
20
|
-
it "returns the address familly and path of the server end of the connection" do
|
21
|
-
@client.peeraddr.should == ["AF_UNIX", @path]
|
22
|
-
end
|
23
|
-
|
24
|
-
it "raises an error in server sockets" do
|
25
|
-
lambda { @server.peeraddr }.should raise_error
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|