summaryrefslogtreecommitdiff
path: root/ext/socket
AgeCommit message (Collapse)Author
2015-11-04ext: use RARRAY_CONST_PTRnobu
* ext/bigdecimal/bigdecimal.c: use RARRAY_CONST_PTR just fore reference instead of RARRAY_PTR, to keep the array WB-protected. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-24* configure.in: fixed build failure of Haiku.hsbt
[fix GH-984] Patch by @kallisti5 * ext/socket/getaddrinfo.c: ditto. * ext/socket/getnameinfo.c: ditto. * ext/socket/rubysocket.h: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-19suppress a warningnobu
* ext/socket/raddrinfo.c (rsock_fd_family): suppress a sign-compare warning. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-19init.c: glibc bugnobu
* ext/socket/init.c (rsock_raise_socket_error): get rid of a glibc bug. [ruby-core:71100] [Bug #11600] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18* ChangeLog: Good-bye OS/2.kosaki
* common.mk: ditto. * configure.in: ditto. * dln_find.c: ditto. * ext/Setup.emx: ditto. * ext/extmk.rb: ditto. * ext/socket/extconf.rb: ditto. * ext/zlib/extconf.rb: ditto. * file.c: ditto. * include/ruby/defines.h: ditto. * io.c: ditto. * lib/mkmf.rb: ditto. * missing/os2.c: ditto. * process.c: ditto. * ruby.c: ditto. * NEWS: announce OS/2 is no longer supported. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-13* ext/socket/raddrinfo.c (rsock_fd_family): Check sa_len.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-13rsock_addrinfo: specify address familynobu
* ext/socket/rsock_addrinfo (rsock_addrinfo): specify address family. [Fix GH-1052] * ext/socket/udpsocket.c (udp_connect, udp_bind, udp_send): address family by the receiver. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-12udpsocket.c: free addrinfonobu
* ext/socket/udpsocket.c (udp_send): ensure addrinfo gets freed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-12udpsocket.c: check once firstnobu
* ext/socket/udpsocket.c (udp_connect, udp_bind): check if the socket is opened once before retreiving address infos. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-10udpsocket.c: refix r52097nobu
* ext/socket/udpsocket.c (udp_connect, udp_bind): get open files inside ensure functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52101 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-09udpsocket.c: memory leaksnobu
* ext/socket/udpsocket.c (udp_connect, udp_bind, udp_send): fix memory leaks at closed socket. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-15use rb_sym2strnobu
* ext/openssl/ossl_ssl.c (ossl_sslctx_set_ssl_version): use rb_sym2str to get rid of inadvertent ID creations. * ext/socket/ancdata.c (ancillary_inspect): ditto. * ext/socket/option.c (sockopt_inspect): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-05socket.c: suppress warningsnobu
* ext/socket/socket.c (socket_s_ip_address_list): suppress warnings to assign pointers to literal strings. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51491 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-21ruby/win32.h: include windows.hnobu
* include/ruby/win32.h: include windows.h before winsock2.h, because mswsock.h included by the former uses SOCKET defined after it in the latter. fix a build failure with VC6. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-12* ext/socket/basicsocket.c: [DOC] typo (Errno::AGAIN -> Errno::EAGAIN)sorah
* ext/socket/socket.c: ditto * ext/socket/tcpserver.c: ditto * ext/socket/udpsocket.c: ditto * ext/socket/unixserver.c: ditto * io.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-08basicsocket.c: swap examples [ci skip]nobu
* ext/socket/basicsocket.c (bsock_do_not_reverse_lookup), (bsock_do_not_reverse_lookup_set): [DOC] swap examples. the code setting the flag is for the setter. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-08pass saved errnonobu
* ext/socket/socket.c (socket_s_ip_address_list): pass saved errno to rb_syserr_fail. * ext/readline/readline.c (readline_getc, readline_s_set_input), (readline_s_set_output): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-02socket: memoize common socket families in fptr->modenormal
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
2015-06-23ext/socket/ancdata.c (bsock_recvmsg_internal): reduce stack usenormal
Using 8K stack is probably too much. As reference, ALLOCV falls back to heap allocation at a mere 1K. Since bsock_recvmsg_internal is a function which will always allocate and can trigger GC, it is in our best interest to minimize stack usage to avoid scanning 8K of stack on GC. [ruby-core:69595] [Feature #11263] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-18* include/ruby/ruby.h: $SAFE=2 is now obsolete.hsbt
* dir.c, ext/fiddle/handle.c, ext/socket/basicsocket.c, file.c gc.c, io.c, process.c, safe.c, signal.c, win32/file.c: removed code for $SAFE=2 * test/erb/test_erb.rb, test/fiddle/test_handle.rb test/ruby/test_env.rb: removed tests for $SAFE=2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-17* include/ruby/ruby.h: $SAFE=3 is now obsolete.hsbt
* ext/socket/init.c, ext/socket/socket.c, ext/socket/tcpsocket.c ext/socket/udpsocket.c, gc.c, object.c, re.c, safe.c: removed code for $SAFE=3 * bootstraptest/test_method.rb, test/erb/test_erb.rb, test/ruby/test_dir.rb test/ruby/test_file.rb, test/ruby/test_method.rb, test/ruby/test_regexp.rb test/ruby/test_thread.rb: remove tests for $SAFE=3 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-16fix unbalanced square bracketskazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-15socket: allow explicit buffer for recv and recv_nonblocknormal
This reduces GC overhead and makes the API more consistent with IO#read and IO#read_nonblock. * ext/socket/basicsocket.c (bsock_recv): document outbuf * ext/socket/unixsocket.c (unix_recvfrom): ditto * ext/socket/init.c (rsock_strbuf, recvfrom_locktmp): new functions (rsock_s_recvfrom): support destination buffer as 3rd arg (rsock_s_recvfrom_nonblock): ditto * string.c (rb_str_locktmp_ensure): export for internal ext * test/socket/test_nonblock.rb: test recv_nonblock * test/socket/test_unix.rb: test recv [ruby-core:69543] [Feature #11242] Benchmark results: user system total real alloc 0.130000 0.280000 0.410000 ( 0.420656) extbuf 0.100000 0.220000 0.320000 ( 0.318708) -------------------8<-------------------- require 'socket' require 'benchmark' nr = 100000 msg = ' ' * 16384 size = msg.bytesize buf = ' ' * size UNIXSocket.pair(:DGRAM) do |a, b| Benchmark.bmbm do |x| x.report('alloc') do nr.times do b.send(msg, 0) a.recv(size, 0) end end x.report('extbuf') do nr.times do b.send(msg, 0) a.recv(size, 0, buf) end end end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-15socket: allow exception-free nonblocking sendmsg/recvmsgnormal
As documented before, exceptions are expensive and IO::Wait*able are too common in socket applications to be the exceptional case. Datagram sockets deserve the same API which stream sockets are allowed with read_nonblock and write_nonblock. Note: this does not offer a performance advantage under optimal conditions when both ends are equally matched in speed, but it it does make debug output cleaner by avoiding exceptions whenever the receiver slows down. * ext/socket/ancdata.c (bsock_sendmsg_internal, bsock_recvmsg_internal): support "exception: false" kwarg * ext/socket/init.c (rsock_s_recvfrom_nonblock): ditto * ext/socket/init.c (rsock_s_recvfrom_nonblock): use rsock_opt_false_p * ext/socket/socket.c (sock_connect_nonblock): ditto * ext/socket/rubysocket.h (rsock_opt_false_p): new function * ext/socket/basicsocket.c (bsock_recv_nonblock): update rdoc * ext/socket/udpsocket.c (udp_recvfrom_nonblock): ditto * test/socket/test_nonblock.rb: new tests [ruby-core:69542] [Feature #11229] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-14raddrinfo.c: suppress a warningnobu
* ext/socket/raddrinfo.c (parse_numeric_port): used only when inet_pton() is available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-14raddrinfo.c: suppress a warningnobu
* ext/socket/raddrinfo.c (parse_numeric_port): explict cast to suppress a warning for precision losing conversion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-14* ext/socket/raddrinfo.c (parse_numeric_port): Detectakr
port overflow. (numeric_getaddrinfo): Use parse_numeric_port. numeric_getaddrinfo fails if port is too big now. This makes rb_getaddrinfo invokes the real getaddrinfo() on such condition. This change is related to [ruby-core:69355] [Bug #11179]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-05* ext/socket/ancdata.c (bsock_sendmsg_internal): drop redundant assignmentnormal
We call memset to zero `mh' a few lines above anyways, making explicitly zero-ing each field unnecessary. Compilers optimize this code away anyways, but it still costs me 4 lines of my small terminal and even smaller attention span. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-05* ext/socket/ancdata.c (bsock_sendmsg_internal): all arguments arengoto
parsed even on systems without HAVE_STRUCT_MSGHDR_MSG_CONTROL to prevent SEGV caused by passing Qnil to RARRAY_LENINT and to preserve behavior before r50776. [Bug #11224] [ruby-core:69468] [Bug #11225] [ruby-core:69469] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-05ext/socket/ancdata.c (bsock_sendmsg_internal): portability fixnormal
* ext/socket/ancdata.c (bsock_sendmsg_internal): avoid msg_control ptr if msg_controllen is zero to fix portability problems. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-05ext/socket/ancdata.c (bsock_sendmsg_internal): fix build error from r50776normal
Systems without HAVE_STRUCT_MSGHDR_MSG_CONTROL still need controls to be nil for the check after argument parsing. Note: not actually tested on a real system without msg_control git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-04ext/socket/ancdata.c (bsock_sendmsg_internal): use rb_scan_argsnormal
This should make the code more maintainable and make it easier to add keyword argument support for "exception: false" in the future. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-30ext/socket/ancdata.c: use RB_GC_GUARD instead of volatilenormal
See doc/extension.rdoc for explanation. [ruby-core:69419] [Feature #11198] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-29socket: avoid redundant fcntl on Linuxnormal
* ext/socket/ancdata.c (bsock_sendmsg_internal, bsock_recvmsg_internal): avoid redundant fcntl on Linux [ruby-core:69154] [Feature #11145] * ext/socket/init.c (rsock_s_recvfrom_nonblock): ditto * ext/socket/rubysocket.h (MSG_DONTWAIT_RELIABLE): new macro MSG_DONTWAIT is enough to force non-blocking I/O under Linux, so avoid changing the state of a socket. This will allow certain threads to do a non-destructive non-blocking "peek" while others block (without relying on an extra ppoll syscall). We shall be conservative about enabling this feature since some OSes may have incomplete support for MSG_DONTWAIT. I shall defer to a FreeBSD expert to enable that for FreeBSD. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-17ext/socket/init.c: use SOCK_NONBLOCK if availablenormal
This saves a system call by allowing us to use SOCK_NONBLOCK in Linux when accept4 is available. Note: I do not agree accept_nonblock should always make accepted sockets non-blocking, and will propose a future API to allow controlling whether accepted sockets are non-blocking or not regardless of how they were created. * ext/socket/init.c (cloexec_accept): support nonblock flag and use SOCK_NONBLOCK if possible * ext/socket/init.c (rsock_s_accept_nonblock): update cloexec_accept call * ext/socket/init.c (accept_blocking): ditto for blocking * test/socket/test_nonblock.rb: check nonblock? on accepted socket [Feature #11138] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-16ifaddr.c: wrapper object before allocnobu
* ext/socket/ifaddr.c (rsock_getifaddrs): make wrapper object before result structs allocation and manage refcount for each elements to get rid of potential memory leak. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-08ext/socket/ancdata.c (bsock_recvmsg_internal): GC guardnormal
The control buffer may be used throughout the function, so prevent the string from being lost to GC. * ext/socket/ancdata.c (bsock_recvmsg_internal): GC guard [Bug #11123] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-06stdlib: use IO#wait_*able instead of IO.select when possiblenormal
In case a process encounters high-numbered FDs, this allows consistent performance on systems with ppoll support. [ruby-core:35572] * ext/socket/lib/socket.rb (connect_nonblock): use IO#wait_writable * lib/drb/drb.rb (DRB::DRbTCPSocket#alive?): use IO#wait_readable * lib/webrick/httpserver.rb (run): ditto * lib/resolv.rb (request): ditto for single socket case [ruby-core:68943] [Feature #11081] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50432 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-30ipsocket.c: fix merge missnobu
* ext/socket/ipsocket.c (init_inetsock_internal): fix local variable name by merge miss. [ruby-core:68531] [Bug #10975] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-30ipsocket.c: sys_errornobu
* ext/socket/ipsocket.c (init_inetsock_internal): preserve errno before other library calls and use rb_syserr_fail. [ruby-core:68531] [Bug #10975] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-20socket: avoid common exceptions when calling connect_nonblocknormal
Errno::EISCONN and IO::WaitReadable exceptions are common, expensive, and noisy under normal use. Avoid raising on them since they are not exceptional. * ext/socket/lib/socket.rb (connect_internal): avoid common exceptions from connect_nonblock. [ruby-core:68909] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-20connect_nonblock(..., exception: false) does not raise EISCONNnormal
* ext/socket/socket.c (sock_connect_nonblock): do not raise EISCONN [ruby-core:68926] [Feature #11072] * test/socket/test_nonblock.rb: check non-EISCONN on 2nd connect This is to reduce exceptions for code which issues a (IMHO, unnecessary) second connect() syscall. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-15* doc/contributors.rdoc: fix a typo. Patch by @davydovantonhsbt
[fix GH-872][ci skip] * doc/syntax/methods.rdoc: ditto. * ext/digest/sha2/sha2.c: ditto. * ext/socket/ipsocket.c: ditto. * ext/tk/*: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-14use frozen string of symbolsnobu
* range.c (range_step, range_each): String#upto should never modifies the receiver, use frozen strings to enumerate symbols. * re.c (reg_operand): matching target is not modified. * ext/socket/constants.c (constant_arg): str_to_int never modifies argument strings. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-12connect_nonblock supports "exception: false"normal
This is for consistency with accept_nonblock arguments and gives a minor speedup from avoiding exceptions. [ruby-core:68838] [Feature #11024] * ext/openssl/ossl_ssl.c (ossl_ssl_connect_nonblock): support `exception: false' * (get_no_exception): move function location * ext/socket/socket.c (sock_connect_nonblock): support `exception: false' * test/openssl/test_pair.rb (test_connect_accept_nonblock_no_exception): test `exception: false' on connect, rename from `test_accept_nonblock_no_exception' * test/socket/test_nonblock.rb (test_connect_nonblock_no_exception): new test Benchmark results: default 0.050000 0.100000 0.150000 ( 0.151307) exception: false 0.030000 0.080000 0.110000 ( 0.108840) ----------------------------8<----------------------- require 'socket' require 'benchmark' require 'io/wait' require 'tmpdir' host = '127.0.0.1' serv = TCPServer.new(host, 0) # UNIX sockets may not hit EINPROGRESS nr = 5000 # few iterations to avoid running out of ports addr = serv.getsockname pid = fork do begin serv.accept.close rescue => e warn "#$$: #{e.message} (#{e.class})" end while true end at_exit { Process.kill(:TERM, pid) } serv.close Benchmark.bmbm do |x| x.report("default") do nr.times do s = Socket.new(:INET, :STREAM) s.setsockopt(:SOL_SOCKET, :SO_REUSEADDR, 1) begin s.connect_nonblock(addr) rescue IO::WaitWritable s.wait_writable end s.close end end x.report("exception: false") do nr.times do s = Socket.new(:INET, :STREAM) s.setsockopt(:SOL_SOCKET, :SO_REUSEADDR, 1) case s.connect_nonblock(addr, exception: false) when :wait_writable s.wait_writable end s.close end end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50254 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-08raddrinfo.c: fix memory leaknobu
* ext/socket/raddrinfo.c (addrinfo_mload): fix memory leak of addrinfo. [ruby-dev:48923] [Bug #11051] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-25* ext/socket/extconf.rb: Solaris 11 has struct tcp_info.tcpi_ca_state,naruse
but it is a dummy. * ext/socket/option.c: Solaris 11 doesn't have u_intN_t. * ext/socket/option.c: Solaris 11 needs inspect_tcpi_msec. * ext/socket/raddrinfo.c: Solaris 11 has AF_PACKET but doesn't have related macros. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-12accept_nonblock: favor rb_hash_lookup2 to avoid Hash#defaultnormal
* ext/socket/init.c (rsock_s_accept_nonblock): use rb_hash_lookup2 * ext/openssl/ossl_ssl.c (get_no_exception): new function (ossl_ssl_accept_nonblock): use get_no_exception (ossl_ssl_read_internal): ditto (ossl_ssl_write_nonblock): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-12accept_nonblock supports "exception: false"normal
This is analogous to functionality found in IO#read_nonblock and IO#wait_nonblock. Raising exceptions for common failures on non-blocking servers is expensive and makes $DEBUG too noisy. Benchmark results: user system total real default 2.790000 0.870000 3.660000 ( 3.671597) exception: false 1.120000 0.800000 1.920000 ( 1.922032) exception: false (cached arg) 0.820000 0.770000 1.590000 ( 1.589267) --------------------- benchmark script ------------------------ require 'socket' require 'benchmark' require 'tmpdir' nr = 1000000 Dir.mktmpdir('nb_bench') do |path| sock_path = "#{path}/test.sock" s = UNIXServer.new(sock_path) Benchmark.bmbm do |x| x.report("default") do nr.times do begin s.accept_nonblock rescue IO::WaitReadable end end end x.report("exception: false") do nr.times do begin s.accept_nonblock(exception: false) rescue IO::WaitReadable abort "should not raise" end end end x.report("exception: false (cached arg)") do arg = { exception: false } nr.times do begin s.accept_nonblock(arg) rescue IO::WaitReadable abort "should not raise" end end end end end * ext/socket/init.c (rsock_s_accept_nonblock): support exception: false [ruby-core:66385] [Feature #10532] * ext/socket/init.c (rsock_init_socket_init): define new symbols * ext/socket/rubysocket.h: adjust prototype * ext/socket/socket.c (sock_accept_nonblock): support exception: false * ext/openssl/ossl_ssl.c (ossl_ssl_accept_nonblock): ditto * ext/socket/socket.c (Init_socket): adjust accept_nonblock definition * ext/openssl/ossl_ssl.c (Init_ossl_ssl): ditto * ext/socket/tcpserver.c (rsock_init_tcpserver): ditto * ext/socket/unixserver.c (rsock_init_unixserver): ditto * ext/socket/tcpserver.c (tcp_accept_nonblock): adjust rsock_s_accept_nonblock call * ext/socket/unixserver.c (unix_accept_nonblock): ditto * ext/openssl/ossl_ssl.c (ossl_start_ssl): support no_exception * ext/openssl/ossl_ssl.c (ossl_ssl_connect): adjust ossl_start_ssl call * ext/openssl/ossl_ssl.c (ossl_ssl_connect_nonblock): ditto * ext/openssl/ossl_ssl.c (ossl_ssl_accept): ditto * test/socket/test_nonblock.rb (test_accept_nonblock): test for "exception :false" * test/socket/test_tcp.rb (test_accept_nonblock): new test * test/socket/test_unix.rb (test_accept_nonblock): ditto * test/openssl/test_pair.rb (test_accept_nonblock_no_exception): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-16use rb_funcallvnobu
* use rb_funcallv() for no arguments call instead of variadic rb_funcall(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49612 b2dd03c8-39d4-4d8f-98ff-823fe69b080e