OLD | NEW |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // +build !netgo | 5 // +build !netgo |
6 // +build darwin dragonfly freebsd linux netbsd openbsd | 6 // +build darwin dragonfly freebsd linux netbsd openbsd |
7 | 7 |
8 package net | 8 package net |
9 | 9 |
10 /* | 10 /* |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 hints.ai_socktype = C.SOCK_STREAM | 92 hints.ai_socktype = C.SOCK_STREAM |
93 | 93 |
94 h := C.CString(name) | 94 h := C.CString(name) |
95 defer C.free(unsafe.Pointer(h)) | 95 defer C.free(unsafe.Pointer(h)) |
96 gerrno, err := C.getaddrinfo(h, nil, &hints, &res) | 96 gerrno, err := C.getaddrinfo(h, nil, &hints, &res) |
97 if gerrno != 0 { | 97 if gerrno != 0 { |
98 var str string | 98 var str string |
99 if gerrno == C.EAI_NONAME { | 99 if gerrno == C.EAI_NONAME { |
100 str = noSuchHost | 100 str = noSuchHost |
101 } else if gerrno == C.EAI_SYSTEM { | 101 } else if gerrno == C.EAI_SYSTEM { |
| 102 if err == nil { |
| 103 // err should not be nil, but sometimes getaddri
nfo returns |
| 104 // gerrno == C.EAI_SYSTEM with err == nil on Lin
ux. |
| 105 // The report claims that it happens when we hav
e too many |
| 106 // open files, so use syscall.EMFILE (too many o
pen files in system). |
| 107 // Most system calls would return ENFILE (too ma
ny open files), |
| 108 // so at the least EMFILE should be easy to reco
gnize if this |
| 109 // comes up again. golang.org/issue/6232. |
| 110 err = syscall.EMFILE |
| 111 } |
102 str = err.Error() | 112 str = err.Error() |
103 } else { | 113 } else { |
104 str = C.GoString(C.gai_strerror(gerrno)) | 114 str = C.GoString(C.gai_strerror(gerrno)) |
105 } | 115 } |
106 return nil, "", &DNSError{Err: str, Name: name}, true | 116 return nil, "", &DNSError{Err: str, Name: name}, true |
107 } | 117 } |
108 defer C.freeaddrinfo(res) | 118 defer C.freeaddrinfo(res) |
109 if res != nil { | 119 if res != nil { |
110 cname = C.GoString(res.ai_canonname) | 120 cname = C.GoString(res.ai_canonname) |
111 if cname == "" { | 121 if cname == "" { |
(...skipping 30 matching lines...) Expand all Loading... |
142 func cgoLookupCNAME(name string) (cname string, err error, completed bool) { | 152 func cgoLookupCNAME(name string) (cname string, err error, completed bool) { |
143 _, cname, err, completed = cgoLookupIPCNAME(name) | 153 _, cname, err, completed = cgoLookupIPCNAME(name) |
144 return | 154 return |
145 } | 155 } |
146 | 156 |
147 func copyIP(x IP) IP { | 157 func copyIP(x IP) IP { |
148 y := make(IP, len(x)) | 158 y := make(IP, len(x)) |
149 copy(y, x) | 159 copy(y, x) |
150 return y | 160 return y |
151 } | 161 } |
OLD | NEW |