Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from ruby:master #572

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/error_highlight/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def self.max_snippet_width=(width)
def self.terminal_width
# lazy load io/console, so it's not loaded when 'max_snippet_width' is set
require "io/console"
STDERR.winsize[1] if STDERR.tty?
$stderr.winsize[1] if $stderr.tty?
rescue LoadError, NoMethodError, SystemCallError
# do not truncate when window size is not available
end
Expand Down
23 changes: 19 additions & 4 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,14 @@ class ResolvError < StandardError; end

class ResolvTimeout < Timeout::Error; end

WINDOWS = /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM || ::RbConfig::CONFIG['host_os'] =~ /mswin/
private_constant :WINDOWS

##
# Resolv::Hosts is a hostname resolver that uses the system hosts file.

class Hosts
if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM and
if WINDOWS
begin
require 'win32/resolv'
DefaultFileName = Win32::Resolv.get_hosts_path || IO::NULL
Expand Down Expand Up @@ -659,8 +662,20 @@ def self.free_request_id(host, port, id) # :nodoc:
}
end

def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
begin
case RUBY_PLATFORM
when *[
# https://www.rfc-editor.org/rfc/rfc6056.txt
# Appendix A. Survey of the Algorithms in Use by Some Popular Implementations
/freebsd/, /linux/, /netbsd/, /openbsd/, /solaris/,
/darwin/, # the same as FreeBSD
] then
def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
udpsock.bind(bind_host, 0)
end
else
# Sequential port assignment
def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
# Ephemeral port number range recommended by RFC 6056
port = random(1024..65535)
udpsock.bind(bind_host, port)
rescue Errno::EADDRINUSE, # POSIX
Expand Down Expand Up @@ -1007,7 +1022,7 @@ def Config.default_config_hash(filename="/etc/resolv.conf")
if File.exist? filename
config_hash = Config.parse_resolv_conf(filename)
else
if /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
if WINDOWS
require 'win32/resolv'
search, nameserver = Win32::Resolv.get_resolv_info
config_hash = {}
Expand Down
Loading