test.diff

testcase for TCP fast open - Masaki Matsushita, 09/17/2013 11:48 PM

Download (1.12 KB)

View differences:

test/socket/test_socket.rb
575 575
      assert_instance_of(Socket::Ifaddr, ifaddr)
576 576
    }
577 577
  end
578

  
579
  def test_tcp_fastopen
580
    port = random_port
581
    serv = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM)
582
    serv.setsockopt(Socket::SOL_TCP, Socket::TCP_FASTOPEN, 5)
583
    addrinfo = Addrinfo.new(Socket.sockaddr_in(port, "localhost"))
584
    serv.bind(addrinfo)
585
    serv.listen(1)
586
    th = Thread.new do
587
      sock, = serv.accept
588
      begin
589
        assert_equal("foo", sock.read)
590
      ensure
591
        sock.close if sock && !sock.closed?
592
      end
593
    end
594

  
595
    sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM)
596
    len = sock.send("foo", Socket::MSG_FASTOPEN, Socket.sockaddr_in(port, "localhost"))
597
    assert_equal(len, 3)
598
    sock.close
599
    assert(th.join(10))
600
  ensure
601
    th.kill if th
602
    sock.close if sock && !sock.closed?
603
  end if defined?(Socket::TCP_FASTOPEN) && defined?(Socket::MSG_FASTOPEN)
578 604
end if defined?(Socket)