summaryrefslogtreecommitdiff
path: root/test/socket
AgeCommit message (Collapse)Author
2016-08-30Use qualified namesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-30* ext/socket/raddrinfo.c (host_str, port_str): Use StringValueCStrusa
instead of (Safe)StringValue, to detect NUL byte in the string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-30* test/socket/test_addrinfo.rb (TestSocketAddrinfo#test_addrinfo_ip): previoususa
test logic depended on platform specific implementation. use more portable logic. this fixes a test failure on Windows. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-30test_addrinfo.rb: signle digit addressnobu
* test/socket/test_addrinfo.rb (test_addrinfo_ip): use single digit address so that the values are same in both decimal and octal. some platform zero-prefixed dotted-decimal is parsed as an octal value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-30raddrinfo.c: fix for SHARABLE_MIDDLE_SUBSTRINGnobu
* ext/socket/raddrinfo.c (host_str, port_str): use RSTRING_LEN instead of strlen, since RSTRING_PTR StringValueCStr may not be NUL-terminated when SHARABLE_MIDDLE_SUBSTRING=1. reported by @tmtms, http://twitter.com/tmtms/status/736910516229005312 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-30test_addrinfo.rb: special hostnamesnobu
* test/socket/test_addrinfo.rb (test_addrinfo_ip): add tests for special hostnames, <any> and <broadcast>. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55211 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-10* test/socket/test_socket.rb (test_udp_recvmsg_truncation):odaira
AIX does not set the MSG_TRUNC flag for a message partially read by recvmsg(2) with the MSG_PEEK flag set. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-05* test/socket/test_addrinfo.rb (test_ipv6_address_predicates):odaira
IN6_IS_ADDR_V4COMPAT and IN6_IS_ADDR_V4MAPPED are broken on AIX, so skip related tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-05Sat Mar 5 09:17:54 2016 Rei Odaira <Rei.Odaira@gmail.com>odaira
* test/rinda/test_rinda.rb (test_make_socket_ipv4_multicast): The fifth argument to getsockopt(2) should be modified to indicate the actual size of the value on return, but not in AIX. This is a know bug. Skip related tests. * test/rinda/test_rinda.rb (test_ring_server_ipv4_multicast): ditto. * test/rinda/test_rinda.rb (test_make_socket_unicast): ditto. * test/socket/test_basicsocket.rb (test_getsockopt): ditto. * test/socket/test_sockopt.rb (test_bool): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-17option.c: single byte booleannobu
* ext/socket/option.c (sockopt_bool): relax boolean size to be one too not only sizeof(int). Winsock getsockopt() returns a single byte as a boolean socket option. [ruby-core:72730] [Bug #11958] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-24ignore exception is the address is IPv6naruse
some environments disables IPv6 even if they have IPv6 addresses. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-22Revert r53253. naruse fixed it differently in r53244normal
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53254 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-22test/socket/test_basicsocket.rb: attempt fix for [ruby-cvs:60402]normal
I'm not sure how fstat on fd=-1 can succeed on some systems... git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-21avoid rb_bug on BasicSocket.for_fd(-1)normal
* 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-07socket: expand docs+tests for recv_io/send_ionormal
* ext/socket/unixsocket.c (unix_send_io): document args (unix_recv_io): ditto * test/socket/test_unix.rb (test_fd_passing_class_mode): added I was working on these when I encountered the problem in with BasicSocket.for_fd not handling mode args: https://bugs.ruby-lang.org/issues/11778 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-03* test/ruby/test_mixed_unicode_escapes.rb: fixed typo.hsbt
[fix GH-1122] Patch by @davydovanton * test/ruby/test_object.rb: ditto. * test/socket/test_tcp.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-21* test/socket/test_socket.rb (test/socket/test_socket.rb): skip the test ↵ngoto
when Socket::SO_TIMESTAMP is not defined. Fix error on Solaris 10. [Bug #11728] [ruby-dev:49377] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52701 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-18* test/socket/test_socket.rb (test_udp_recvmsg_truncation): rflags isakr
nil on Solaris 10 which have no HAVE_STRUCT_MSGHDR_MSG_CONTROL. Reported by Naohisa Goto. [ruby-core:71557] [Bug #11709] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-18add tests.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52647 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-17socket: fix recvmsg without argumentnormal
* ext/socket/ancdata.c (bsock_recvmsg_internal): grow buffer on unspecified maxdatlen [ruby-core:71517] [Bug #11701] * ext/socket/lib/socket.rb (Socket#recvmsg): nil default for dlen (Socket#recvmsg_nonblock): ditto * test/socket/test_socket.rb (test_recvmsg_udp_no_arg): new test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-14* ext/socket/lib/socket.rb: Specify frozen_string_literal: true.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52576 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-07-21test/socket/test_nonblock.rb: increase buffer sizes to OpenBSD limitsnormal
* test/socket/test_nonblock.rb: increase buffer sizes to OpenBSD limits. Thanks to Jeremy Evans <code@jeremyevans.net> [ruby-core:70058] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51310 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-17test/socket/test_nonblock: use smaller buffer for sendmsgnormal
OpenBSD's limit is less than 128. * test/socket/test_nonblock: use smaller buffer for sendmsg Patch-by: Jeremy Evans <code@jeremyevans.net> [ruby-core:70016] [Bug #11364] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-13use Timeout.timeoutnobu
* time: Object#timeout has been deprecated a long time ago, use Timeout.timeout. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-18test/socket/test_unix.rb: replace sleep with selectnormal
Not sure what drugs I was on, but blindly sleeping instead of using IO#wait or IO.select to wait for data on a socket is completely wrong. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50951 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-16test_nonblock.rb: use assert_predicatenobu
* test/socket/test_nonblock.rb (test_recv_nonblock_no_exception), (test_recvfrom_nonblock_no_exception): use assert_predicate for failure messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50917 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-16test_nonblock.rb: fix failure on OSXnobu
* test/socket/test_nonblock.rb (test_recvfrom_nonblock_no_exception): no destination to already connected socket. fix failure on OSX. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50916 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-05test/socket/test_nonblock.rb: try to avoid EMSGSIZEnormal
We want to test the IO::WaitWritable behavior, so silently discarding Errno::EMSGSIZE prevents the test from being effective. [ruby-core:69466] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-04FreeBSD raises Errno::EMSGSIZEnaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-02use assert_raisenobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-02test_nonblock.rb: skip if EPROTONOSUPPORTnobu
* test/socket/test_nonblock.rb (test_sendmsg_nonblock_seqpacket): OSX raises EPROTONOSUPPORT. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-02test/socket/test_nonblock.rb: new test for sendmsg_nonblocknormal
sendmsg_nonblock was not tested on any of my systems due to the common 64K limit. I also don't believe UDP sockets are at all a useful candidate for sendmsg_nonblock testing since they should never block on sending. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-18test_nonblock.rb: refine failure messagenobu
* test/socket/test_nonblock.rb (test_accept_nonblock): refine assertion for better failure message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50530 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-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-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-10test_addrinfo.rb: relax memory usage criterionnobu
* test/socket/test_addrinfo.rb (test_marshal_memory_leak): relax the criterion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50202 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-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-01-15* io.c (rb_io_close_m): Don't raise when the IO object is closed.akr
[ruby-core:67444] [Feature #10718] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-13test_basicsocket.rb: do not hardcode port numbernobu
* test/socket/test_basicsocket.rb (socks): use dynamically chosen port number, and remove never used argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-13* test/socket/test_basicsocket.rb: Remove unused constant.headius
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-13* remove trailing spaces.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-13* test/socket/test_basicsocket.rb: Add basic tests for close_readheadius
and close_write using TCPServer/Socket as a target. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-04test/socket/test_unix.rb (TestSocket_UNIXSocket#test_too_long_path): ↵odaira
sockaddr_un.sun_path in AIX is defined as char[1024], so "a" * 300 is not too long. "a" * 3000 would be enough. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-28Suppress warnings.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-28* ext/socket/unixsocket.c (rsock_init_unixsock): Open a socketakr
after path length check. This fixes a fd leak by TestSocket_UNIXSocket#test_too_long_path. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e