diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-02 01:58:14 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-02 01:58:14 +0000 |
commit | 5da34572a5b2b9f57699b997f1892774bd5294b0 (patch) | |
tree | 2218eaaeadc6c44cc1934c32d1285339165c145c /ext/socket/rubysocket.h | |
parent | 8ef33651e81fbf51024d45375ec34414c63fb175 (diff) | |
download | ruby-5da34572a5b2b9f57699b997f1892774bd5294b0.tar.gz |
socket: memoize common socket families in fptr->mode
This provides a minor speedup by avoiding an extra syscall
require 'socket'
require 'benchmark'
nr = 100000
msg = 'hello world'
buf = ''
size = msg.bytesize
puts(Benchmark.measure do
UNIXSocket.pair(:SEQPACKET) do |a, b|
nr.times do
a.sendmsg_nonblock(msg, 0, exception: false)
b.recv(size, 0, buf)
end
end
end)
user system total real
before: 0.330000 0.340000 0.670000 ( 0.678235)
after: 0.290000 0.240000 0.530000 ( 0.534527)
* ext/socket/rubysocket.h: flags for common socket families
(rsock_getfamily): update signature
* include/ruby/io.h: comment socket FMODE flags
* ext/socket/init.c (rsock_getfamily): memoize family
* ext/socket/basicsocket.c: adjust rsock_getfamily calls
* ext/socket/ancdata.c: ditto
[ruby-core:69713] [Feature #11298]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/rubysocket.h')
-rw-r--r-- | ext/socket/rubysocket.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h index d03b1c5e0b..79dd78324f 100644 --- a/ext/socket/rubysocket.h +++ b/ext/socket/rubysocket.h @@ -232,6 +232,12 @@ extern int rsock_do_not_reverse_lookup; extern int rsock_cmsg_cloexec_state; #define FMODE_NOREVLOOKUP 0x100 +/* common socket families only */ +#define FMODE_UNIX 0x00200000 +#define FMODE_INET 0x00400000 +#define FMODE_INET6 0x00800000 +#define FMODE_SOCK (FMODE_UNIX|FMODE_INET|FMODE_INET6) + extern VALUE rb_cBasicSocket; extern VALUE rb_cIPSocket; extern VALUE rb_cTCPSocket; @@ -279,7 +285,7 @@ int rsock_optname_arg(int family, int level, VALUE optname); int rsock_cmsg_type_arg(int family, int level, VALUE type); int rsock_shutdown_how_arg(VALUE how); -int rsock_getfamily(int sockfd); +int rsock_getfamily(rb_io_t *fptr); struct rb_addrinfo { struct addrinfo *ai; |