8 class SubSocket < Kgio::Socket
10 def kgio_wait_writable
15 class TestKgioUnixConnect < Test::Unit::TestCase
18 @tmpdir = Dir.mktmpdir('kgio_unix_1')
19 tmp = Tempfile.new('kgio_unix_1', @tmpdir)
22 @srv = Kgio::UNIXServer.new(@path)
23 @addr = Socket.pack_sockaddr_un(@path)
27 @srv.close unless @srv.closed?
29 FileUtils.remove_entry_secure(@tmpdir)
30 Kgio.accept_cloexec = true
33 def test_unix_socket_new_invalid
34 assert_raises(ArgumentError) { Kgio::UNIXSocket.new('*' * 1024 * 1024) }
37 def test_unix_socket_new
38 sock = Kgio::UNIXSocket.new(@path)
40 sock.respond_to?(:close_on_exec?) and
41 assert_equal(RUBY_VERSION.to_f >= 2.0, sock.close_on_exec?)
43 assert_instance_of Kgio::UNIXSocket, sock
44 ready = IO.select(nil, [ sock ])
45 assert_equal sock, ready[1][0]
46 assert_equal nil, sock.kgio_write("HELLO")
50 sock = Kgio::Socket.new(@addr)
52 sock.respond_to?(:close_on_exec?) and
53 assert_equal(RUBY_VERSION.to_f >= 2.0, sock.close_on_exec?)
55 assert_instance_of Kgio::Socket, sock
56 ready = IO.select(nil, [ sock ])
57 assert_equal sock, ready[1][0]
58 assert_equal nil, sock.kgio_write("HELLO")
62 sock = Kgio::Socket.start(@addr)
63 assert_instance_of Kgio::Socket, sock
64 ready = IO.select(nil, [ sock ])
65 assert_equal sock, ready[1][0]
66 assert_equal nil, sock.kgio_write("HELLO")
70 sock = SubSocket.start(@addr)
72 ready = IO.select(nil, [ sock ])
73 assert_equal sock, ready[1][0]
74 assert_equal nil, sock.kgio_write("HELLO")
77 def test_wait_writable_set
78 sock = SubSocket.new(@addr)
79 assert_kind_of Kgio::Socket, sock
80 assert_instance_of SubSocket, sock
81 assert_equal nil, sock.kgio_write("HELLO")