mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
resolv.rb: remove rangerand
* 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
This commit is contained in:
parent
e6c0a8f19e
commit
e667897b46
1 changed files with 2 additions and 12 deletions
|
@ -609,16 +609,6 @@ class Resolv
|
|||
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:
|
||||
|
||||
|
@ -627,7 +617,7 @@ class Resolv
|
|||
RequestIDMutex.synchronize {
|
||||
h = (RequestID[[host, port]] ||= {})
|
||||
begin
|
||||
id = rangerand(0x0000..0xffff)
|
||||
id = random(0x0000..0xffff)
|
||||
end while h[id]
|
||||
h[id] = true
|
||||
}
|
||||
|
@ -648,7 +638,7 @@ class Resolv
|
|||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue