7 class TestTCPCopyStream < Test::Unit::TestCase
9 host = ENV["TEST_HOST"] || "127.0.0.1"
10 @srv = TCPServer.new(host, 0)
12 @client = TCPSocket.new(host, @port)
13 @client.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
15 @accept.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
16 @client.sync = @accept.sync = true
22 [ @client, @accept, @r, @w ].each { |io| io.close unless io.closed? }
25 def test_client_to_server_eof
27 buf = '0123456789abcdef' * 1024
28 expect = buf.size * nr
30 nr.times { @client.write(buf) }
33 sleep 1 # wait for rcvbuf to fill up
34 bytes = IO::Splice.copy_stream(@accept, "/dev/null")
35 assert_equal expect, bytes
38 def test_client_to_server_expect
40 buf = '0123456789abcdef' * 1024
41 expect = buf.size * nr
43 nr.times { @client.write(buf) }
45 sleep 1 # wait for rcvbuf to fill up
46 bytes = IO::Splice.copy_stream(@accept, "/dev/null", expect)
47 assert_equal expect, bytes
52 buf = '0123456789abcdef' * 1024
53 expect = buf.size * nr
55 nr.times { @client.write(buf) }
58 size_t_max = if (1 << 30).kind_of?(Bignum)
63 bytes = IO::Splice.copy_stream(@accept, "/dev/null", size_t_max)
64 assert_equal expect, bytes