4 class TestTFO < Test::Unit::TestCase
6 if `uname -s`.chomp == "Linux" && `uname -r`.to_f >= 3.7
7 assert_equal 23, Kgio::TCP_FASTOPEN
8 assert_equal 0x20000000, Kgio::MSG_FASTOPEN
13 if RUBY_PLATFORM =~ /linux/
14 tfo = File.read("/proc/sys/net/ipv4/tcp_fastopen").to_i
17 enable = client_enable | server_enable
18 (tfo & enable) == enable
24 def test_tfo_client_server
26 warn "TCP Fast Open not enabled on this system (check kernel docs)"
31 s = Kgio::TCPServer.new(addr, 0)
32 s.setsockopt(:TCP, Kgio::TCP_FASTOPEN, qlen)
33 port = s.local_address.ip_port
34 addr = Socket.pack_sockaddr_in(port, addr)
35 c = Kgio::Socket.new(:INET, :STREAM)
36 assert_nil c.fastopen("HELLO", addr)
38 assert_equal "HELLO", a.read(5)
42 # ensure empty sends work
43 c = Kgio::Socket.new(:INET, :STREAM)
44 assert_nil c.fastopen("", addr)
46 Thread.new { c.close }
50 # try a monster packet
51 buf = 'x' * (1024 * 1024 * 320)
53 c = Kgio::Socket.new(:INET, :STREAM)
56 assert_equal buf.size, a.read(buf.size).size
59 assert_nil c.fastopen(buf, addr)
64 c = Kgio::Socket.new(:INET, :STREAM)
65 c.setsockopt(:SOCKET, :SNDTIMEO, [ 0, 10 ].pack("l_l_"))
66 unsent = c.fastopen(buf, addr)
68 assert_equal s.accept.read.size + unsent.size, buf.size
69 end if defined?(Addrinfo) && defined?(Kgio::TCP_FASTOPEN)