net: give C.getaddrinfo a hint that we only want SOCK_STREAM answers

This should be more efficient everywhere, and appears to be
required on Solaris.

Copied from master repository.

From-SVN: r201637
This commit is contained in:
Ian Lance Taylor 2013-08-09 20:51:16 +00:00
parent cc277e8fd9
commit 537a6f7b47
1 changed files with 2 additions and 1 deletions

View File

@ -103,6 +103,7 @@ func cgoLookupIPCNAME(name string) (addrs []IP, cname string, err error, complet
var hints syscall.Addrinfo var hints syscall.Addrinfo
hints.Ai_flags = int32(cgoAddrInfoFlags()) hints.Ai_flags = int32(cgoAddrInfoFlags())
hints.Ai_socktype = syscall.SOCK_STREAM
h := syscall.StringBytePtr(name) h := syscall.StringBytePtr(name)
syscall.Entersyscall() syscall.Entersyscall()
@ -130,7 +131,7 @@ func cgoLookupIPCNAME(name string) (addrs []IP, cname string, err error, complet
} }
} }
for r := res; r != nil; r = r.Ai_next { for r := res; r != nil; r = r.Ai_next {
// Everything comes back twice, once for UDP and once for TCP. // We only asked for SOCK_STREAM, but check anyhow.
if r.Ai_socktype != syscall.SOCK_STREAM { if r.Ai_socktype != syscall.SOCK_STREAM {
continue continue
} }