summaryrefslogtreecommitdiff
path: root/ext/socket/init.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-16 23:40:15 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-16 23:40:15 +0000
commitbee5b49aece1499309b7e7bb6e8e373a1d67e4ce (patch)
tree8624f2be2e0563b09f36016bc3a60be51849200a /ext/socket/init.c
parentbb6dfab2a8a798f68c7935596ec03855106d7fd4 (diff)
socket: avoid arg parsing in rsock_s_accept_nonblock
* ext/socket/init.c (rsock_s_accept_nonblock): avoid parsing args [ruby-core:71439] [Feature #11339] * ext/socket/rubysocket.h: adjust prototype * ext/socket/socket.c (sock_accept_nonblock): make private * ext/socket/tcpserver.c (tcp_accept_nonblock): ditto * ext/socket/unixserver.c (unix_accept_nonblock): ditto * ext/socket/lib/socket.rb (Socket#accept_nonblock): implement as wrapper, move RDoc (TCPServer#accept_nonblock): ditto (UNIXServer#accept_nonblock): ditto target 0: a (ruby 2.3.0dev (2015-11-12 trunk 52550) [x86_64-linux]) target 1: b (ruby 2.3.0dev (2015-11-12 avoid-kwarg-capi 52550) [x86_64-linux] ----------------------------------------------------------- accept_nonblock require 'tempfile' require 'socket' require 'io/wait' nr = 500000 Tempfile.create(%w(accept_nonblock .sock)) do |tmp| path = tmp.path File.unlink(path) s = UNIXServer.new(path) addr = Socket.sockaddr_un(path).freeze nr.times do s.accept_nonblock(exception: false) c = UNIXSocket.new(path) s.wait_readable s.accept_nonblock(exception: false).close c.close end end ----------------------------------------------------------- raw data: [["accept_nonblock", [[4.807877402752638, 4.930681671947241, 4.738454818725586, 4.69268161803484, 4.684675686061382], [4.253904823213816, 4.255124930292368, 4.295955188572407, 4.248479191213846, 4.213303029537201]]]] Elapsed time: 45.123040065 (sec) ----------------------------------------------------------- benchmark results: minimum results in each 5 measurements. Execution time (sec) name a b accept_nonblock 4.685 4.213 Speedup ratio: compare with the result of `a' (greater is better) name b accept_nonblock 1.112 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/init.c')
-rw-r--r--ext/socket/init.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/ext/socket/init.c b/ext/socket/init.c
index 350ba65..45070d5 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -29,7 +29,7 @@ VALUE rb_cSOCKSSocket;
#endif
int rsock_do_not_reverse_lookup = 1;
-static VALUE sym_exception, sym_wait_readable;
+static VALUE sym_wait_readable;
void
rsock_raise_socket_error(const char *reason, int error)
@@ -544,13 +544,10 @@ cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len,
}
VALUE
-rsock_s_accept_nonblock(int argc, VALUE *argv, VALUE klass, rb_io_t *fptr,
+rsock_s_accept_nonblock(VALUE klass, VALUE ex, rb_io_t *fptr,
struct sockaddr *sockaddr, socklen_t *len)
{
int fd2;
- VALUE opts = Qnil;
-
- rb_scan_args(argc, argv, "0:", &opts);
rb_io_set_nonblock(fptr);
fd2 = cloexec_accept(fptr->fd, (struct sockaddr*)sockaddr, len, 1);
@@ -564,7 +561,7 @@ rsock_s_accept_nonblock(int argc, VALUE *argv, VALUE klass, rb_io_t *fptr,
#if defined EPROTO
case EPROTO:
#endif
- if (rsock_opt_false_p(opts, sym_exception))
+ if (ex == Qfalse)
return sym_wait_readable;
rb_readwrite_sys_fail(RB_IO_WAIT_READABLE, "accept(2) would block");
}
@@ -673,6 +670,5 @@ rsock_init_socket_init(void)
rsock_init_socket_constants();
#undef rb_intern
- sym_exception = ID2SYM(rb_intern("exception"));
sym_wait_readable = ID2SYM(rb_intern("wait_readable"));
}