kgio 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/GIT-VERSION-GEN +1 -1
- data/ext/kgio/kgio_ext.c +31 -2
- data/test/test_accept_class.rb +52 -0
- metadata +6 -4
data/GIT-VERSION-GEN
CHANGED
data/ext/kgio/kgio_ext.c
CHANGED
@@ -32,6 +32,8 @@ static int accept4_flags = A4_SOCK_CLOEXEC;
|
|
32
32
|
static int accept4_flags = A4_SOCK_CLOEXEC | A4_SOCK_NONBLOCK;
|
33
33
|
#endif /* ! linux */
|
34
34
|
|
35
|
+
static VALUE cClientSocket;
|
36
|
+
static VALUE mSocketMethods;
|
35
37
|
static VALUE cSocket;
|
36
38
|
static VALUE localhost;
|
37
39
|
static VALUE mKgio_WaitReadable, mKgio_WaitWritable;
|
@@ -533,7 +535,7 @@ retry:
|
|
533
535
|
rb_sys_fail("accept");
|
534
536
|
}
|
535
537
|
}
|
536
|
-
return sock_for_fd(
|
538
|
+
return sock_for_fd(cClientSocket, client);
|
537
539
|
}
|
538
540
|
|
539
541
|
static void in_addr_set(VALUE io, struct sockaddr_in *addr)
|
@@ -950,10 +952,34 @@ static VALUE kgio_start(VALUE klass, VALUE addr)
|
|
950
952
|
return stream_connect(klass, addr, 0);
|
951
953
|
}
|
952
954
|
|
955
|
+
static VALUE set_accepted(VALUE klass, VALUE aclass)
|
956
|
+
{
|
957
|
+
VALUE tmp;
|
958
|
+
|
959
|
+
if (NIL_P(aclass))
|
960
|
+
aclass = cSocket;
|
961
|
+
|
962
|
+
tmp = rb_funcall(aclass, rb_intern("included_modules"), 0, 0);
|
963
|
+
tmp = rb_funcall(tmp, rb_intern("include?"), 1, mSocketMethods);
|
964
|
+
|
965
|
+
if (tmp != Qtrue)
|
966
|
+
rb_raise(rb_eTypeError,
|
967
|
+
"class must include Kgio::SocketMethods");
|
968
|
+
|
969
|
+
cClientSocket = aclass;
|
970
|
+
|
971
|
+
return aclass;
|
972
|
+
}
|
973
|
+
|
974
|
+
static VALUE get_accepted(VALUE klass)
|
975
|
+
{
|
976
|
+
return cClientSocket;
|
977
|
+
}
|
978
|
+
|
953
979
|
void Init_kgio_ext(void)
|
954
980
|
{
|
955
981
|
VALUE mKgio = rb_define_module("Kgio");
|
956
|
-
VALUE mPipeMethods
|
982
|
+
VALUE mPipeMethods;
|
957
983
|
VALUE cUNIXServer, cTCPServer, cUNIXSocket, cTCPSocket;
|
958
984
|
|
959
985
|
rb_require("socket");
|
@@ -967,6 +993,7 @@ void Init_kgio_ext(void)
|
|
967
993
|
*/
|
968
994
|
cSocket = rb_const_get(rb_cObject, rb_intern("Socket"));
|
969
995
|
cSocket = rb_define_class_under(mKgio, "Socket", cSocket);
|
996
|
+
cClientSocket = cSocket;
|
970
997
|
|
971
998
|
localhost = rb_str_new2("127.0.0.1");
|
972
999
|
|
@@ -1001,6 +1028,8 @@ void Init_kgio_ext(void)
|
|
1001
1028
|
rb_define_singleton_method(mKgio, "accept_cloexec=", set_cloexec, 1);
|
1002
1029
|
rb_define_singleton_method(mKgio, "accept_nonblock?", get_nonblock, 0);
|
1003
1030
|
rb_define_singleton_method(mKgio, "accept_nonblock=", set_nonblock, 1);
|
1031
|
+
rb_define_singleton_method(mKgio, "accept_class=", set_accepted, 1);
|
1032
|
+
rb_define_singleton_method(mKgio, "accept_class", get_accepted, 0);
|
1004
1033
|
|
1005
1034
|
/*
|
1006
1035
|
* Document-module: Kgio::PipeMethods
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'io/nonblock'
|
3
|
+
$-w = true
|
4
|
+
require 'kgio'
|
5
|
+
|
6
|
+
class TestAcceptClass < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
assert_equal Kgio::Socket, Kgio.accept_class
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
assert_nothing_raised { Kgio.accept_class = nil }
|
13
|
+
assert_equal Kgio::Socket, Kgio.accept_class
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_tcp_socket
|
17
|
+
assert_nothing_raised { Kgio.accept_class = Kgio::TCPSocket }
|
18
|
+
assert_equal Kgio::TCPSocket, Kgio.accept_class
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_invalid
|
22
|
+
assert_raises(TypeError) { Kgio.accept_class = TCPSocket }
|
23
|
+
assert_equal Kgio::Socket, Kgio.accept_class
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_accepted_class
|
27
|
+
@host = ENV["TEST_HOST"] || '127.0.0.1'
|
28
|
+
@srv = Kgio::TCPServer.new(@host, 0)
|
29
|
+
@port = @srv.addr[1]
|
30
|
+
|
31
|
+
assert_nothing_raised { Kgio.accept_class = Kgio::TCPSocket }
|
32
|
+
client = TCPSocket.new(@host, @port)
|
33
|
+
assert_instance_of Kgio::TCPSocket, @srv.kgio_accept
|
34
|
+
client = TCPSocket.new(@host, @port)
|
35
|
+
IO.select([@srv])
|
36
|
+
assert_instance_of Kgio::TCPSocket, @srv.kgio_tryaccept
|
37
|
+
|
38
|
+
assert_nothing_raised { Kgio.accept_class = nil }
|
39
|
+
client = TCPSocket.new(@host, @port)
|
40
|
+
assert_instance_of Kgio::Socket, @srv.kgio_accept
|
41
|
+
client = TCPSocket.new(@host, @port)
|
42
|
+
IO.select([@srv])
|
43
|
+
assert_instance_of Kgio::Socket, @srv.kgio_tryaccept
|
44
|
+
|
45
|
+
assert_nothing_raised { Kgio.accept_class = Kgio::UNIXSocket }
|
46
|
+
client = TCPSocket.new(@host, @port)
|
47
|
+
assert_instance_of Kgio::UNIXSocket, @srv.kgio_accept
|
48
|
+
client = TCPSocket.new(@host, @port)
|
49
|
+
IO.select([@srv])
|
50
|
+
assert_instance_of Kgio::UNIXSocket, @srv.kgio_tryaccept
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kgio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- kgio hackers
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-29 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- setup.rb
|
68
68
|
- test/lib_read_write.rb
|
69
69
|
- test/lib_server_accept.rb
|
70
|
+
- test/test_accept_class.rb
|
70
71
|
- test/test_connect_fd_leak.rb
|
71
72
|
- test/test_pipe_popen.rb
|
72
73
|
- test/test_pipe_read_write.rb
|
@@ -128,3 +129,4 @@ test_files:
|
|
128
129
|
- test/test_unix_client_read_server_write.rb
|
129
130
|
- test/test_tcp_client_read_server_write.rb
|
130
131
|
- test/test_pipe_popen.rb
|
132
|
+
- test/test_accept_class.rb
|