rubysl-socket 2.0.1 → 2.1.0

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.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +70 -16
  3. data/lib/rubysl/socket.rb +201 -1396
  4. data/lib/rubysl/socket/ancillary_data.rb +56 -0
  5. data/lib/rubysl/socket/bsd.rb +28 -0
  6. data/lib/rubysl/socket/error.rb +67 -0
  7. data/lib/rubysl/socket/foreign.rb +324 -0
  8. data/lib/rubysl/socket/foreign/addrinfo.rb +10 -0
  9. data/lib/rubysl/socket/foreign/hostent.rb +36 -0
  10. data/lib/rubysl/socket/foreign/ifaddrs.rb +129 -0
  11. data/lib/rubysl/socket/foreign/iovec.rb +18 -0
  12. data/lib/rubysl/socket/foreign/linger.rb +41 -0
  13. data/lib/rubysl/socket/foreign/msghdr.rb +41 -0
  14. data/lib/rubysl/socket/foreign/servent.rb +17 -0
  15. data/lib/rubysl/socket/foreign/sockaddr.rb +21 -0
  16. data/lib/rubysl/socket/foreign/sockaddr_in.rb +25 -0
  17. data/lib/rubysl/socket/foreign/sockaddr_in6.rb +25 -0
  18. data/lib/rubysl/socket/foreign/sockaddr_un.rb +29 -0
  19. data/lib/rubysl/socket/ipv6.rb +38 -0
  20. data/lib/rubysl/socket/linux.rb +16 -0
  21. data/lib/rubysl/socket/socket_options.rb +84 -0
  22. data/lib/rubysl/socket/version.rb +1 -1
  23. data/lib/socket.rb +45 -1
  24. data/lib/socket/addrinfo.rb +453 -0
  25. data/lib/socket/ancillary_data.rb +114 -0
  26. data/lib/socket/basic_socket.rb +295 -0
  27. data/lib/socket/constants.rb +41 -0
  28. data/lib/socket/ifaddr.rb +29 -0
  29. data/lib/socket/ip_socket.rb +37 -0
  30. data/lib/socket/mri.rb +928 -0
  31. data/lib/socket/option.rb +96 -0
  32. data/lib/socket/socket.rb +353 -0
  33. data/lib/socket/socket_error.rb +2 -0
  34. data/lib/socket/tcp_server.rb +78 -0
  35. data/lib/socket/tcp_socket.rb +109 -0
  36. data/lib/socket/udp_socket.rb +73 -0
  37. data/lib/socket/unix_server.rb +35 -0
  38. data/lib/socket/unix_socket.rb +78 -0
  39. data/rubysl-socket.gemspec +15 -10
  40. metadata +78 -293
  41. data/.gitignore +0 -17
  42. data/.travis.yml +0 -9
  43. data/Gemfile +0 -4
  44. data/Rakefile +0 -1
  45. data/spec/addrinfo/afamily_spec.rb +0 -5
  46. data/spec/addrinfo/bind_spec.rb +0 -5
  47. data/spec/addrinfo/canonname_spec.rb +0 -5
  48. data/spec/addrinfo/connect_from_spec.rb +0 -5
  49. data/spec/addrinfo/connect_spec.rb +0 -5
  50. data/spec/addrinfo/connect_to_spec.rb +0 -5
  51. data/spec/addrinfo/family_addrinfo_spec.rb +0 -5
  52. data/spec/addrinfo/foreach_spec.rb +0 -5
  53. data/spec/addrinfo/getaddrinfo_spec.rb +0 -5
  54. data/spec/addrinfo/getnameinfo_spec.rb +0 -5
  55. data/spec/addrinfo/inspect_sockaddr_spec.rb +0 -5
  56. data/spec/addrinfo/inspect_spec.rb +0 -5
  57. data/spec/addrinfo/ip_address_spec.rb +0 -5
  58. data/spec/addrinfo/ip_port_spec.rb +0 -5
  59. data/spec/addrinfo/ip_spec.rb +0 -9
  60. data/spec/addrinfo/ip_unpack_spec.rb +0 -5
  61. data/spec/addrinfo/ipv4_loopback_spec.rb +0 -5
  62. data/spec/addrinfo/ipv4_multicast_spec.rb +0 -5
  63. data/spec/addrinfo/ipv4_private_spec.rb +0 -5
  64. data/spec/addrinfo/ipv4_spec.rb +0 -5
  65. data/spec/addrinfo/ipv6_linklocal_spec.rb +0 -5
  66. data/spec/addrinfo/ipv6_loopback_spec.rb +0 -5
  67. data/spec/addrinfo/ipv6_mc_global_spec.rb +0 -5
  68. data/spec/addrinfo/ipv6_mc_linklocal_spec.rb +0 -5
  69. data/spec/addrinfo/ipv6_mc_nodelocal_spec.rb +0 -5
  70. data/spec/addrinfo/ipv6_mc_orglocal_spec.rb +0 -5
  71. data/spec/addrinfo/ipv6_mc_sitelocal_spec.rb +0 -5
  72. data/spec/addrinfo/ipv6_multicast_spec.rb +0 -5
  73. data/spec/addrinfo/ipv6_sitelocal_spec.rb +0 -5
  74. data/spec/addrinfo/ipv6_spec.rb +0 -5
  75. data/spec/addrinfo/ipv6_to_ipv4_spec.rb +0 -5
  76. data/spec/addrinfo/ipv6_unspecified_spec.rb +0 -5
  77. data/spec/addrinfo/ipv6_v4compat_spec.rb +0 -5
  78. data/spec/addrinfo/ipv6_v4mapped_spec.rb +0 -5
  79. data/spec/addrinfo/listen_spec.rb +0 -5
  80. data/spec/addrinfo/marshal_dump_spec.rb +0 -5
  81. data/spec/addrinfo/marshal_load_spec.rb +0 -5
  82. data/spec/addrinfo/pfamily_spec.rb +0 -5
  83. data/spec/addrinfo/protocol_spec.rb +0 -5
  84. data/spec/addrinfo/socktype_spec.rb +0 -5
  85. data/spec/addrinfo/tcp_spec.rb +0 -5
  86. data/spec/addrinfo/to_s_spec.rb +0 -5
  87. data/spec/addrinfo/to_sockaddr_spec.rb +0 -5
  88. data/spec/addrinfo/udp_spec.rb +0 -5
  89. data/spec/addrinfo/unix_path_spec.rb +0 -5
  90. data/spec/addrinfo/unix_spec.rb +0 -9
  91. data/spec/basicsocket/close_read_spec.rb +0 -42
  92. data/spec/basicsocket/close_write_spec.rb +0 -42
  93. data/spec/basicsocket/do_not_reverse_lookup_spec.rb +0 -78
  94. data/spec/basicsocket/for_fd_spec.rb +0 -37
  95. data/spec/basicsocket/getpeername_spec.rb +0 -24
  96. data/spec/basicsocket/getsockname_spec.rb +0 -27
  97. data/spec/basicsocket/getsockopt_spec.rb +0 -54
  98. data/spec/basicsocket/ioctl_spec.rb +0 -22
  99. data/spec/basicsocket/recv_nonblock_spec.rb +0 -6
  100. data/spec/basicsocket/recv_spec.rb +0 -76
  101. data/spec/basicsocket/send_spec.rb +0 -81
  102. data/spec/basicsocket/setsockopt_spec.rb +0 -333
  103. data/spec/basicsocket/shutdown_spec.rb +0 -5
  104. data/spec/constants/constants_spec.rb +0 -63
  105. data/spec/fixtures/classes.rb +0 -174
  106. data/spec/fixtures/send_io.txt +0 -1
  107. data/spec/ipsocket/addr_spec.rb +0 -72
  108. data/spec/ipsocket/getaddress_spec.rb +0 -26
  109. data/spec/ipsocket/peeraddr_spec.rb +0 -79
  110. data/spec/ipsocket/recvfrom_spec.rb +0 -64
  111. data/spec/option/int_spec.rb +0 -27
  112. data/spec/option/linger_spec.rb +0 -52
  113. data/spec/option/new_spec.rb +0 -32
  114. data/spec/shared/pack_sockaddr.rb +0 -26
  115. data/spec/shared/partially_closable_sockets.rb +0 -13
  116. data/spec/shared/recv_nonblock.rb +0 -33
  117. data/spec/shared/socketpair.rb +0 -35
  118. data/spec/socket/accept_nonblock_spec.rb +0 -27
  119. data/spec/socket/accept_spec.rb +0 -1
  120. data/spec/socket/bind_spec.rb +0 -80
  121. data/spec/socket/connect_nonblock_spec.rb +0 -62
  122. data/spec/socket/connect_spec.rb +0 -1
  123. data/spec/socket/for_fd_spec.rb +0 -29
  124. data/spec/socket/getaddrinfo_spec.rb +0 -120
  125. data/spec/socket/gethostbyaddr_spec.rb +0 -1
  126. data/spec/socket/gethostbyname_spec.rb +0 -26
  127. data/spec/socket/gethostname_spec.rb +0 -9
  128. data/spec/socket/getnameinfo_spec.rb +0 -57
  129. data/spec/socket/getservbyname_spec.rb +0 -24
  130. data/spec/socket/listen_spec.rb +0 -21
  131. data/spec/socket/new_spec.rb +0 -109
  132. data/spec/socket/pack_sockaddr_in_spec.rb +0 -6
  133. data/spec/socket/pack_sockaddr_un_spec.rb +0 -6
  134. data/spec/socket/pair_spec.rb +0 -6
  135. data/spec/socket/recvfrom_nonblock_spec.rb +0 -1
  136. data/spec/socket/recvfrom_spec.rb +0 -1
  137. data/spec/socket/sockaddr_in_spec.rb +0 -6
  138. data/spec/socket/sockaddr_un_spec.rb +0 -6
  139. data/spec/socket/socket_spec.rb +0 -37
  140. data/spec/socket/socketpair_spec.rb +0 -6
  141. data/spec/socket/sysaccept_spec.rb +0 -1
  142. data/spec/socket/unpack_sockaddr_in_spec.rb +0 -16
  143. data/spec/socket/unpack_sockaddr_un_spec.rb +0 -2
  144. data/spec/tcpserver/accept_nonblock_spec.rb +0 -30
  145. data/spec/tcpserver/accept_spec.rb +0 -60
  146. data/spec/tcpserver/gets_spec.rb +0 -17
  147. data/spec/tcpserver/listen_spec.rb +0 -1
  148. data/spec/tcpserver/new_spec.rb +0 -88
  149. data/spec/tcpserver/output_spec.rb +0 -8
  150. data/spec/tcpserver/readpartial_spec.rb +0 -8
  151. data/spec/tcpserver/sysaccept_spec.rb +0 -1
  152. data/spec/tcpsocket/gethostbyname_spec.rb +0 -62
  153. data/spec/tcpsocket/new_spec.rb +0 -5
  154. data/spec/tcpsocket/open_spec.rb +0 -5
  155. data/spec/tcpsocket/partially_closable_spec.rb +0 -20
  156. data/spec/tcpsocket/recv_nonblock_spec.rb +0 -31
  157. data/spec/tcpsocket/setsockopt_spec.rb +0 -49
  158. data/spec/tcpsocket/shared/new.rb +0 -85
  159. data/spec/udpsocket/bind_spec.rb +0 -33
  160. data/spec/udpsocket/connect_spec.rb +0 -1
  161. data/spec/udpsocket/new_spec.rb +0 -1
  162. data/spec/udpsocket/open_spec.rb +0 -12
  163. data/spec/udpsocket/recvfrom_nonblock_spec.rb +0 -1
  164. data/spec/udpsocket/send_spec.rb +0 -57
  165. data/spec/unixserver/accept_nonblock_spec.rb +0 -33
  166. data/spec/unixserver/accept_spec.rb +0 -64
  167. data/spec/unixserver/for_fd_spec.rb +0 -32
  168. data/spec/unixserver/new_spec.rb +0 -5
  169. data/spec/unixserver/open_spec.rb +0 -25
  170. data/spec/unixserver/shared/new.rb +0 -23
  171. data/spec/unixsocket/addr_spec.rb +0 -37
  172. data/spec/unixsocket/new_spec.rb +0 -5
  173. data/spec/unixsocket/open_spec.rb +0 -26
  174. data/spec/unixsocket/pair_spec.rb +0 -38
  175. data/spec/unixsocket/partially_closable_spec.rb +0 -25
  176. data/spec/unixsocket/path_spec.rb +0 -29
  177. data/spec/unixsocket/peeraddr_spec.rb +0 -29
  178. data/spec/unixsocket/recv_io_spec.rb +0 -40
  179. data/spec/unixsocket/recvfrom_spec.rb +0 -48
  180. data/spec/unixsocket/send_io_spec.rb +0 -30
  181. data/spec/unixsocket/shared/new.rb +0 -25
@@ -1,17 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "TCPServer#gets" do
4
- before :each do
5
- @server = TCPServer.new(SocketSpecs.hostname, SocketSpecs.port)
6
- end
7
-
8
- after :each do
9
- @server.close
10
- end
11
-
12
- ruby_bug "#", "1.8" do
13
- it "raises Errno::ENOTCONN on gets" do
14
- lambda { @server.gets }.should raise_error(Errno::ENOTCONN)
15
- end
16
- end
17
- end
@@ -1 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
@@ -1,88 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "TCPServer.new" do
4
- after(:each) do
5
- @server.close if @server && !@server.closed?
6
- end
7
-
8
- it "binds to a host and a port" do
9
- @server = TCPServer.new('127.0.0.1', SocketSpecs.port)
10
- addr = @server.addr
11
- addr[0].should == 'AF_INET'
12
- addr[1].should be_kind_of(Fixnum)
13
- # on some platforms (Mac), MRI
14
- # returns comma at the end.
15
- addr[2].should =~ /^#{SocketSpecs.hostname}\b/
16
- addr[3].should == '127.0.0.1'
17
- end
18
-
19
- it "binds to localhost and a port with either IPv4 or IPv6" do
20
- @server = TCPServer.new(SocketSpecs.hostname, SocketSpecs.port)
21
- addr = @server.addr
22
- if addr[0] == 'AF_INET'
23
- addr[1].should == SocketSpecs.port
24
- addr[2].should =~ /^#{SocketSpecs.hostname}\b/
25
- addr[3].should == '127.0.0.1'
26
- else
27
- addr[1].should == SocketSpecs.port
28
- addr[2].should =~ /^#{SocketSpecs.hostnamev6}\b/
29
- addr[3].should == '::1'
30
- end
31
- end
32
-
33
- it "binds to INADDR_ANY if the hostname is empty" do
34
- @server = TCPServer.new('', SocketSpecs.port)
35
- addr = @server.addr
36
- addr[0].should == 'AF_INET'
37
- addr[1].should == SocketSpecs.port
38
- expected = ['', '0.0.0.0']
39
- expected.should include(addr[2])
40
- addr[3].should == '0.0.0.0'
41
- end
42
-
43
- it "binds to INADDR_ANY if the hostname is empty and the port is a string" do
44
- @server = TCPServer.new('', SocketSpecs.port.to_s)
45
- addr = @server.addr
46
- addr[0].should == 'AF_INET'
47
- addr[1].should == SocketSpecs.port
48
- expected = ['', '0.0.0.0']
49
- expected.should include(addr[2])
50
- addr[3].should == '0.0.0.0'
51
- end
52
-
53
- it "coerces port to string, then determines port from that number or service name" do
54
- t = Object.new
55
- lambda { TCPServer.new(SocketSpecs.hostname, t) }.should raise_error(TypeError)
56
-
57
- def t.to_str; SocketSpecs.port.to_s; end
58
-
59
- @server = TCPServer.new(SocketSpecs.hostname, t)
60
- addr = @server.addr
61
- addr[1].should == SocketSpecs.port
62
-
63
- # TODO: This should also accept strings like 'https', but I don't know how to
64
- # pick such a service port that will be able to reliably bind...
65
- end
66
-
67
- it "raises Errno::EADDRNOTAVAIL when the adress is unknown" do
68
- lambda { TCPServer.new("1.2.3.4", 4000) }.should raise_error(Errno::EADDRNOTAVAIL)
69
- end
70
-
71
- # There is no way to make this fail-proof on all machines, because
72
- # DNS servers like opendns return A records for ANY host, including
73
- # traditionally invalidly named ones.
74
- quarantine! do
75
- it "raises a SocketError when the host is unknown" do
76
- lambda {
77
- TCPServer.new("--notavalidname", 4000)
78
- }.should raise_error(SocketError)
79
- end
80
- end
81
-
82
- it "raises Errno::EADDRINUSE when address is already in use" do
83
- lambda {
84
- @server = TCPServer.new('127.0.0.1', SocketSpecs.port)
85
- @server = TCPServer.new('127.0.0.1', SocketSpecs.port)
86
- }.should raise_error(Errno::EADDRINUSE)
87
- end
88
- end
@@ -1,8 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "TCPServer#<<" do
4
- after(:each) do
5
- @server.close if @server
6
- @socket.close if @socket
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "TCPServer#readpartial" do
4
- after(:each) do
5
- @server.close if @server
6
- @socket.close if @socket
7
- end
8
- end
@@ -1 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
@@ -1,62 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- # TODO: verify these for windows
4
- describe "TCPSocket#gethostbyname" do
5
- before :each do
6
- @host_info = TCPSocket.gethostbyname(SocketSpecs.hostname)
7
- end
8
-
9
- it "returns an array elements of information on the hostname" do
10
- @host_info.should be_kind_of(Array)
11
- end
12
-
13
- platform_is_not :windows do
14
- it "returns the canonical name as first value" do
15
- @host_info[0].should == SocketSpecs.hostname
16
- end
17
-
18
- not_compliant_on :jruby do
19
- it "returns the address type as the third value" do
20
- address_type = @host_info[2]
21
- [Socket::AF_INET, Socket::AF_INET6].include?(address_type).should be_true
22
- end
23
-
24
- it "returns the IP address as the fourth value" do
25
- ip = @host_info[3]
26
- ["127.0.0.1", "::1"].include?(ip).should be_true
27
- end
28
- end
29
-
30
- deviates_on :jruby do
31
- it "returns the address type as the third value" do
32
- address_type = @host_info[2]
33
- [Socket::AF_INET, Socket::AF_INET6].include?(address_type).should be_true
34
- end
35
-
36
- it "returns the IP address as the fourth value" do
37
- ip = @host_info[3]
38
- ["127.0.0.1", "::1"].include?(ip).should be_true
39
- end
40
- end
41
- end
42
-
43
- platform_is :windows do
44
- it "returns the canonical name as first value" do
45
- host = "#{ENV['COMPUTERNAME'].downcase}"
46
- host << ".#{ENV['USERDNSDOMAIN'].downcase}" if ENV['USERDNSDOMAIN']
47
- @host_info[0].should == host
48
- end
49
-
50
- it "returns the address type as the third value" do
51
- @host_info[2].should == Socket::AF_INET
52
- end
53
-
54
- it "returns the IP address as the fourth value" do
55
- @host_info[3].should == "127.0.0.1"
56
- end
57
- end
58
-
59
- it "returns any aliases to the address as second value" do
60
- @host_info[1].should be_kind_of(Array)
61
- end
62
- end
@@ -1,5 +0,0 @@
1
- require File.expand_path('../shared/new', __FILE__)
2
-
3
- describe "TCPSocket.new" do
4
- it_behaves_like :tcpsocket_new, :new
5
- end
@@ -1,5 +0,0 @@
1
- require File.expand_path('../shared/new', __FILE__)
2
-
3
- describe "TCPSocket.open" do
4
- it_behaves_like :tcpsocket_new, :open
5
- end
@@ -1,20 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
- require File.expand_path('../../shared/partially_closable_sockets', __FILE__)
3
-
4
- describe "TCPSocket partial closability" do
5
-
6
- before :each do
7
- @server = TCPServer.new("127.0.0.1", SocketSpecs.port+1)
8
- @s1 = TCPSocket.new("127.0.0.1", SocketSpecs.port+1)
9
- @s2 = @server.accept
10
- end
11
-
12
- after :each do
13
- @server.close
14
- @s1.close
15
- @s2.close
16
- end
17
-
18
- it_should_behave_like "partially closable sockets"
19
-
20
- end
@@ -1,31 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "TCPSocket#recv_nonblock" do
4
- before :all do
5
- SocketSpecs::SpecTCPServer.start
6
- end
7
-
8
- before :each do
9
- @hostname = SocketSpecs::SpecTCPServer.get.hostname
10
- @socket = nil
11
- end
12
-
13
- after :each do
14
- if @socket
15
- @socket.write "QUIT"
16
- @socket.close
17
- end
18
- end
19
-
20
- it "returns a String read from the socket" do
21
- @socket = TCPSocket.new @hostname, SocketSpecs.port
22
- @socket.write "TCPSocket#recv_nonblock"
23
-
24
- # Wait for the server to echo. This spec is testing the return
25
- # value, not the non-blocking behavior.
26
- #
27
- # TODO: Figure out a good way to test non-blocking.
28
- IO.select([@socket])
29
- @socket.recv_nonblock(50).should == "TCPSocket#recv_nonblock"
30
- end
31
- end
@@ -1,49 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "TCPSocket#setsockopt" do
4
- before :all do
5
- SocketSpecs::SpecTCPServer.start
6
- end
7
-
8
- before(:each) do
9
- hostname = SocketSpecs::SpecTCPServer.get.hostname
10
- port = SocketSpecs::SpecTCPServer.get.port
11
- @sock = TCPSocket.new(hostname, port)
12
- end
13
-
14
- after :each do
15
- @sock.close unless @sock.closed?
16
- end
17
-
18
- describe "using constants" do
19
- it "sets the TCP nodelay to 1" do
20
- @sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1).should == 0
21
- end
22
- end
23
-
24
- ruby_version_is "1.9" do
25
- describe "using symbols" do
26
- it "sets the TCP nodelay to 1" do
27
- @sock.setsockopt(:IPPROTO_TCP, :TCP_NODELAY, 1).should == 0
28
- end
29
-
30
- context "without prefix" do
31
- it "sets the TCP nodelay to 1" do
32
- @sock.setsockopt(:TCP, :NODELAY, 1).should == 0
33
- end
34
- end
35
- end
36
-
37
- describe "using strings" do
38
- it "sets the TCP nodelay to 1" do
39
- @sock.setsockopt('IPPROTO_TCP', 'TCP_NODELAY', 1).should == 0
40
- end
41
-
42
- context "without prefix" do
43
- it "sets the TCP nodelay to 1" do
44
- @sock.setsockopt('TCP', 'NODELAY', 1).should == 0
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,85 +0,0 @@
1
- require File.expand_path('../../../fixtures/classes', __FILE__)
2
-
3
- describe :tcpsocket_new, :shared => true do
4
- before :all do
5
- SocketSpecs::SpecTCPServer.start
6
- end
7
-
8
- after :all do
9
- SocketSpecs::SpecTCPServer.cleanup
10
- end
11
-
12
- before :each do
13
- @hostname = SocketSpecs::SpecTCPServer.get.hostname
14
- end
15
-
16
- it "requires a hostname and a port as arguments" do
17
- lambda { TCPSocket.send(@method) }.should raise_error(ArgumentError)
18
- end
19
-
20
- it "throws a type error if the port is not a fixnum or string" do
21
- lambda { TCPSocket.send(@method, @hostname, {}) }.should raise_error(TypeError)
22
- end
23
-
24
- it "refuses the connection when there is no server to connect to" do
25
- lambda do
26
- TCPSocket.send(@method, @hostname, SocketSpecs.local_port)
27
- end.should raise_error(Errno::ECONNREFUSED)
28
- end
29
-
30
- describe "with a running server" do
31
- before :each do
32
- @socket = nil
33
- end
34
-
35
- after :each do
36
- if @socket
37
- @socket.write "QUIT"
38
- @socket.shutdown
39
- @socket.close
40
- end
41
- end
42
-
43
- it "silently ignores 'nil' as the third parameter" do
44
- @socket = TCPSocket.send(@method, @hostname, SocketSpecs.port, nil)
45
- @socket.should be_an_instance_of(TCPSocket)
46
- end
47
-
48
- it "connects to a listening server with host and port" do
49
- @socket = TCPSocket.send(@method, @hostname, SocketSpecs.port)
50
- @socket.should be_an_instance_of(TCPSocket)
51
- end
52
-
53
- it "connects to a server when passed local_host argument" do
54
- @socket = TCPSocket.send(@method, @hostname, SocketSpecs.port, @hostname)
55
- @socket.should be_an_instance_of(TCPSocket)
56
- end
57
-
58
- it "connects to a server when passed local_host and local_port arguments" do
59
- @socket = TCPSocket.send(@method, @hostname, SocketSpecs.port,
60
- @hostname, SocketSpecs.local_port)
61
- @socket.should be_an_instance_of(TCPSocket)
62
- end
63
-
64
- it "has an address once it has connected to a listening server" do
65
- @socket = TCPSocket.send(@method, @hostname, SocketSpecs.port)
66
- @socket.should be_an_instance_of(TCPSocket)
67
-
68
- # TODO: Figure out how to abstract this. You can get AF_INET
69
- # from 'Socket.getaddrinfo(hostname, nil)[0][3]' but socket.addr
70
- # will return AF_INET6. At least this check will weed out clearly
71
- # erroneous values.
72
- @socket.addr[0].should =~ /^AF_INET6?/
73
-
74
- case @socket.addr[0]
75
- when 'AF_INET'
76
- @socket.addr[3].should == SocketSpecs.addr(:ipv4)
77
- when 'AF_INET6'
78
- @socket.addr[3].should == SocketSpecs.addr(:ipv6)
79
- end
80
-
81
- @socket.addr[1].should be_kind_of(Fixnum)
82
- @socket.addr[2].should =~ /^#{@hostname}/
83
- end
84
- end
85
- end
@@ -1,33 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "UDPSocket.bind" do
4
-
5
- before :each do
6
- @socket = UDPSocket.new
7
- end
8
-
9
- after :each do
10
- @socket.close unless @socket.closed?
11
- end
12
-
13
- it "binds the socket to a port" do
14
- @socket.bind(SocketSpecs.hostname, SocketSpecs.port)
15
-
16
- lambda { @socket.bind(SocketSpecs.hostname, SocketSpecs.port) }.should raise_error
17
- end
18
-
19
- it "receives a hostname and a port" do
20
- @socket.bind(SocketSpecs.hostname, SocketSpecs.port)
21
-
22
- port, host = Socket.unpack_sockaddr_in(@socket.getsockname)
23
-
24
- host.should == "127.0.0.1"
25
- port.should == SocketSpecs.port
26
- end
27
-
28
- it "binds to INADDR_ANY if the hostname is empty" do
29
- @socket.bind("", SocketSpecs.port)
30
- port, host = Socket.unpack_sockaddr_in(@socket.getsockname)
31
- host.should == "0.0.0.0"
32
- end
33
- end
@@ -1 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
@@ -1 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
@@ -1,12 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "UDPSocket.open" do
4
- after(:each) do
5
- @socket.close if @socket && !@socket.closed?
6
- end
7
-
8
- it "allows calls to open without arguments" do
9
- @socket = UDPSocket.open
10
- @socket.should be_kind_of(UDPSocket)
11
- end
12
- end