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.
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,5 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "Socket::BasicSocket#shutdown" do
4
-
5
- end
@@ -1,63 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
- include Socket::Constants
3
-
4
- describe "Socket::Constants" do
5
- it "defines socket types" do
6
- consts = ["SOCK_DGRAM", "SOCK_RAW", "SOCK_RDM", "SOCK_SEQPACKET", "SOCK_STREAM"]
7
- consts.each do |c|
8
- Socket::Constants.should have_constant(c)
9
- end
10
- end
11
-
12
- it "defines protocol families" do
13
- consts = ["PF_INET6", "PF_INET", "PF_IPX", "PF_UNIX", "PF_UNSPEC"]
14
- consts.each do |c|
15
- Socket::Constants.should have_constant(c)
16
- end
17
- end
18
-
19
- it "defines address families" do
20
- consts = ["AF_INET6", "AF_INET", "AF_IPX", "AF_UNIX", "AF_UNSPEC"]
21
- consts.each do |c|
22
- Socket::Constants.should have_constant(c)
23
- end
24
- end
25
-
26
- it "defines send/receive options" do
27
- consts = ["MSG_DONTROUTE", "MSG_OOB", "MSG_PEEK"]
28
- consts.each do |c|
29
- Socket::Constants.should have_constant(c)
30
- end
31
- end
32
-
33
- it "defines socket level options" do
34
- consts = ["SOL_SOCKET"]
35
- consts.each do |c|
36
- Socket::Constants.should have_constant(c)
37
- end
38
- end
39
-
40
- it "defines socket options" do
41
- consts = ["SO_BROADCAST", "SO_DEBUG", "SO_DONTROUTE", "SO_ERROR", "SO_KEEPALIVE", "SO_LINGER",
42
- "SO_OOBINLINE", "SO_RCVBUF", "SO_REUSEADDR", "SO_SNDBUF", "SO_TYPE"]
43
- consts.each do |c|
44
- Socket::Constants.should have_constant(c)
45
- end
46
-
47
- end
48
-
49
- it "defines multicast options" do
50
- consts = ["IP_ADD_MEMBERSHIP", "IP_DEFAULT_MULTICAST_LOOP", "IP_DEFAULT_MULTICAST_TTL",
51
- "IP_MAX_MEMBERSHIPS", "IP_MULTICAST_LOOP", "IP_MULTICAST_TTL"]
52
- consts.each do |c|
53
- Socket::Constants.should have_constant(c)
54
- end
55
- end
56
-
57
- it "defines TCP options" do
58
- consts = ["TCP_MAXSEG", "TCP_NODELAY"]
59
- consts.each do |c|
60
- Socket::Constants.should have_constant(c)
61
- end
62
- end
63
- end
@@ -1,174 +0,0 @@
1
- require 'socket'
2
-
3
- module SocketSpecs
4
- # helper to get the hostname associated to 127.0.0.1
5
- def self.hostname
6
- # Calculate each time, without caching, since the result might
7
- # depend on things like do_not_reverse_lookup mode, which is
8
- # changing from test to test
9
- Socket.getaddrinfo("127.0.0.1", nil)[0][2]
10
- end
11
-
12
- def self.hostnamev6
13
- Socket.getaddrinfo("::1", nil)[0][2]
14
- end
15
-
16
- def self.addr(which=:ipv4)
17
- case which
18
- when :ipv4
19
- host = "127.0.0.1"
20
- when :ipv6
21
- host = "::1"
22
- end
23
- Socket.getaddrinfo(host, nil)[0][3]
24
- end
25
-
26
- def self.port
27
- 43191
28
- end
29
-
30
- def self.str_port
31
- "43191"
32
- end
33
-
34
- def self.local_port
35
- @base ||= $$
36
- @base += 1
37
- local_port = (@base % (0xffff-1024)) + 1024
38
- local_port += 1 if local_port == port
39
- local_port
40
- end
41
-
42
- def self.sockaddr_in(port, host)
43
- Socket::SockAddr_In.new(Socket.sockaddr_in(port, host))
44
- end
45
-
46
- def self.socket_path
47
- tmp("unix_server_spec.socket", false)
48
- end
49
-
50
- # TCPServer that does not block waiting for connections. Each
51
- # connection is serviced in a separate thread. The data read
52
- # from the socket is echoed back. The server is shutdown when
53
- # the spec process exits.
54
- class SpecTCPServer
55
- @spec_server = nil
56
-
57
- def self.start(host=nil, port=nil, logger=nil)
58
- return if @spec_server
59
-
60
- @spec_server = new host, port, logger
61
- @spec_server.start
62
-
63
- at_exit do
64
- SocketSpecs::SpecTCPServer.shutdown
65
- end
66
- end
67
-
68
- def self.get
69
- @spec_server
70
- end
71
-
72
- # Clean up any waiting handlers.
73
- def self.cleanup
74
- @spec_server.cleanup if @spec_server
75
- end
76
-
77
- # Exit completely.
78
- def self.shutdown
79
- @spec_server.shutdown if @spec_server
80
- end
81
-
82
- attr_accessor :hostname, :port, :logger
83
-
84
- def initialize(host=nil, port=nil, logger=nil)
85
- @hostname = host || SocketSpecs.hostname
86
- @port = port || SocketSpecs.port
87
- @logger = logger
88
- @cleanup = false
89
- @shutdown = false
90
- @accepted = false
91
- @main = nil
92
- @server = nil
93
- @threads = []
94
- end
95
-
96
- def start
97
- @main = Thread.new do
98
- log "SpecTCPServer starting on #{@hostname}:#{@port}"
99
- @server = TCPServer.new @hostname, @port
100
-
101
- wait_for @server do
102
- socket = @server.accept
103
- log "SpecTCPServer accepted connection: #{socket}"
104
- service socket
105
-
106
- @accepted = true
107
- end
108
- end
109
-
110
- Thread.pass until @server
111
- end
112
-
113
- def service(socket)
114
- thr = Thread.new do
115
- begin
116
- wait_for socket do
117
- break if cleanup?
118
-
119
- data = socket.recv(1024)
120
- break if data.empty?
121
- log "SpecTCPServer received: #{data.inspect}"
122
-
123
- break if data == "QUIT"
124
-
125
- socket.send data, 0
126
- end
127
- ensure
128
- socket.close unless socket.closed?
129
- end
130
- end
131
-
132
- @threads << thr
133
- end
134
-
135
- def wait_for(io)
136
- return unless io
137
-
138
- loop do
139
- read, _, _ = IO.select([io], [], [], 0.25)
140
- return false if shutdown?
141
- yield if read
142
- end
143
- end
144
-
145
- def shutdown?
146
- @shutdown
147
- end
148
-
149
- def cleanup?
150
- @cleanup
151
- end
152
-
153
- def cleanup
154
- @cleanup = true
155
- log "SpecTCPServer cleaning up"
156
-
157
- @threads.each { |thr| thr.join }
158
- @cleanup = false
159
- end
160
-
161
- def shutdown
162
- @shutdown = true
163
- log "SpecTCPServer shutting down"
164
-
165
- @threads.each { |thr| thr.join }
166
- @main.join
167
- @server.close if @accepted and !@server.closed?
168
- end
169
-
170
- def log(message)
171
- @logger.puts message if @logger
172
- end
173
- end
174
- end
@@ -1 +0,0 @@
1
- This data is magic.
@@ -1,72 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "Socket::IPSocket#addr" do
4
- before :all do
5
- @do_not_reverse_lookup = BasicSocket.do_not_reverse_lookup
6
- end
7
-
8
-
9
- before :each do
10
- @socket = TCPServer.new("127.0.0.1", SocketSpecs.port)
11
- end
12
-
13
- after :each do
14
- @socket.close unless @socket.closed?
15
- BasicSocket.do_not_reverse_lookup = false
16
- end
17
-
18
- after :all do
19
- BasicSocket.do_not_reverse_lookup = @do_not_reverse_lookup
20
- end
21
-
22
- ruby_version_is ""..."1.9" do
23
- it "returns an array with the socket's information" do
24
- BasicSocket.do_not_reverse_lookup = false
25
-
26
- addrinfo = @socket.addr
27
- addrinfo[0].should == "AF_INET"
28
- addrinfo[1].should == SocketSpecs.port
29
- addrinfo[2].should == SocketSpecs.hostname
30
- addrinfo[3].should == "127.0.0.1"
31
- end
32
-
33
- it "returns an address in the array if do_not_reverse_lookup is true" do
34
- BasicSocket.do_not_reverse_lookup = true
35
- addrinfo = @socket.addr
36
- addrinfo[0].should == "AF_INET"
37
- addrinfo[1].should == SocketSpecs.port
38
- addrinfo[2].should == "127.0.0.1"
39
- addrinfo[3].should == "127.0.0.1"
40
- end
41
- end
42
-
43
- ruby_version_is "1.9" do
44
- it "returns an array with the socket's information" do
45
- @socket.do_not_reverse_lookup = false
46
- BasicSocket.do_not_reverse_lookup = false
47
- addrinfo = @socket.addr
48
- addrinfo[0].should == "AF_INET"
49
- addrinfo[1].should == SocketSpecs.port
50
- addrinfo[2].should == SocketSpecs.hostname
51
- addrinfo[3].should == "127.0.0.1"
52
- end
53
-
54
- it "returns an address in the array if do_not_reverse_lookup is true" do
55
- @socket.do_not_reverse_lookup = true
56
- BasicSocket.do_not_reverse_lookup = true
57
- addrinfo = @socket.addr
58
- addrinfo[0].should == "AF_INET"
59
- addrinfo[1].should == SocketSpecs.port
60
- addrinfo[2].should == "127.0.0.1"
61
- addrinfo[3].should == "127.0.0.1"
62
- end
63
-
64
- it "returns an address in the array if passed false" do
65
- addrinfo = @socket.addr(false)
66
- addrinfo[0].should == "AF_INET"
67
- addrinfo[1].should == SocketSpecs.port
68
- addrinfo[2].should == "127.0.0.1"
69
- addrinfo[3].should == "127.0.0.1"
70
- end
71
- end
72
- end
@@ -1,26 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "Socket::IPSocket#getaddress" do
4
-
5
- it "returns the IP address of hostname" do
6
- addr_local = IPSocket.getaddress(SocketSpecs.hostname)
7
- ["127.0.0.1", "::1"].include?(addr_local).should == true
8
- end
9
-
10
- it "returns the IP address when passed an IP" do
11
- IPSocket.getaddress("127.0.0.1").should == "127.0.0.1"
12
- IPSocket.getaddress("0.0.0.0").should == "0.0.0.0"
13
- end
14
-
15
- # There is no way to make this fail-proof on all machines, because
16
- # DNS servers like opendns return A records for ANY host, including
17
- # traditionally invalidly named ones.
18
- quarantine! do
19
- it "raises an error on unknown hostnames" do
20
- lambda {
21
- IPSocket.getaddress("rubyspecdoesntexist.fallingsnow.net")
22
- }.should raise_error(SocketError)
23
- end
24
- end
25
-
26
- end
@@ -1,79 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "Socket::IPSocket#peeraddr" do
4
- before :all do
5
- @do_not_reverse_lookup = BasicSocket.do_not_reverse_lookup
6
- end
7
-
8
- before :each do
9
- @server = TCPServer.new("127.0.0.1", SocketSpecs.port)
10
- @client = TCPSocket.new("127.0.0.1", SocketSpecs.port)
11
- end
12
-
13
- after :each do
14
- @server.close unless @server.closed?
15
- @client.close unless @client.closed?
16
- BasicSocket.do_not_reverse_lookup = false
17
- end
18
-
19
- after :all do
20
- BasicSocket.do_not_reverse_lookup = @do_not_reverse_lookup
21
- end
22
-
23
- it "raises error if socket is not connected" do
24
- lambda { @server.peeraddr }.should raise_error
25
- end
26
-
27
-
28
- ruby_version_is ""..."1.9" do
29
-
30
- it "returns an array of information on the peer" do
31
- BasicSocket.do_not_reverse_lookup = false
32
- addrinfo = @client.peeraddr
33
- addrinfo[0].should == "AF_INET"
34
- addrinfo[1].should == SocketSpecs.port
35
- addrinfo[2].should == SocketSpecs.hostname
36
- addrinfo[3].should == "127.0.0.1"
37
- end
38
-
39
- it "returns an IP instead of hostname if do_not_reverse_lookup is true" do
40
- BasicSocket.do_not_reverse_lookup = true
41
- addrinfo = @client.peeraddr
42
- addrinfo[0].should == "AF_INET"
43
- addrinfo[1].should == SocketSpecs.port
44
- addrinfo[2].should == "127.0.0.1"
45
- addrinfo[3].should == "127.0.0.1"
46
- end
47
- end
48
-
49
- ruby_version_is "1.9" do
50
-
51
- it "returns an array of information on the peer" do
52
- @client.do_not_reverse_lookup = false
53
- BasicSocket.do_not_reverse_lookup = false
54
- addrinfo = @client.peeraddr
55
- addrinfo[0].should == "AF_INET"
56
- addrinfo[1].should == SocketSpecs.port
57
- addrinfo[2].should == SocketSpecs.hostname
58
- addrinfo[3].should == "127.0.0.1"
59
- end
60
-
61
- it "returns an IP instead of hostname if do_not_reverse_lookup is true" do
62
- @client.do_not_reverse_lookup = true
63
- BasicSocket.do_not_reverse_lookup = true
64
- addrinfo = @client.peeraddr
65
- addrinfo[0].should == "AF_INET"
66
- addrinfo[1].should == SocketSpecs.port
67
- addrinfo[2].should == "127.0.0.1"
68
- addrinfo[3].should == "127.0.0.1"
69
- end
70
-
71
- it "returns an IP instead of hostname if passed false" do
72
- addrinfo = @client.peeraddr(false)
73
- addrinfo[0].should == "AF_INET"
74
- addrinfo[1].should == SocketSpecs.port
75
- addrinfo[2].should == "127.0.0.1"
76
- addrinfo[3].should == "127.0.0.1"
77
- end
78
- end
79
- end
@@ -1,64 +0,0 @@
1
- require File.expand_path('../../fixtures/classes', __FILE__)
2
-
3
- describe "Socket::IPSocket#recvfrom" do
4
-
5
- before :each do
6
- @server = TCPServer.new("127.0.0.1", SocketSpecs.port)
7
- @client = TCPSocket.new("127.0.0.1", SocketSpecs.port)
8
- end
9
-
10
- after :each do
11
- @server.close unless @server.closed?
12
- @client.close unless @client.closed?
13
- end
14
-
15
- it "reads data from the connection" do
16
- data = nil
17
- t = Thread.new do
18
- client = @server.accept
19
- data = client.recvfrom(6)
20
- client.close
21
- end
22
-
23
- @client.send('hello', 0)
24
- @client.shutdown rescue nil
25
- # shutdown may raise Errno::ENOTCONN when sent data is pending.
26
- t.join
27
-
28
- data.first.should == 'hello'
29
- end
30
-
31
- it "reads up to len bytes" do
32
- data = nil
33
- t = Thread.new do
34
- client = @server.accept
35
- data = client.recvfrom(3)
36
- client.close
37
- end
38
-
39
- @client.send('hello', 0)
40
- @client.shutdown rescue nil
41
- t.join
42
-
43
- data.first.should == 'hel'
44
- end
45
-
46
- it "returns an array with the data and connection info" do
47
- data = nil
48
- t = Thread.new do
49
- client = @server.accept
50
- data = client.recvfrom(3)
51
- client.close
52
- end
53
-
54
- @client.send('hello', 0)
55
- @client.shutdown rescue nil
56
- t.join
57
-
58
- data.size.should == 2
59
- data.first.should == "hel"
60
- # This does not apply to every platform, dependant on recvfrom(2)
61
- # data.last.should == nil
62
- end
63
-
64
- end