Граф коммитов

78 Коммитов

Автор SHA1 Сообщение Дата
nobu f9adadc5e6 rb_readwrite_syserr_fail
* io.c (rb_readwrite_syserr_fail): works with the given errno than
  thread local errno.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53265 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-23 14:58:47 +00:00
nobu f4166e2dd7 prefer rb_syserr_fail
* file.c, io.c, util.c: prefer rb_syserr_fail with saved errno
  over setting errno then call rb_sys_fail, not to be clobbered
  potentially and to reduce thread local errno accesses.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53264 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-23 08:57:48 +00:00
normal 1abef5bd11 ext/socket/init.c (rsock_init_sock): reject reserved FDs
[ruby-core:72445] [Bug #11862]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-22 22:28:31 +00:00
naruse 4eac2e833c fix r53231: raise Errno::EBADF like other OSes
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-22 13:45:14 +00:00
normal 409e53dec1 avoid rb_bug on BasicSocket.for_fd(-1)
* ext/socket/init.c (rsock_init_sock): check FD after validating
* test/socket/test_basicsocket.rb (test_for_fd): new
  [ruby-core:72418] [Bug #11854]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53231 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-21 18:57:50 +00:00
normal d51743afc8 ext/socket/init.c (rsock_accept): handle ENOMEM
accept(2) documents ENOMEM as a possible error, handle it
consistent with all of our other FD-allocating wrappers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-23 22:57:29 +00:00
normal 61e5fe0674 use rb_gc_for_fd for more callers
* dir.c (dir_initialize): use rb_gc_for_fd for ENOMEM
* ext/socket/init.c (rsock_socket): ditto
* ext/socket/socket.c (rsock_socketpair): ditto
* internal.h (rb_gc_for_fd): prototype
* io.c (rb_gc_for_fd): remove static
  [ruby-core:71623] [Feature #11727]

Manpages for opendir(2), socket(2), and socketpair(3posix)
describe ENOMEM as a possible error for each of these;
handle it consistently with our existing wrappers for
open(2)/pipe(2) etc...

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-23 22:50:53 +00:00
nobu afe142997b init.c: is_socket
* ext/socket/init.c (is_socket): extract predicate to see if the
  given fd is a socket.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52605 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-17 02:15:55 +00:00
normal bee5b49aec 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
2015-11-16 23:40:15 +00:00
normal 528ff1b9f9 socket: avoid arg parsing in rsock_s_recvfrom_nonblock
* ext/socket/init.c (rsock_s_recvfrom_nonblock):
  avoid arg parsing with C API
  [ruby-core:71439] [Feature #11339]
* ext/socket/basicsocket.c (bsock_recv_nonblock):
  adjust for above change, make private
* ext/socket/socket.c (sock_recvfrom_nonblock): ditto
* ext/socket/udpsocket.c (udp_recvfrom_nonblock): ditto
* ext/socket/lib/socket.rb (BasicSocket#recv_nonblock):
  new wrapper for private method, move RDoc
  (Socket#recvfrom_nonblock): ditto
  (UDPSocket#recvfrom_nonblock): ditto

Note, not adding bm_recv_nonblock.rb to benchmark/ directory
since it is non-portable.  It is only in this commit message.

Benchmark results + code
target 0: a (ruby 2.3.0dev (2015-11-12 trunk 52540) [x86_64-linux])
target 1: b (ruby 2.3.0dev (2015-11-12 avoid-kwarg-capi 52540) [x86_64-linux]

-----------------------------------------------------------
recv_nonblock

require 'socket'
nr = 1000000
msg = 'hello world'
buf = ''
size = msg.bytesize
UNIXSocket.pair(:SEQPACKET) do |a, b|
  nr.times do
    a.sendmsg(msg)
    b.recv_nonblock(size, 0, buf, exception: false)
  end
end

-----------------------------------------------------------
raw data:

[["recv_nonblock",
  [[1.83511221408844,
    1.8703329525887966,
    1.8448856547474861,
    1.859263762831688,
    1.8331583738327026],
   [1.5637447573244572,
    1.4062932096421719,
    1.4247371144592762,
    1.4108827747404575,
    1.4802536629140377]]]]

Elapsed time: 16.530452496 (sec)
-----------------------------------------------------------
benchmark results:
minimum results in each 5 measurements.
Execution time (sec)
name          a       b
recv_nonblock   1.833   1.406

Speedup ratio: compare with the result of `a' (greater is better)
name          b
recv_nonblock   1.304

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-16 23:25:03 +00:00
nobu 7594a99322 init.c: glibc bug
* 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-19 01:33:49 +00:00
normal 6dda4f17a9 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
2015-07-02 01:58:14 +00:00
hsbt bbf440c90b * include/ruby/ruby.h: $SAFE=3 is now obsolete.
* 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-17 05:29:51 +00:00
normal a02a3f4649 socket: allow explicit buffer for recv and recv_nonblock
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-15 20:02:43 +00:00
normal b9a91334c5 socket: allow exception-free nonblocking sendmsg/recvmsg
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-15 19:38:49 +00:00
normal d8bbb5eda8 socket: avoid redundant fcntl on Linux
* 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-29 02:24:18 +00:00
normal 8ff35b816a ext/socket/init.c: use SOCK_NONBLOCK if available
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-17 05:56:07 +00:00
normal 9941f348e0 accept_nonblock: favor rb_hash_lookup2 to avoid Hash#default
* 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-12 22:04:24 +00:00
normal aaf2d070a8 accept_nonblock supports "exception: false"
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-03-12 03:03:04 +00:00
nobu 28b9f11d5a protoize no-arguments functions
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-30 05:25:32 +00:00
normal 4d10c2b91d ext/socket/*.c: trivial struct packing for 64-bit
* ext/socket/ancdata.c ({send,recv}msg_args_struct): 24 => 16 bytes
* ext/socket/init.c (connect_arg): ditto
* ext/socket/raddrinfo.c (getnameinfo_arg): 56 => 48 bytes

Other big stack reductions are less trivial.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-22 00:46:25 +00:00
normal 7914a8726e socket (rsock_connect): fix and refactor for blocking
* ext/socket/init.c (rsock_connect): refactor for blocking
  (wait_connectable): clear error before wait
  [Bug #9356]

We no longer use non-blocking sockets to emulate blocking behavior,
so eliminate error-prone and confusing platform-dependent code.
According to POSIX, connect() only needs to be called once in the
face of EINTR, so do not loop on it.

Before waiting on connect, drop any pending errors, since
rb_wait_for_single_fd may not clear the existing error
properly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-17 21:20:58 +00:00
shugo 139d06c34f * ext/socket/init.c (wait_connectable): break if the socket is
writable to avoid infinite loops on FreeBSD and other platforms
  which conforms to SUSv3.  This problem cannot be reproduced with
  loopback interfaces, so it's hard to write test code.
  rsock_connect() and wait_connectable() are overly complicated, so
  they should be refactored, but I commit this fix as a workaround
  for the release of Ruby 1.9.3 scheduled on Feb 24.
  [ruby-core:60940] [Bug #9547]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-21 14:59:44 +00:00
normal cb07275001 socket: split out SOCK_CLOEXEC versions of wrappers for readability
* ext/socket/init.c (rsock_socket0): split out SOCK_CLOEXEC version
	* ext/socket/socket.c (rsock_socketpair0): ditto
	  [ruby-core:60377]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-31 08:06:19 +00:00
nobu d0a84c2ce9 socket.c: suppress warnings
* ext/socket/init.c (rsock_socket0): suppress unused label
  warnings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-31 07:08:52 +00:00
akr 965b947fff * ext/socket: Avoid redundant fcntl/fstat syscalls for cloexec
sockets.
  Patch by Eric Wong.  [ruby-core:59429] [Feature #9330]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-28 14:37:34 +00:00
hsbt d1ab866d4a * ext/nkf/nkf-utf8/nkf.c: fix typo by @windwiny [fix GH-506]
* ext/openssl/ossl_ssl.c: ditto
* ext/psych/yaml/scanner.c: ditto
* ext/socket/init.c: ditto
* ext/socket/socket.c: ditto
* ext/tk/tcltklib.c: ditto
* ext/win32ole/win32ole.c: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-19 05:43:23 +00:00
akr 971ef82267 * ext/socket: Avoid unnecessary ppoll/select on Linux.
Patch by Eric Wong.  [ruby-core:57950] [Bug #9039]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-18 14:13:22 +00:00
ko1 83aba04862 * include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
  This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
  This function reveal interal (hidden) object by rb_obj_hide().
  Note that do not change class before and after hiding.
  Only permitted example is:
  klass = RBASIC_CLASS(obj);
  rb_obj_hide(obj);
  ....
  rb_obj_reveal(obj, klass);
  TODO: API design. rb_obj_reveal() should be replaced with others.
  TODO: modify constified variables using cast may be harmful for
  compiler's analysis and optimizaton.
  Any idea to prohibt inserting RBasic::klass directly?
  If rename RBasic::klass and force to use RBASIC_CLASS(obj),
  then all codes such as `RBASIC(obj)->klass' will be
  compilation error. Is it acceptable? (We have similar
  experience at Ruby 1.9,
  for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
  object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
  without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
  file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
  parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
  string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
  Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
  ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 10:49:11 +00:00
akr b323d7d54c * ext/socket: New method, Socket.getifaddrs, implemented.
[ruby-core:54777] [Feature #8368]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-11 08:32:26 +00:00
headius 0626d9b91c Fix #6154 by introducing new EAGAIN/EWOULDBLOCK/EINPROGRESS
subclasses that include WaitReadable or WaitWritable rather than
extending them into the exception object each time.

* error.c: Capture EGAIN, EWOULDBLOCK, EINPROGRESS exceptions and
  export them for use in WaitReadable/Writable exceptions.
* io.c: Create versions of EAGAIN, EWOULDBLOCK, EINPROGRESS that
  include WaitReadable and WaitWritable. Add rb_readwrite_sys_fail
  for nonblocking failures using those exceptions. Use that
  function in io_getpartial and io_write_nonblock instead of
  rb_mod_sys_fail
* ext/openssl/ossl_ssl.c: Add new SSLError subclasses that include
  WaitReadable and WaitWritable. Use those classes for
  write_would_block and read_would_block instead of rb_mod_sys_fail.
* ext/socket/ancdata.c: Use rb_readwrite_sys_fail instead of
  rb_mod_sys_fail in bsock_sendmsg_internal and
  bsock_recvmsg_internal.
* ext/socket/init.c: Use rb_readwrite_sys_fail instead of
  rb_mod_sys_fail in rsock_s_recvfrom_nonblock and
  rsock_s_connect_nonblock.
* ext/socket/socket.c: Use rb_readwrite_sys_fail instead of
  rb_mod_sys_fail in sock_connect_nonblock.
* include/ruby/ruby.h: Export rb_readwrite_sys_fail for use instead
  of rb_mod_sys_fail. Introduce new constants RB_IO_WAIT_READABLE and
  RB_IO_WAIT_WRITABLE for first arg to rb_readwrite_sys_fail.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-08 19:58:55 +00:00
akr d933fb2296 * ext/socket: Improve socket exception message to show socket address.
[ruby-core:45617] [Feature #6583] proposed Eric Hodel.

* ext/socket/rubysocket.h (rsock_sys_fail_host_port): Declared.
  (rsock_sys_fail_path): Ditto.
  (rsock_sys_fail_sockaddr): Ditto.

* ext/socket/udpsocket.c (udp_connect): Use rsock_sys_fail_host_port.
  (udp_bind): Ditto.
  (udp_send): Ditto.

* ext/socket/init.c (rsock_init_sock): Specify a string for rb_sys_fail
  argument.
  (make_fd_nonblock): Ditto.
  (rsock_s_accept): Ditto.

* ext/socket/ipsocket.c (init_inetsock_internal): Use
  rsock_sys_fail_host_port.

* ext/socket/socket.c (rsock_sys_fail_host_port): Defined.
  (rsock_sys_fail_path): Ditto.
  (rsock_sys_fail_sockaddr): Ditto.
  (setup_domain_and_type): Use rsock_sys_fail_sockaddr.
  (sock_connect_nonblock): Ditto.
  (sock_bind): Ditto.
  (sock_gethostname): Specify a string for rb_sys_fail argument.
  (socket_s_ip_address_list): Ditto.

* ext/socket/basicsocket.c (bsock_shutdown): Specify a string for
  rb_sys_fail argument.
  (bsock_setsockopt): Use rsock_sys_fail_path.
  (bsock_getsockopt): Ditto.
  (bsock_getpeereid): Refine the argument for rb_sys_fail.

* ext/socket/unixsocket.c (rsock_init_unixsock): Use
  rsock_sys_fail_path.
  (unix_path): Ditto.
  (unix_send_io): Ditto.
  (unix_recv_io): Ditto.
  (unix_addr): Ditto.
  (unix_peeraddr): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-06 02:39:44 +00:00
akr fbb29bc08c * ext/socket/init.c (cloexec_accept): Fix a compile error on
Debian GNU/kFreeBSD.  Consider HAVE_ACCEPT4 is defined
  but SOCK_CLOEXEC is not defined.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-05 16:40:36 +00:00
akr c89844dbc5 * ext/socket: define and use union_sockaddr instead of struct
sockaddr_storage for less casts.

* ext/socket/rubysocket.h (union_sockaddr): defined.

* ext/socket/socket.c (sock_accept): use union_sockaddr.
  (sock_accept_nonblock): ditto.
  (sock_sysaccept): ditto.
  (sock_s_getnameinfo): ditto.

* ext/socket/basicsocket.c (bsock_getsockname): ditto.
  (bsock_getpeername): ditto.
  (bsock_local_address): ditto.
  (bsock_remote_address): ditto.

* ext/socket/ancdata.c (bsock_recvmsg_internal): ditto.

* ext/socket/init.c (recvfrom_arg): ditto.
  (recvfrom_blocking): ditto.
  (rsock_s_recvfrom): ditto.
  (rsock_s_recvfrom_nonblock): ditto.
  (rsock_getfamily): ditto.

* ext/socket/raddrinfo.c (rb_addrinfo_t): ditto.
  (ai_get_afamily): ditto.
  (inspect_sockaddr): ditto.
  (addrinfo_mdump): ditto.
  (addrinfo_mload): ditto.
  (addrinfo_getnameinfo): ditto.
  (addrinfo_ip_port): ditto.
  (extract_in_addr): ditto.
  (addrinfo_ipv6_to_ipv4): ditto.
  (addrinfo_unix_path): ditto.

* ext/socket/tcpserver.c (tcp_accept): ditto.
  (tcp_accept_nonblock): ditto.
  (tcp_sysaccept): ditto.

* ext/socket/ipsocket.c (ip_addr): ditto.
  (ip_peeraddr): ditto.
  (ip_s_getaddress): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-24 17:51:17 +00:00
akr 75a5be3717 * ext/socket/ancdata.c (rsock_recvmsg): ignore truncated part of
socket address returned from recvmsg().

* ext/socket/init.c (recvfrom_blocking): ignore truncated part of
  socket address returned from recvfrom().
  (rsock_s_recvfrom_nonblock): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-16 11:44:42 +00:00
akr 18a8046d1c * ext/socket: always operate length of socket addess companion with
socket address. 

* ext/socket/rubysocket.h (rsock_make_ipaddr): add an argument for
  socket address length.
  (rsock_ipaddr): ditto.

* ext/socket/ipsocket.c (ip_addr): pass length to rsock_ipaddr.
  (ip_peeraddr): ditto.
  (ip_s_getaddress): pass length to rsock_make_ipaddr.

* ext/socket/socket.c (make_addrinfo): pass length to rsock_ipaddr.
  (sock_s_getnameinfo): pass actual address length to rb_getnameinfo.
  (sock_s_unpack_sockaddr_in): pass length to rsock_make_ipaddr.
  
* ext/socket/init.c (rsock_s_recvfrom): pass length to rsock_ipaddr.
  (rsock_s_recvfrom_nonblock): ditto.

* ext/socket/tcpsocket.c (tcp_sockaddr): pass length to
  rsock_make_ipaddr.

* ext/socket/raddrinfo.c (make_ipaddr0): add an argument for socket
  address length.  pass the length to rb_getnameinfo.
  (rsock_ipaddr): ditto.
  (rsock_make_ipaddr): add an argument for socket address length. 
  pass the length to make_ipaddr0.
  (make_inetaddr): pass length to make_ipaddr0.
  a local variable renamed.
  (host_str): a local variable renamed.
  (port_str): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-14 11:28:49 +00:00
nobu a9cbe8c721 init.c: declaration-after-statement
* ext/socket/init.c (cloexec_accept): fix declaration-after-statement.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-04 06:19:40 +00:00
akr 1ff38a5bbf * ext/socket/basicsocket.c (bsock_getsockname): ignore truncated
part of socket address.
  (bsock_getpeername): ditto.
  (bsock_local_address): ditto.
  (bsock_remote_address): ditto.

* ext/socket/unixsocket.c (unix_path): ditto.
  (unix_addr): ditto.
  (unix_peeraddr): ditto.

* ext/socket/init.c (cloexec_accept): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38993 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-30 12:01:51 +00:00
usa 91987f6b04 * ext/socket/{basicksocket,init,udpsocket}.c: revert some parts of
r36944.  it breaks mswin/mingw ruby and brought into many many
  crashes.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-09-10 01:41:59 +00:00
kosaki 84c77c1520 * ext/socket/basicsocket.c (rsock_bsock_send):
avoid unnecessary select() calls before doing I/O
  Patch by Eric Wong. [Feature #4538] [ruby-core:35586]
* ext/socket/init.c (rsock_s_recvfrom): ditto.
* ext/socket/init.c (rsock_s_accept): ditto.
* ext/socket/udpsocket.c (udp_send): ditto.
* io.c (io_fflush): ditto.
* io.c (io_binwrite): ditto.
* io.c (rb_io_syswrite): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-09-09 17:29:12 +00:00
usa 2574b80d83 * ext/socket/init.c (rsock_init_sock): need to update max fd on all
platforms.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-19 05:20:08 +00:00
akr 385a7d4594 * ext/socket/init.c (rsock_socket0): don't clear try_sock_cloexec if
SOCK_CLOEXEC is not a reason for EINVAL.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-11-05 08:56:50 +00:00
akr 0e68c46e2d * ext/socket/init.c (rsock_socket0): extract single socket() call with
CLOEXEC handling from rsock_socket.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-11-05 06:46:02 +00:00
nagachika a0b22b1a39 * ext/socket/init.c (rsock_socket): set close-on-exec flag when
SOCK_CLOEXEC is not available.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-11-03 13:14:48 +00:00
akr c16f98ab0a * io.c (rb_maygvl_fd_fix_cloexec): renamed from fd_set_cloexec.
* internal.h (rb_maygvl_fd_fix_cloexec): declared.

* ext/socket/init.c (cloexec_accept): use rb_maygvl_fd_fix_cloexec.
  (rsock_s_accept_nonblock): use rb_update_max_fd.
  (rsock_s_accept): use rb_update_max_fd.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-11-01 03:04:03 +00:00
akr 5dbc3d1e79 * ext/socket/init.c (cloexec_accept): new function to use accept4 if
available.
  (rsock_s_accept_nonblock): use cloexec_accept.
  (accept_blocking): ditto.

* ext/socket/extconf.rb: check accept4.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-10-31 23:26:19 +00:00
akr 1a8fbff3db * ext/socket/init.c (rsock_socket): use SOCK_CLOEXEC if available.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-10-31 14:38:50 +00:00
akr 1a70dfe6f4 * include/ruby/intern.h (rb_fd_fix_cloexec): renamed from
rb_fd_set_cloexec.

* io.c: follow the above renaming.

* ext/pty/pty.c: ditto.

* ext/socket/init.c: ditto.

* ext/socket/socket.c: ditto.

* ext/socket/ancdata.c: ditto.

* ext/socket/unixsocket.c: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33585 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-10-31 12:49:16 +00:00
akr b574a4d4a1 * include/ruby/intern.h (rb_fd_set_cloexec): declared.
* io.c (rb_fd_set_cloexec): new function.
  (ruby_dup): call rb_fd_set_cloexec to set close-on-exec flag.
  (rb_sysopen_internal): ditto.
  (rb_pipe): ditto.
  (io_reopen): ditto.
  (io_cntl): ditto.

* process.c (rb_f_exec): change the default :close_others option to
  true.
  (rb_f_system): ditto.
  (move_fds_to_avoid_crash): call rb_fd_set_cloexec to set
  close-on-exec flag.
  (ruby_setsid): ditto.
  (rb_daemon): ditto.

* thread_pthread.c (rb_thread_create_timer_thread): call
  rb_fd_set_cloexec to set close-on-exec flag.

* ruby.c (load_file_internal): ditto.

* file.c (rb_file_s_truncate): ditto.
  (file_load_ok): ditto.

* random.c (fill_random_seed): ditto.

* ext/pty/pty.c (chfunc): ditto.
  (get_device_once): ditto.

* ext/openssl/ossl_bio.c (ossl_obj2bio): ditto.

* ext/socket/init.c (rsock_socket): ditto.
  (rsock_s_accept_nonblock): ditto.
  (rsock_s_accept): ditto.

* ext/socket/socket.c (rsock_sock_s_socketpair): ditto.

* ext/socket/ancdata.c (discard_cmsg): ditto.
  (make_io_for_unix_rights): ditto.

* ext/socket/unixsocket.c (unix_recv_io): ditto.

* ext/io/console/console.c (console_dev): ditto.

[ruby-core:38140] [Feature #5041]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-10-22 09:58:15 +00:00
drbrain 1297942451 * ext/socket: Make Socket documentation appear. Add documentation for
Socket, TCPServer, SOCKSSocket.  Patch by Sylvain Daubert.
  [Ruby 1.9 - Feature #5182]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-15 23:08:39 +00:00