drop remaining 1.8 and fragile autopush code paths
[kgio.git] / test / test_syssend.rb
bloba7224626b4fd43c6265ab94c559570998ebe99c7
1 require 'test/unit'
2 require 'kgio'
4 class TestKgioSyssend < Test::Unit::TestCase
5   def setup
6     @host = '127.0.0.1' || ENV["TEST_HOST"]
7   end
9   def test_syssend
10     srv = Kgio::TCPServer.new(@host, 0)
11     port = srv.addr[1]
12     client = TCPSocket.new(@host, port)
13     acc = srv.kgio_accept
14     th = Thread.new { client.readpartial(4) }
15     sleep(0.05)
16     assert_nil acc.kgio_syssend("HI", Socket::MSG_DONTWAIT | Socket::MSG_MORE)
17     assert_nil acc.kgio_syssend("HI", Socket::MSG_DONTWAIT)
18     assert_equal "HIHI", th.value
20     buf = "*" * 123
21     res = []
22     case rv = acc.kgio_syssend(buf, Socket::MSG_DONTWAIT)
23     when nil
24     when String
25       res << rv
26     when Symbol
27       res << rv
28       break
29     end while true
30     assert_equal :wait_writable, res.last
31     if res.size > 1
32       assert_kind_of String, res[-2]
33     else
34       warn "res too small"
35     end
37     # blocking
38     th = Thread.new { loop { acc.kgio_syssend("ZZZZ", 0) } }
39     assert_nil th.join(0.1)
40     th.kill
41     assert th.join(10), 'thread should be killed'
42   ensure
43     [ srv, acc, client ].each { |io| io.close if io }
44   end
45 end if RUBY_PLATFORM =~ /linux/ && Socket.const_defined?(:MSG_MORE)