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__)
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# -*- encoding: US-ASCII -*-
|
2
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
3
|
-
|
4
|
-
require 'socket'
|
5
|
-
|
6
|
-
describe "Socket#gethostbyname" do
|
7
|
-
it "returns broadcast address info for '<broadcast>'" do
|
8
|
-
addr = Socket.gethostbyname('<broadcast>').first;
|
9
|
-
["broadcasthost", "255.255.255.255"].should include(addr)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "returns broadcast address info for '<any>'" do
|
13
|
-
addr = Socket.gethostbyname('<any>').first;
|
14
|
-
addr.should == "0.0.0.0"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns address list in pack format (IPv4)" do
|
18
|
-
laddr = Socket.gethostbyname('127.0.0.1')[3..-1];
|
19
|
-
laddr.should == ["\x7f\x00\x00\x01"]
|
20
|
-
end
|
21
|
-
|
22
|
-
it "returns address list in pack format (IPv6)" do
|
23
|
-
laddr = Socket.gethostbyname('::1')[3..-1]
|
24
|
-
laddr.should == ["\x00" * 15 + "\x01"]
|
25
|
-
end
|
26
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
describe "Socket.gethostname" do
|
4
|
-
# This currently works in Unix and Windows. Edit the helper
|
5
|
-
# to add other platforms.
|
6
|
-
it "returns the host name" do
|
7
|
-
Socket.gethostname.should == hostname
|
8
|
-
end
|
9
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
require 'socket'
|
4
|
-
|
5
|
-
describe "Socket.getnameinfo" do
|
6
|
-
before :all do
|
7
|
-
@reverse_lookup = BasicSocket.do_not_reverse_lookup
|
8
|
-
BasicSocket.do_not_reverse_lookup = true
|
9
|
-
end
|
10
|
-
|
11
|
-
after :all do
|
12
|
-
BasicSocket.do_not_reverse_lookup = @reverse_lookup
|
13
|
-
end
|
14
|
-
|
15
|
-
it "gets the name information and don't resolve it" do
|
16
|
-
sockaddr = Socket.sockaddr_in SocketSpecs.port, '127.0.0.1'
|
17
|
-
name_info = Socket.getnameinfo(sockaddr, Socket::NI_NUMERICHOST | Socket::NI_NUMERICSERV)
|
18
|
-
name_info.should == ['127.0.0.1', "#{SocketSpecs.port}"]
|
19
|
-
end
|
20
|
-
|
21
|
-
it "gets the name information and resolve the host" do
|
22
|
-
sockaddr = Socket.sockaddr_in SocketSpecs.port, '127.0.0.1'
|
23
|
-
name_info = Socket.getnameinfo(sockaddr, Socket::NI_NUMERICSERV)
|
24
|
-
name_info[0].should be_valid_DNS_name
|
25
|
-
name_info[1].should == SocketSpecs.port.to_s
|
26
|
-
end
|
27
|
-
|
28
|
-
it "gets the name information and resolves the service" do
|
29
|
-
sockaddr = Socket.sockaddr_in 80, '127.0.0.1'
|
30
|
-
name_info = Socket.getnameinfo(sockaddr)
|
31
|
-
name_info.size.should == 2
|
32
|
-
name_info[0].should be_valid_DNS_name
|
33
|
-
# see http://www.iana.org/assignments/port-numbers
|
34
|
-
name_info[1].should =~ /^(www|http|www-http)$/
|
35
|
-
end
|
36
|
-
|
37
|
-
it "gets a 3-element array and doesn't resolve hostname" do
|
38
|
-
name_info = Socket.getnameinfo(["AF_INET", SocketSpecs.port, '127.0.0.1'], Socket::NI_NUMERICHOST | Socket::NI_NUMERICSERV)
|
39
|
-
name_info.should == ['127.0.0.1', "#{SocketSpecs.port}"]
|
40
|
-
end
|
41
|
-
|
42
|
-
it "gets a 3-element array and resolves the service" do
|
43
|
-
name_info = Socket.getnameinfo ["AF_INET", 80, '127.0.0.1']
|
44
|
-
name_info[1].should =~ /^(www|http|www-http)$/
|
45
|
-
end
|
46
|
-
|
47
|
-
it "gets a 4-element array and doesn't resolve hostname" do
|
48
|
-
name_info = Socket.getnameinfo(["AF_INET", SocketSpecs.port, 'foo', '127.0.0.1'], Socket::NI_NUMERICHOST | Socket::NI_NUMERICSERV)
|
49
|
-
name_info.should == ['127.0.0.1', "#{SocketSpecs.port}"]
|
50
|
-
end
|
51
|
-
|
52
|
-
it "gets a 4-element array and resolves the service" do
|
53
|
-
name_info = Socket.getnameinfo ["AF_INET", 80, 'foo', '127.0.0.1']
|
54
|
-
name_info[1].should =~ /^(www|http|www-http)$/
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
3
|
-
|
4
|
-
describe "Socket#getservbyname" do
|
5
|
-
it "returns the port for service 'http'" do
|
6
|
-
Socket.getservbyname('http').should == 80
|
7
|
-
end
|
8
|
-
|
9
|
-
it "returns the port for service 'http' with protocol 'tcp'" do
|
10
|
-
Socket.getservbyname('http', 'tcp').should == 80
|
11
|
-
end
|
12
|
-
|
13
|
-
it "returns the port for service 'domain' with protocol 'udp'" do
|
14
|
-
Socket.getservbyname('domain', 'udp').should == 53
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns the port for service 'daytime'" do
|
18
|
-
Socket.getservbyname('daytime').should == 13
|
19
|
-
end
|
20
|
-
|
21
|
-
it "raises a SocketError when the service or port is invalid" do
|
22
|
-
lambda { Socket.getservbyname('invalid') }.should raise_error(SocketError)
|
23
|
-
end
|
24
|
-
end
|
data/spec/socket/listen_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
include Socket::Constants
|
4
|
-
|
5
|
-
describe "Socket#listen" do
|
6
|
-
before :each do
|
7
|
-
@socket = Socket.new(AF_INET, SOCK_STREAM, 0)
|
8
|
-
end
|
9
|
-
|
10
|
-
after :each do
|
11
|
-
@socket.closed?.should be_false
|
12
|
-
@socket.close
|
13
|
-
end
|
14
|
-
|
15
|
-
it "verifies we can listen for incoming connections" do
|
16
|
-
sockaddr = Socket.pack_sockaddr_in(SocketSpecs.port, "127.0.0.1")
|
17
|
-
@socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
|
18
|
-
@socket.bind(sockaddr)
|
19
|
-
@socket.listen(1).should == 0
|
20
|
-
end
|
21
|
-
end
|
data/spec/socket/new_spec.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
describe "Socket.new" do
|
4
|
-
before :each do
|
5
|
-
@socket = nil
|
6
|
-
end
|
7
|
-
|
8
|
-
after :each do
|
9
|
-
@socket.close if @socket and not @socket.closed?
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "with a Socket::PF_INET family" do
|
13
|
-
it "creates a socket with a :DGRAM type specifier" do
|
14
|
-
@socket = Socket.new Socket::PF_INET, "SOCK_DGRAM", 0
|
15
|
-
@socket.should be_an_instance_of(Socket)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "creates a socket with a Socket::PF_STREAM type specifier" do
|
19
|
-
@socket = Socket.new Socket::PF_INET, "SOCK_STREAM", 0
|
20
|
-
@socket.should be_an_instance_of(Socket)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "with a Socket::PF_UNIX family" do
|
25
|
-
it "creates a socket with a :DGRAM type specifier" do
|
26
|
-
@socket = Socket.new Socket::PF_UNIX, "SOCK_DGRAM", 0
|
27
|
-
@socket.should be_an_instance_of(Socket)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "creates a socket with a :STREAM type specifier" do
|
31
|
-
@socket = Socket.new Socket::PF_UNIX, "SOCK_STREAM", 0
|
32
|
-
@socket.should be_an_instance_of(Socket)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "calls #to_str to convert the family to a String" do
|
37
|
-
family = mock("socket new family")
|
38
|
-
family.should_receive(:to_str).and_return("PF_UNIX")
|
39
|
-
@socket = Socket.new family, "SOCK_STREAM", 0
|
40
|
-
@socket.should be_an_instance_of(Socket)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "raises a TypeError if #to_str does not return a String" do
|
44
|
-
family = mock("socket new family")
|
45
|
-
family.should_receive(:to_str).and_return(1)
|
46
|
-
lambda { @socket = Socket.new family, "SOCK_STREAM", 0 }.should raise_error(TypeError)
|
47
|
-
end
|
48
|
-
|
49
|
-
ruby_version_is ""..."1.9" do
|
50
|
-
it "raises an Errno::EPROTONOSUPPORT if socket type is not a string or integer" do
|
51
|
-
lambda { Socket.new(Socket::PF_UNIX, :DGRAM, 0) }.should raise_error(Errno::EPROTONOSUPPORT)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
ruby_version_is "1.9" do
|
56
|
-
it "raises a SocketError if given symbol is not a Socket constants reference" do
|
57
|
-
lambda { Socket.new(Socket::PF_UNIX, :NO_EXIST, 0) }.should raise_error(SocketError)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "creates a socket with an :INET family specifier" do
|
61
|
-
@socket = Socket.new :INET, :STREAM
|
62
|
-
@socket.should be_an_instance_of(Socket)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "creates a socket with an 'INET' family specifier" do
|
66
|
-
@socket = Socket.new "INET", :STREAM
|
67
|
-
@socket.should be_an_instance_of(Socket)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "creates a socket with a :UNIX family specifier" do
|
71
|
-
@socket = Socket.new :UNIX, :STREAM
|
72
|
-
@socket.should be_an_instance_of(Socket)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "creates a socket with a 'UNIX' family specifier" do
|
76
|
-
@socket = Socket.new "UNIX", :STREAM
|
77
|
-
@socket.should be_an_instance_of(Socket)
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "with an :INET family" do
|
81
|
-
it "creates a socket with a :DGRAM type specifier" do
|
82
|
-
@socket = Socket.new :INET, :DGRAM
|
83
|
-
@socket.should be_an_instance_of(Socket)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "creates a socket with a :STREAM type specifier" do
|
87
|
-
@socket = Socket.new :INET, :STREAM
|
88
|
-
@socket.should be_an_instance_of(Socket)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe "with a :UNIX family" do
|
93
|
-
it "creates a socket with a :DGRAM type specifier" do
|
94
|
-
@socket = Socket.new :UNIX, :DGRAM
|
95
|
-
@socket.should be_an_instance_of(Socket)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "creates a socket with a :STREAM type specifier" do
|
99
|
-
@socket = Socket.new :UNIX, :STREAM
|
100
|
-
@socket.should be_an_instance_of(Socket)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
it "accepts an optional protocol parameter" do
|
105
|
-
@socket = Socket.new Socket::PF_UNIX, Socket::SOCK_DGRAM, 0
|
106
|
-
@socket.should be_an_instance_of(Socket)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
data/spec/socket/pair_spec.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
@@ -1 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
data/spec/socket/socket_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
describe "Socket" do
|
4
|
-
it "inherits from BasicSocket and IO" do
|
5
|
-
Socket.superclass.should == BasicSocket
|
6
|
-
BasicSocket.superclass.should == IO
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "The socket class hierarchy" do
|
11
|
-
it "has an IPSocket in parallel to Socket" do
|
12
|
-
Socket.ancestors.include?(IPSocket).should == false
|
13
|
-
IPSocket.ancestors.include?(Socket).should == false
|
14
|
-
IPSocket.superclass.should == BasicSocket
|
15
|
-
end
|
16
|
-
|
17
|
-
it "has TCPSocket and UDPSocket subclasses of IPSocket" do
|
18
|
-
TCPSocket.superclass.should == IPSocket
|
19
|
-
UDPSocket.superclass.should == IPSocket
|
20
|
-
end
|
21
|
-
|
22
|
-
not_supported_on :jruby, :windows do
|
23
|
-
it "has a UNIXSocket in parallel to Socket" do
|
24
|
-
Socket.ancestors.include?(UNIXSocket).should == false
|
25
|
-
UNIXSocket.ancestors.include?(Socket).should == false
|
26
|
-
UNIXSocket.superclass.should == BasicSocket
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
not_supported_on :jruby, :windows do
|
32
|
-
describe "Server class hierarchy" do
|
33
|
-
it "contains UNIXServer" do
|
34
|
-
UNIXServer.superclass.should == UNIXSocket
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
require 'socket'
|
3
|
-
|
4
|
-
describe "Socket#unpack_sockaddr_in" do
|
5
|
-
|
6
|
-
it "decodes the host name and port number of a packed sockaddr_in" do
|
7
|
-
sockaddr = Socket.sockaddr_in SocketSpecs.port, '127.0.0.1'
|
8
|
-
Socket.unpack_sockaddr_in(sockaddr).should == [SocketSpecs.port, '127.0.0.1']
|
9
|
-
end
|
10
|
-
|
11
|
-
it "raises an ArgumentError when the sin_family is not AF_INET" do
|
12
|
-
sockaddr = Socket.sockaddr_un '/tmp/x'
|
13
|
-
lambda { Socket.unpack_sockaddr_in sockaddr }.should raise_error(ArgumentError)
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
describe "Socket::TCPServer.accept_nonblock" do
|
4
|
-
before :each do
|
5
|
-
@server = TCPServer.new("127.0.0.1", SocketSpecs.port)
|
6
|
-
end
|
7
|
-
|
8
|
-
after :each do
|
9
|
-
@server.close
|
10
|
-
end
|
11
|
-
|
12
|
-
it "accepts non blocking connections" do
|
13
|
-
@server.listen(5)
|
14
|
-
lambda { @server.accept_nonblock}.should raise_error(Errno::EAGAIN)
|
15
|
-
|
16
|
-
c = TCPSocket.new("127.0.0.1", SocketSpecs.port)
|
17
|
-
sleep 0.1
|
18
|
-
s = @server.accept_nonblock
|
19
|
-
|
20
|
-
# commenting while we get some input on the current JRuby situation
|
21
|
-
# port, address = Socket.unpack_sockaddr_in(s.getsockname)
|
22
|
-
|
23
|
-
# port.should == SocketSpecs.port
|
24
|
-
# address.should == "127.0.0.1"
|
25
|
-
s.should be_kind_of(TCPSocket)
|
26
|
-
|
27
|
-
c.close
|
28
|
-
s.close
|
29
|
-
end
|
30
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
-
|
3
|
-
|
4
|
-
describe "TCPServer#accept" do
|
5
|
-
before :each do
|
6
|
-
@server = TCPServer.new("127.0.0.1", SocketSpecs.port)
|
7
|
-
end
|
8
|
-
|
9
|
-
after :each do
|
10
|
-
@server.close unless @server.closed?
|
11
|
-
end
|
12
|
-
|
13
|
-
it "accepts a connection and returns a TCPSocket" do
|
14
|
-
data = nil
|
15
|
-
t = Thread.new do
|
16
|
-
client = @server.accept
|
17
|
-
client.should be_kind_of(TCPSocket)
|
18
|
-
data = client.read(5)
|
19
|
-
client << "goodbye"
|
20
|
-
client.close
|
21
|
-
end
|
22
|
-
Thread.pass while t.status and t.status != "sleep"
|
23
|
-
|
24
|
-
socket = TCPSocket.new('127.0.0.1', SocketSpecs.port)
|
25
|
-
socket.write('hello')
|
26
|
-
socket.shutdown(1) # we are done with sending
|
27
|
-
socket.read.should == 'goodbye'
|
28
|
-
t.join
|
29
|
-
data.should == 'hello'
|
30
|
-
socket.close
|
31
|
-
end
|
32
|
-
|
33
|
-
it "can be interrupted by Thread#kill" do
|
34
|
-
t = Thread.new { @server.accept }
|
35
|
-
|
36
|
-
Thread.pass while t.status and t.status != "sleep"
|
37
|
-
|
38
|
-
# kill thread, ensure it dies in a reasonable amount of time
|
39
|
-
t.kill
|
40
|
-
a = 1
|
41
|
-
while a < 2000
|
42
|
-
break unless t.alive?
|
43
|
-
Thread.pass
|
44
|
-
sleep 0.2
|
45
|
-
a += 1
|
46
|
-
end
|
47
|
-
a.should < 2000
|
48
|
-
end
|
49
|
-
|
50
|
-
it "can be interrupted by Thread#raise" do
|
51
|
-
t = Thread.new { @server.accept }
|
52
|
-
|
53
|
-
Thread.pass while t.status and t.status != "sleep"
|
54
|
-
|
55
|
-
# raise in thread, ensure the raise happens
|
56
|
-
ex = Exception.new
|
57
|
-
t.raise ex
|
58
|
-
lambda { t.join }.should raise_error(Exception)
|
59
|
-
end
|
60
|
-
end
|