From c478549ea7490de2432ed31ffee37a2bfc1d24f3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 12 Mar 2011 12:56:15 -0800 Subject: allow reusing netlink socket for inet_diag No need to waste resources on creating/destroying a socket. --- test/test_inet_diag_socket.rb | 13 +++++++++++++ test/test_linux.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/test_inet_diag_socket.rb (limited to 'test') diff --git a/test/test_inet_diag_socket.rb b/test/test_inet_diag_socket.rb new file mode 100644 index 0000000..c40d50e --- /dev/null +++ b/test/test_inet_diag_socket.rb @@ -0,0 +1,13 @@ +# -*- encoding: binary -*- +require 'test/unit' +require 'raindrops' +$stderr.sync = $stdout.sync = true + +class TestInetDiagSocket < Test::Unit::TestCase + def test_new + sock = Raindrops::InetDiagSocket.new + assert_kind_of Socket, sock + assert_kind_of Fixnum, sock.fileno + assert_nil sock.close + end +end if RUBY_PLATFORM =~ /linux/ diff --git a/test/test_linux.rb b/test/test_linux.rb index 5a7269d..d3c8da7 100644 --- a/test/test_linux.rb +++ b/test/test_linux.rb @@ -62,6 +62,32 @@ class TestLinux < Test::Unit::TestCase assert_equal 1, stats[addr].active end + def test_tcp_reuse_sock + nlsock = Raindrops::InetDiagSocket.new + s = TCPServer.new(TEST_ADDR, 0) + port = s.addr[1] + addr = "#{TEST_ADDR}:#{port}" + addrs = [ addr ] + stats = tcp_listener_stats(addrs, nlsock) + assert_equal 1, stats.size + assert_equal 0, stats[addr].queued + assert_equal 0, stats[addr].active + + c = TCPSocket.new(TEST_ADDR, port) + stats = tcp_listener_stats(addrs, nlsock) + assert_equal 1, stats.size + assert_equal 1, stats[addr].queued + assert_equal 0, stats[addr].active + + sc = s.accept + stats = tcp_listener_stats(addrs, nlsock) + assert_equal 1, stats.size + assert_equal 0, stats[addr].queued + assert_equal 1, stats[addr].active + ensure + nlsock.close + end + def test_tcp_multi s1 = TCPServer.new(TEST_ADDR, 0) s2 = TCPServer.new(TEST_ADDR, 0) -- cgit v1.2.3-24-ge0c7