10 @srv.close unless @srv.closed?
11 Kgio.accept_cloexec = true
12 Kgio.accept_nonblock = false
15 def test_tryaccept_success
18 b = @srv.kgio_tryaccept
19 assert_kind_of Kgio::Socket, b
20 assert_equal @host, b.kgio_addr
23 def test_tryaccept_flags
26 b = @srv.kgio_tryaccept nil, 0
27 assert_kind_of Kgio::Socket, b
28 assert_equal 0, b.fcntl(Fcntl::F_GETFD)
31 def test_blocking_accept_flags
34 b = @srv.kgio_accept nil, 0
35 assert_kind_of Kgio::Socket, b
36 assert_equal 0, b.fcntl(Fcntl::F_GETFD)
39 def test_tryaccept_fail
40 assert_equal nil, @srv.kgio_tryaccept
43 def test_blocking_accept
45 pid = fork { sleep 1; a = client_connect; sleep }
47 elapsed = Time.now - t0
48 assert_kind_of Kgio::Socket, b
49 assert_equal @host, b.kgio_addr
50 Process.kill(:TERM, pid)
52 assert elapsed >= 1, "elapsed: #{elapsed}"
55 def test_blocking_accept_with_nonblock_socket
58 pid = fork { sleep 1; a = client_connect; sleep }
60 elapsed = Time.now - t0
61 assert_kind_of Kgio::Socket, b
62 assert_equal @host, b.kgio_addr
63 Process.kill(:TERM, pid)
65 assert elapsed >= 1, "elapsed: #{elapsed}"
68 pid = fork { sleep 6; a = client_connect; sleep }
70 elapsed = Time.now - t0
71 assert_kind_of Kgio::Socket, b
72 assert_equal @host, b.kgio_addr
73 Process.kill(:TERM, pid)
75 assert elapsed >= 6, "elapsed: #{elapsed}"
78 pid = fork { sleep 1; a = client_connect; sleep }
80 elapsed = Time.now - t0
81 assert_kind_of Kgio::Socket, b
82 assert_equal @host, b.kgio_addr
83 Process.kill(:TERM, pid)
85 assert elapsed >= 1, "elapsed: #{elapsed}"