net: introduce net.Error interface
Adds two more methods, Timeout and Temporary.
Implemented by os.Errno too. The intent is to make
the checks for os.EAGAIN a little less clunky.
It should also let us clean up a bug that Mike Solomon
pointed out: if a network server gets an "out of file descriptors"
error from Accept, the listener should not stop.
It will be able to check this because that error would
have Temporary() == true.
Also clean up some underscore names.
Fixes #442.
R=r
CC=golang-dev, msolo
https://golang.org/cl/957045
diff --git a/src/pkg/net/dnsconfig.go b/src/pkg/net/dnsconfig.go
index 4be2076..26f0e04 100644
--- a/src/pkg/net/dnsconfig.go
+++ b/src/pkg/net/dnsconfig.go
@@ -8,7 +8,7 @@
import "os"
-type _DNS_Config struct {
+type dnsConfig struct {
servers []string // servers to use
search []string // suffixes to append to local name
ndots int // number of dots in name to trigger absolute lookup
@@ -17,18 +17,30 @@
rotate bool // round robin among servers
}
-var _DNS_configError os.Error
+var dnsconfigError os.Error
+
+type DNSConfigError struct {
+ Error os.Error
+}
+
+func (e *DNSConfigError) String() string {
+ return "error reading DNS config: " + e.Error.String()
+}
+
+func (e *DNSConfigError) Timeout() bool { return false }
+func (e *DNSConfigError) Temporary() bool { return false }
+
// See resolv.conf(5) on a Linux machine.
// TODO(rsc): Supposed to call uname() and chop the beginning
// of the host name to get the default search domain.
// We assume it's in resolv.conf anyway.
-func _DNS_ReadConfig() (*_DNS_Config, os.Error) {
+func dnsReadConfig() (*dnsConfig, os.Error) {
file, err := open("/etc/resolv.conf")
if err != nil {
- return nil, err
+ return nil, &DNSConfigError{err}
}
- conf := new(_DNS_Config)
+ conf := new(dnsConfig)
conf.servers = make([]string, 3)[0:0] // small, but the standard limit
conf.search = make([]string, 0)
conf.ndots = 1