Server IP : 172.67.216.182 / Your IP : 162.158.170.96 Web Server : Apache System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /lib/ruby/vendor_ruby/rubygems/core_ext/ |
Upload File : |
require 'socket' module CoreExtensions module TCPSocketExt def self.prepended(base) base.prepend Initializer end module Initializer CONNECTION_TIMEOUT = 5 IPV4_DELAY_SECONDS = 0.1 def initialize(host, serv, *rest) mutex = Thread::Mutex.new addrs = [] threads = [] cond_var = Thread::ConditionVariable.new Addrinfo.foreach(host, serv, nil, :STREAM) do |addr| Thread.report_on_exception = false if defined? Thread.report_on_exception = () threads << Thread.new(addr) do # give head start to ipv6 addresses sleep IPV4_DELAY_SECONDS if addr.ipv4? # raises Errno::ECONNREFUSED when ip:port is unreachable Socket.tcp(addr.ip_address, serv, connect_timeout: CONNECTION_TIMEOUT).close mutex.synchronize do addrs << addr.ip_address cond_var.signal end end end mutex.synchronize do timeout_time = CONNECTION_TIMEOUT + Time.now.to_f while addrs.empty? && (remaining_time = timeout_time - Time.now.to_f) > 0 cond_var.wait(mutex, remaining_time) end host = addrs.shift unless addrs.empty? end threads.each {|t| t.kill.join if t.alive? } super(host, serv, *rest) end end end end TCPSocket.prepend CoreExtensions::TCPSocketExt