summaryrefslogtreecommitdiff
path: root/test/socket/test_unix.rb
AgeCommit message (Collapse)Author
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-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-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-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-02use assert_raisenobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50727 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
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
2014-02-21socket: sendmsg/recvmsg only retries blocking on errorsnormal
* ext/socket/ancdata.c (bsock_sendmsg_internal): only retry on error (bsock_recvmsg_internal): ditto * test/socket/test_unix.rb: test above for infinite loop git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-18* test/socket/test_socket.rb: unix socket is required by test case.hsbt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-18* test/socket/test_addrinfo.rb: remove unused variables.hsbt
* test/socket/test_nonblock.rb: ditto. * test/socket/test_socket.rb: ditto. * test/socket/test_unix.rb: ditto. * test/testunit/test_parallel.rb: ditto. * test/webrick/test_filehandler.rb: ditto. * test/xmlrpc/test_features.rb: ditto. * test/zlib/test_zlib.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-08Fix #6154 by introducing new EAGAIN/EWOULDBLOCK/EINPROGRESSheadius
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-01-31* ext/socket/raddrinfo.c (rsock_unix_sockaddr_len): returnshugo
sizeof(sa_familiy_t) if path is empty. see "Autobind Feature" in unix(7) for details. * ext/socket/lib/socket.rb (unix_socket_abstract_name?): treat an empty path as an abstract name. * test/socket/test_unix.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-30* ext/socket/unixsocket.c (rsock_init_unixsock): use rb_inspect()shugo
because rb_sys_fail_str() fails if its argument contains NUL. * test/socket/test_unix.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-29* ext/socket/socket.c (sock_s_pack_sockaddr_un): calculate theshugo
correct address length of an abstract socket. * test/socket/test_unix.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-25* ext/socket/raddrinfo.c (rsock_unixpath_len, init_unix_addrinfo),shugo
ext/socket/unixsocket.c (unixsock_connect_internal, rsock_init_unixsock): calculate the correct address length of an abstract socket. Without this fix, sizeof(struct sockaddr_un) is specified as the length of an abstract socket for bind(2) or connect(2), so the address of the socket is filled with extra NUL characters. See unix(7) for details. * ext/socket/lib/socket.rb (unix_server_socket): don't access the file system if the platform is Linux and path starts with NUL, which means that the socket is an abstract socket. * test/socket/test_unix.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-04-26* ext/socket/raddrinfo.c (init_unix_addrinfo): support the longestakr
path in sockaddr_un. (inspect_sockaddr): ditto. (addrinfo_mdump): ditto. (addrinfo_mload): ditto. (rsock_unixpath_str): new function. (rsock_unixpath): removed. (rsock_unixaddr): use rsock_unixpath_str. * ext/socket/socket.c (sock_s_pack_sockaddr_un): support the longest path in sockaddr_un. (sock_s_unpack_sockaddr_un): ditto. (sock_s_gethostbyaddr): unused variable removed. * ext/socket/unixsocket.c (rsock_init_unixsock): support the longest path in sockaddr_un. * ext/socket/rubysocket.h (rsock_unixpath_str): declared. (rsock_unixpath): removed. * test/socket/test_unix.rb: comment out test_nul because abstract unix sockets may contain NULs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-04-23* test/socket/test_unix.rb (bound_unix_socket): make temporaryakr
filename shorter for less possibility of Unix socket path over 107 bytes when TMPDIR has long path. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-11-03add test for close-on-exec.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-13* test/socket/test_unix.rb: don't use Thread.abort_on_exception.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-13* ext/socket/unixsocket.c (unix_send_io): race condition fixed.akr
(unix_recv_io): ditto. fixed by Eric Wong. [ruby-core:35574] * test/socket/test_unix.rb: test added for above problem. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-28* test/socket/test_unix.rb (TestSocket_UNIXSocket#test_recvmsg):nobu
skip if AncillaryData is not available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27531 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-01-25* lib/matrix.rb: suppress warnings.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-06* {ext,lib,test}/**/*.rb: removed trailing spaces.nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-02* ext/socket/ancdata.c (rsock_discard_cmsg_resource): definedakr
unconditionally. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-27* ext/socket/ancdata.c (bsock_recvmsg_internal): close FDs passed byakr
SCM_RIGHTS unless :scm_rights=>true is given. (discard_cmsg): extracted from rsock_discard_cmsg_resource. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-25* ext/socket/ancdata.c (ancillary_s_unix_rights): new method.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-19* ext/socket/ancdata.c (ancillary_unix_rights): method renamed.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-18* ext/socket/ancdata.c (ancillary_rights): new method.akr
(make_io_for_rights): new function to allocate IOs for FDs in SCM_RIGHTS message. (bsock_recvmsg_internal): use make_io_for_rights. So the FDs can be closed by GC. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-11* ext/socket/lib/socket.rb (Socket.unix_server_socket): close theakr
socket when the block exits. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-11* ext/socket/lib/socket.rb (Socket.unix_server_socket): call the blockakr
if given. remove the socket file when the block exits. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-11rename tests classes.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-11* ext/socket/extconf.rb: check getpeereid.akr
* ext/socket/basicsocket.c (bsock_getpeereid): new method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22219 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-09* ext/socket/ancdata.c (ancillary_initialize): add family argument.akr
(ancdata_new): ditto. (ancillary_s_int): ditto. (ancillary_family): new function. (ancillary_family_m): new method. (ancillary_s_ip_pktinfo): follow ancdata_new change. (ancillary_s_ipv6_pktinfo): ditto. (bsock_recvmsg_internal): examine the socket address family. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-08* ext/socket/option.c (inspect_peercred): struct ucred containsakr
effective uid/gid. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-08LOCAL_PEERCRED is also available on MacOS X.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-08* ext/socket/option.c (inspect_local_peercred): cr_uid is a effectiveakr
uid, not a real uid. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-08* ext/socket/extconf.rb: check sys/param.h and sys/ucred.h.akr
* ext/socket/rubysocket.h: include sys/param.h and sys/ucred.h. * ext/socket/option.c (inspect_local_peercred): new function to show LOCAL_PEERCRED socket option on FreeBSD. (sockopt_inspect): show as LOCAL_* socket option if AF_UNIX and level is 0. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-08remove debug print.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-08* ext/socket/option.c (inspect_peercred): new function to showakr
SO_PEERCRED socket option. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-08* ext/socket/extconf.rb: check struct cmsgcred.akr
* ext/socket/ancdata.c (anc_inspect_passcred_credentials): add "(ucred)". (anc_inspect_socket_creds): show struct cmsgcred too, for FreeBSD. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-08test renamed.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-08* ext/socket/extconf.rb: check struct sockcred.akr
* ext/socket/ancdata.c (anc_inspect_socket_creds): new function to show SCM_CREDS on NetBSD. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-08add a test.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-05* ext/socket: AddrInfo is renamed to Addrinfo. [ruby-dev:37876]akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-02* ext/socket/rubysocket.h (cmsg_type_arg): declared.akr
(Init_ancdata): ditto. * ext/socket/init.c (Init_socket_init): call Init_ancdata. * ext/socket/constants.c (cmsg_type_arg): defined. * ext/socket/depend: add dependency for ancdata.o. * ext/socket/mkconstants.rb: generate scm_optname_to_int. more constants. * ext/socket/extconf.rb: add ancdata.o. * ext/socket/ancdata.c: new file. new method BasicSocket#{sendmsg,sendmsg_nonblock,recvmsg,recvmsg_nonblock} git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-05don't get a name for anonymous Unix socket.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21346 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-01* ext/socket/mkconstants.rb: generate family_to_int().akr
* ext/socket/socket.c (setup_domain_and_type): use family_to_int. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-31* ext/socket/socket.c (sock_s_socketpair): yield if a block is given.akr
(io_call_close): defined. (io_close): defined. (pair_yield): defined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e