1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
require "time"
module AsyncDNS
class Settings
@local_domain : String?
@reload_period : Time::Span
@last_reload : Time?
property static_hosts, nameservers, local_domain, search_domains, uses_tcp
getter timeout, max_attempts, abs_num_dots
def timeout=(timeout)
raise ArgumentError.new("timeout must be positive") if timeout < 0
|
<
<
<
<
|
1
2
3
4
5
6
7
8
9
10
|
module AsyncDNS
class Settings
@local_domain : String?
property static_hosts, nameservers, local_domain, search_domains, uses_tcp
getter timeout, max_attempts, abs_num_dots
def timeout=(timeout)
raise ArgumentError.new("timeout must be positive") if timeout < 0
|
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
@nameservers = [] of String
@search_domains = [] of String
@timeout = Time::Span.new(seconds: 2)
@max_attempts = 3
@abs_num_dots = 1
@uses_tcp = false
@reload_period = Time::Span.new(seconds: 2)
self.reload
end
def reload
{% if flag?(:unix) %}
self.parse_hosts "/etc/hosts"
self.parse_resolv_conf "/etc/resolv.conf"
{% else %}
{% raise "Your OS is not supported by AsyncDNS" %}
{% end %}
end
def parse_hosts(path)
@static_hosts.clear
File.each_line(path, chomp: true) do |line|
pos = line.index('#')
|
>
|
>
>
|
>
>
>
|
|
|
>
>
|
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
@nameservers = [] of String
@search_domains = [] of String
@timeout = Time::Span.new(seconds: 2)
@max_attempts = 3
@abs_num_dots = 1
@uses_tcp = false
@reload_period = Time::Span.new(seconds: 2)
@last_reload = Time::Span.zero
reload
end
def reload
return if Time.monotonic - @last_reload < @reload_period
{% if flag?(:haiku) %}
parse_hosts "/system/settings/network/hosts"
parse_resolv_conf "/system/settings/network/resolv.conf"
{% elsif flag?(:unix) %}
parse_hosts "/etc/hosts"
parse_resolv_conf "/etc/resolv.conf"
{% else %}
{% raise "Your OS is not supported by AsyncDNS" %}
{% end %}
@last_reload = Time.monotonic
end
def parse_hosts(path)
@static_hosts.clear
File.each_line(path, chomp: true) do |line|
pos = line.index('#')
|