File: ipsocket.rb

package info (click to toggle)
groonga 9.0.0-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 101,496 kB
  • sloc: ansic: 608,707; ruby: 35,042; xml: 23,643; cpp: 10,319; sh: 7,453; yacc: 5,968; python: 3,033; makefile: 2,609; perl: 133
file content (44 lines) | stat: -rw-r--r-- 920 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
unless SocketTest.win?

# Note: most of tests below will fail if UDPSocket is broken.

assert('IPSocket.getaddress') do
  l = IPSocket.getaddress("localhost")
  assert_true (l == "127.0.0.1" or l == "::1")
end

assert('IPSocket.addr') do
  localhost = "127.0.0.1"
  s = UDPSocket.new
  s.bind(localhost, 0)
  port = Addrinfo.new(s.getsockname).ip_port

  a = s.addr
  assert_equal "AF_INET", a[0]
  assert_equal port,      a[1]
  assert_equal localhost, a[2]
  assert_equal localhost, a[3]
  s.close
  true
end

assert('IPSocket.peeraddr') do
  localhost = "127.0.0.1"
  server = UDPSocket.new
  server.bind(localhost, 0)
  port = server.local_address.ip_port

  client = UDPSocket.new
  client.connect(localhost, port)

  a = client.peeraddr
  assert_equal "AF_INET", a[0]
  assert_equal port,      a[1]
  assert_equal localhost, a[2]
  assert_equal localhost, a[3]
  client.close
  server.close
  true
end

end # win?