Skip to content

Commit

Permalink
resolv.rb: remove rangerand
Browse files Browse the repository at this point in the history
* lib/resolv.rb (Resolv::DNS.rangerand): rand and random_number
  accept a Range.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Mar 6, 2018
1 parent e6c0a8f commit e667897
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,16 +609,6 @@ def self.random(arg) # :nodoc:
end
end


def self.rangerand(range) # :nodoc:
base = range.begin
len = range.end - range.begin
if !range.exclude_end?
len += 1
end
base + random(len)
end

RequestID = {} # :nodoc:
RequestIDMutex = Thread::Mutex.new # :nodoc:

Expand All @@ -627,7 +617,7 @@ def self.allocate_request_id(host, port) # :nodoc:
RequestIDMutex.synchronize {
h = (RequestID[[host, port]] ||= {})
begin
id = rangerand(0x0000..0xffff)
id = random(0x0000..0xffff)
end while h[id]
h[id] = true
}
Expand All @@ -648,7 +638,7 @@ def self.free_request_id(host, port, id) # :nodoc:

def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
begin
port = rangerand(1024..65535)
port = random(1024..65535)
udpsock.bind(bind_host, port)
rescue Errno::EADDRINUSE, # POSIX
Errno::EACCES, # SunOS: See PRIV_SYS_NFS in privileges(5)
Expand Down

0 comments on commit e667897

Please sign in to comment.