11 @srv.close unless @srv.closed?
12 FileUtils.remove_entry_secure(@tmpdir) if defined?(@tmpdir)
13 Kgio.accept_cloexec = true
14 Kgio.accept_nonblock = false
17 def test_tryaccept_success
20 b = @srv.kgio_tryaccept
21 assert_kind_of Kgio::Socket, b
22 assert_equal @host, b.kgio_addr
25 def test_tryaccept_flags
28 b = @srv.kgio_tryaccept nil, 0
29 assert_kind_of Kgio::Socket, b
30 assert_equal 0, b.fcntl(Fcntl::F_GETFD)
33 def test_blocking_accept_flags
36 b = @srv.kgio_accept nil, 0
37 assert_kind_of Kgio::Socket, b
38 assert_equal 0, b.fcntl(Fcntl::F_GETFD)
41 def test_tryaccept_fail
42 assert_equal nil, @srv.kgio_tryaccept
45 def test_blocking_accept
47 pid = fork { sleep 1; a = client_connect; sleep }
49 elapsed = Time.now - t0
50 assert_kind_of Kgio::Socket, b
51 assert_equal @host, b.kgio_addr
52 Process.kill(:KILL, pid)
54 assert elapsed >= 1, "elapsed: #{elapsed}"
57 def test_blocking_accept_with_nonblock_socket
60 pid = fork { sleep 1; a = client_connect; sleep }
62 elapsed = Time.now - t0
63 assert_kind_of Kgio::Socket, b
64 assert_equal @host, b.kgio_addr
65 Process.kill(:KILL, pid)
67 assert elapsed >= 1, "elapsed: #{elapsed}"
70 pid = fork { sleep 6; a = client_connect; sleep }
72 elapsed = Time.now - t0
73 assert_kind_of Kgio::Socket, b
74 assert_equal @host, b.kgio_addr
75 Process.kill(:KILL, pid)
77 assert elapsed >= 6, "elapsed: #{elapsed}"
80 pid = fork { sleep 1; a = client_connect; sleep }
82 elapsed = Time.now - t0
83 assert_kind_of Kgio::Socket, b
84 assert_equal @host, b.kgio_addr
85 Process.kill(:KILL, pid)
87 assert elapsed >= 1, "elapsed: #{elapsed}"