reinstate the original (and dangerous) autopush in C
[kgio.git] / test / test_syssend.rb
blob7d2511a1c5b663f89eddbebd7312de953cce9af9
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   ensure
41     [ srv, acc, client ].each { |io| io.close if io }
42   end
43 end if RUBY_PLATFORM =~ /linux/ && Socket.const_defined?(:MSG_MORE)