* ext/io/nonblock/nonblock.c (io_nonblock_set): return whether
nonblock flag was changed.
* ext/io/nonblock/nonblock.c (rb_io_nonblock_block): nothing to
restore but just yield unless nonblock flag is changed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50531 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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
* 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
* gc.c (rb_data_object_wrap, rb_data_typed_object_wrap): rename
alloc as wrap. these functions do not allocate data pointers
but just wrap the given pointers.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
the patch is from davydovanton <antondavydov.o at gmail.com>.
[fix GH-892]
* lib/rubygems/indexer.rb: ditto.
* test/rubygems/test_gem_indexer.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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
* ext/io/console/win32_vk.inc: renamed not to be included in HDRS
by mkmf.rb and regenerated unexpectedly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50437 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/io/console/depend: check if VK table is modified by the
checksum.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50434 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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
* ext/io/console/extconf.rb: vk_header is used only on Windows,
nonsense to update on other platforms.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/io/console/console.c (console_goto): new method IO#goto on
Windows. [EXPERIMENTAL]
* ext/io/console/console.c (console_cursor_pos): new method
IO#cursor on Windows. [EXPERIMENTAL]
* ext/io/console/console.c (console_cursor_set): new method
IO#cursor= on Windows. [EXPERIMENTAL]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
to use statvfs().
* ext/-test-/file/extconf.rb: check the existence of
sys/statvfs.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/io/console/console.c (LAST_ERROR): remove old ifdef, should
use rb_w32_map_errno always.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* 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
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
* 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
* ext/{etc,openssl,tk}: Adding parens and comparisons around
assignments to get rid of Wparentheses warnings. [Fix GH-875]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50346 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/json/parser/parser.rl (enc_raise): no needs if rb_enc_raise
is available.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/json/parser/parser.rl (convert_encoding): use rb_encoding
functions to compare and convert encodings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/json/parser/parser.rl (cParser_initialize): use StringValue
instead of direct rb_convert_type and remove duplicate
conversion.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50339 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/tk/tkutil/tkutil.c (Init_tkutil): TkUtil::CallbackSubst and
TkUtil::CallbackSubst::Info need the default allocator.
[ruby-list:50115]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/-test-/string/nofree.c: new method for test of r50334.
[ruby-core:68436] [Bug #10942]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/win32ole/win32ole.c: use rb_sym2str when the result strings
will not be modified.
* ext/win32ole/win32ole_event.c: ditto.
* ext/win32ole/win32ole_record.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/tk/tkutil/tkutil.c (rb_sym2str): use rb_sym2str always but
not rb_sym_to_s, and fallback to rb_id2str and SYM2ID.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* 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
* ext/-test-/printf/printf.c (uint_to_str): renamed to get rid of
conflict on cygwin. [ruby-core:68877] [Bug #11065]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
following RFC 6125. with the patch provided by Tony Arcieri and
Hiroshi Nakamura [ruby-core:61545] [Bug #9644]
* test/openssl/test_ssl.rb: add tests for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/io/wait/wait.c (io_wait_readable): simply returns that IO is
readable without blocking, but no longer returns EOF.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/io/wait/wait.c (io_ready_p, io_wait_readable): try polling
first and check FIONREAD optionally to see if EOF.
[ruby-core:36805] [Feature #4849]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/io/wait/wait.c (io_wait_writable): fix rdoc. no EOF to
write. retursn nil when timeout, not self.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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