Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/net/dns/resolver/timeouts.rb
Views: 11784
# -*- coding: binary -*-1require 'timeout'23module SecondsHandle #:nodoc: all4def transform(secs)5case secs6when 07to_s8when 1..599"#{secs} seconds"10when 60..355911"#{secs/60} minutes and #{secs%60} seconds"12else13hours = secs/360014secs -= (hours*3600)15"#{hours} hours, #{secs/60} minutes and #{secs%60} seconds"16end17end18end1920class DnsTimeout # :nodoc: all2122include SecondsHandle2324def initialize(seconds)25if seconds.is_a? Numeric and seconds >= 026@timeout = seconds27else28raise DnsTimeoutArgumentError, "Invalid value for tcp timeout"29end30end3132def to_i33@timeout34end3536def to_s37if @timeout == 038@output39else40@timeout.to_s41end42end4344def pretty_to_s45transform(@timeout)46end4748def timeout49unless block_given?50raise DnsTimeoutArgumentError, "Block required but missing"51end52if @timeout == 053yield54else55return Timeout.timeout(@timeout) do56yield57end58end59end60end6162class TcpTimeout < DnsTimeout # :nodoc: all63def initialize(seconds)64@output = "infinite"65super(seconds)66end67end6869class UdpTimeout < DnsTimeout # :nodoc: all70def initialize(seconds)71@output = "not defined"72super(seconds)73end74end7576class DnsTimeoutArgumentError < ArgumentError # :nodoc: all77end787980