diff options
author | Eric Wong <normalperson@yhbt.net> | 2014-02-04 00:51:59 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2014-02-04 01:43:03 +0000 |
commit | 070b5aeb9313ef09303dffa7bc72c771f6f86f31 (patch) | |
tree | 0048fd8ad2eb5b9099d8142226ecc74630260204 /test | |
parent | a876a30e4bfae6e3aa4af2e34f68bf66be5715b4 (diff) | |
download | kgio-070b5aeb9313ef09303dffa7bc72c771f6f86f31.tar.gz |
This behaves like kgio_trywrite on GNU/Linux, but allows extra flags to be specified. The main purpose of this is to support use of the MSG_MORE flag on GNU/Linux.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_syssend.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/test_syssend.rb b/test/test_syssend.rb new file mode 100644 index 0000000..5089ce3 --- /dev/null +++ b/test/test_syssend.rb @@ -0,0 +1,43 @@ +require 'test/unit' +require 'kgio' + +class TestKgioSyssend < Test::Unit::TestCase + def setup + @host = '127.0.0.1' || ENV["TEST_HOST"] + end + + def test_syssend + srv = Kgio::TCPServer.new(@host, 0) + port = srv.addr[1] + client = TCPSocket.new(@host, port) + acc = srv.kgio_accept + th = Thread.new { client.readpartial(4) } + sleep(0.05) + assert_nil acc.kgio_syssend("HI", Socket::MSG_DONTWAIT | Socket::MSG_MORE) + assert_nil acc.kgio_syssend("HI", Socket::MSG_DONTWAIT) + assert_equal "HIHI", th.value + + buf = "*" * 123 + res = [] + case rv = acc.kgio_syssend(buf, Socket::MSG_DONTWAIT) + when nil + when String + res << rv + when Symbol + res << rv + break + end while true + assert_equal :wait_writable, res.last + if res.size > 1 + assert_kind_of String, res[-2] + else + warn "res too small" + end + + # blocking + th = Thread.new { loop { acc.kgio_syssend("ZZZZ", 0) } } + assert_nil th.join(0.1) + ensure + [ srv, acc, client ].each { |io| io.close if io } + end +end if RUBY_PLATFORM =~ /linux/ |