Sha256: 88f7c8bb91e43df89ee0a54e33861df08ed15f709af960774139484723b88df9
Contents?: true
Size: 1.67 KB
Versions: 1
Compression:
Stored size: 1.67 KB
Contents
require 'socket' require 'io/wait' require 'io/splice' require 'io/nonblock' require "test/unit" class TestTCPCopyStream < Test::Unit::TestCase def setup host = ENV["TEST_HOST"] || "127.0.0.1" @srv = TCPServer.new(host, 0) @port = @srv.addr[1] @client = TCPSocket.new(host, @port) @client.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 @accept = @srv.accept @accept.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 @client.sync = @accept.sync = true @r, @w = IO.pipe end def teardown @srv.close [ @client, @accept, @r, @w ].each { |io| io.close unless io.closed? } end def test_client_to_server_eof nr = 2000 buf = '0123456789abcdef' * 1024 expect = buf.size * nr thr = Thread.new do nr.times { @client.write(buf) } @client.close end sleep 1 # wait for rcvbuf to fill up bytes = IO::Splice.copy_stream(@accept, "/dev/null") assert_equal expect, bytes end def test_client_to_server_expect nr = 2000 buf = '0123456789abcdef' * 1024 expect = buf.size * nr thr = Thread.new do nr.times { @client.write(buf) } end sleep 1 # wait for rcvbuf to fill up bytes = IO::Splice.copy_stream(@accept, "/dev/null", expect) assert_equal expect, bytes end def test_mega_splice nr = 2000 buf = '0123456789abcdef' * 1024 expect = buf.size * nr thr = Thread.new do nr.times { @client.write(buf) } @client.close end size_t_max = if (1 << 30).kind_of?(Bignum) 0xffffffff else 0xffffffffffffffff end bytes = IO::Splice.copy_stream(@accept, "/dev/null", size_t_max) assert_equal expect, bytes end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
io_splice-4.2.0 | test/test_tcp_splice.rb |