Avoid unnecessary object allocation (addrinfo) in `_accept`; ref #3999

parent f7cf5812
...@@ -302,7 +302,7 @@ class TCPServer < TCPSocket ...@@ -302,7 +302,7 @@ class TCPServer < TCPSocket
end end
def sysaccept def sysaccept
Socket._accept(self.fileno)[0] Socket._accept(self.fileno)
end end
end end
...@@ -463,7 +463,7 @@ class Socket < BasicSocket ...@@ -463,7 +463,7 @@ class Socket < BasicSocket
end end
def sysaccept def sysaccept
Socket._accept(self.fileno) Socket._accept2(self.fileno)
end end
end end
...@@ -566,7 +566,7 @@ class UNIXServer < UNIXSocket ...@@ -566,7 +566,7 @@ class UNIXServer < UNIXSocket
end end
def sysaccept def sysaccept
Socket._accept(self.fileno)[0] Socket._accept(self.fileno)
end end
end end
......
...@@ -588,6 +588,20 @@ mrb_socket_gethostname(mrb_state *mrb, mrb_value cls) ...@@ -588,6 +588,20 @@ mrb_socket_gethostname(mrb_state *mrb, mrb_value cls)
static mrb_value static mrb_value
mrb_socket_accept(mrb_state *mrb, mrb_value klass) mrb_socket_accept(mrb_state *mrb, mrb_value klass)
{
int s1;
mrb_int s0;
mrb_get_args(mrb, "i", &s0);
s1 = (int)accept(s0, NULL, NULL);
if (s1 == -1) {
mrb_sys_fail(mrb, "accept");
}
return mrb_fixnum_value(s1);
}
static mrb_value
mrb_socket_accept2(mrb_state *mrb, mrb_value klass)
{ {
mrb_value ary, sastr; mrb_value ary, sastr;
int s1; int s1;
...@@ -872,6 +886,7 @@ mrb_mruby_socket_gem_init(mrb_state* mrb) ...@@ -872,6 +886,7 @@ mrb_mruby_socket_gem_init(mrb_state* mrb)
sock = mrb_define_class(mrb, "Socket", bsock); sock = mrb_define_class(mrb, "Socket", bsock);
mrb_define_class_method(mrb, sock, "_accept", mrb_socket_accept, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, sock, "_accept", mrb_socket_accept, MRB_ARGS_REQ(1));
mrb_define_class_method(mrb, sock, "_accept2", mrb_socket_accept2, MRB_ARGS_REQ(1));
mrb_define_class_method(mrb, sock, "_bind", mrb_socket_bind, MRB_ARGS_REQ(3)); mrb_define_class_method(mrb, sock, "_bind", mrb_socket_bind, MRB_ARGS_REQ(3));
mrb_define_class_method(mrb, sock, "_connect", mrb_socket_connect, MRB_ARGS_REQ(3)); mrb_define_class_method(mrb, sock, "_connect", mrb_socket_connect, MRB_ARGS_REQ(3));
mrb_define_class_method(mrb, sock, "_listen", mrb_socket_listen, MRB_ARGS_REQ(2)); mrb_define_class_method(mrb, sock, "_listen", mrb_socket_listen, MRB_ARGS_REQ(2));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment