Skip to content

Commit 45bb887

Browse files
committed
net: stop using GetHostByName and GetServByName
Go 1.6 requires Windows XP or later. I have: C:\>systeminfo | findstr /B /C:"OS Name" /C:"OS Version" OS Name: Microsoft Windows XP Professional OS Version: 5.1.2600 Service Pack 3 Build 2600 Running "go test" PASSes on my system after this CL is applied. Change-Id: Id59d169138c4a4183322c89ee7e766fb74d381fa Reviewed-on: https://go-review.googlesource.com/22209 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent f947429 commit 45bb887

File tree

2 files changed

+2
-112
lines changed

2 files changed

+2
-112
lines changed

src/net/fd_windows.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ func sysInit() {
4242
initErr = os.NewSyscallError("wsastartup", e)
4343
}
4444
canCancelIO = syscall.LoadCancelIoEx() == nil
45-
if syscall.LoadGetAddrInfo() == nil {
46-
lookupPort = newLookupPort
47-
lookupIP = newLookupIP
48-
}
49-
5045
hasLoadSetFileCompletionNotificationModes = syscall.LoadSetFileCompletionNotificationModes() == nil
5146
if hasLoadSetFileCompletionNotificationModes {
5247
// It's not safe to use FILE_SKIP_COMPLETION_PORT_ON_SUCCESS if non IFS providers are installed:

src/net/lookup_windows.go

Lines changed: 2 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ import (
1212
"unsafe"
1313
)
1414

15-
var (
16-
lookupPort = oldLookupPort
17-
lookupIP = oldLookupIP
18-
)
19-
2015
func getprotobyname(name string) (proto int, err error) {
2116
p, err := syscall.GetProtoByName(name)
2217
if err != nil {
@@ -71,61 +66,7 @@ func lookupHost(ctx context.Context, name string) ([]string, error) {
7166
return addrs, nil
7267
}
7368

74-
func gethostbyname(name string) (addrs []IPAddr, err error) {
75-
// caller already acquired thread
76-
h, err := syscall.GetHostByName(name)
77-
if err != nil {
78-
return nil, os.NewSyscallError("gethostbyname", err)
79-
}
80-
switch h.AddrType {
81-
case syscall.AF_INET:
82-
i := 0
83-
addrs = make([]IPAddr, 100) // plenty of room to grow
84-
for p := (*[100](*[4]byte))(unsafe.Pointer(h.AddrList)); i < cap(addrs) && p[i] != nil; i++ {
85-
addrs[i] = IPAddr{IP: IPv4(p[i][0], p[i][1], p[i][2], p[i][3])}
86-
}
87-
addrs = addrs[0:i]
88-
default: // TODO(vcc): Implement non IPv4 address lookups.
89-
return nil, syscall.EWINDOWS
90-
}
91-
return addrs, nil
92-
}
93-
94-
func oldLookupIP(ctx context.Context, name string) ([]IPAddr, error) {
95-
// GetHostByName return value is stored in thread local storage.
96-
// Start new os thread before the call to prevent races.
97-
type ret struct {
98-
addrs []IPAddr
99-
err error
100-
}
101-
ch := make(chan ret, 1)
102-
go func() {
103-
acquireThread()
104-
defer releaseThread()
105-
runtime.LockOSThread()
106-
defer runtime.UnlockOSThread()
107-
addrs, err := gethostbyname(name)
108-
ch <- ret{addrs: addrs, err: err}
109-
}()
110-
select {
111-
case r := <-ch:
112-
if r.err != nil {
113-
r.err = &DNSError{Err: r.err.Error(), Name: name}
114-
}
115-
return r.addrs, r.err
116-
case <-ctx.Done():
117-
// TODO(bradfitz,brainman): cancel the ongoing
118-
// gethostbyname? For now we just let it finish and
119-
// write to the buffered channel.
120-
return nil, &DNSError{
121-
Name: name,
122-
Err: ctx.Err().Error(),
123-
IsTimeout: ctx.Err() == context.DeadlineExceeded,
124-
}
125-
}
126-
}
127-
128-
func newLookupIP(ctx context.Context, name string) ([]IPAddr, error) {
69+
func lookupIP(ctx context.Context, name string) ([]IPAddr, error) {
12970
// TODO(bradfitz,brainman): use ctx?
13071

13172
type ret struct {
@@ -184,53 +125,7 @@ func newLookupIP(ctx context.Context, name string) ([]IPAddr, error) {
184125
}
185126
}
186127

187-
func getservbyname(network, service string) (int, error) {
188-
acquireThread()
189-
defer releaseThread()
190-
switch network {
191-
case "tcp4", "tcp6":
192-
network = "tcp"
193-
case "udp4", "udp6":
194-
network = "udp"
195-
}
196-
s, err := syscall.GetServByName(service, network)
197-
if err != nil {
198-
return 0, os.NewSyscallError("getservbyname", err)
199-
}
200-
return int(syscall.Ntohs(s.Port)), nil
201-
}
202-
203-
func oldLookupPort(ctx context.Context, network, service string) (int, error) {
204-
// GetServByName return value is stored in thread local storage.
205-
// Start new os thread before the call to prevent races.
206-
type result struct {
207-
port int
208-
err error
209-
}
210-
ch := make(chan result) // unbuffered
211-
go func() {
212-
acquireThread()
213-
defer releaseThread()
214-
runtime.LockOSThread()
215-
defer runtime.UnlockOSThread()
216-
port, err := getservbyname(network, service)
217-
select {
218-
case ch <- result{port: port, err: err}:
219-
case <-ctx.Done():
220-
}
221-
}()
222-
select {
223-
case r := <-ch:
224-
if r.err != nil {
225-
r.err = &DNSError{Err: r.err.Error(), Name: network + "/" + service}
226-
}
227-
return r.port, r.err
228-
case <-ctx.Done():
229-
return 0, mapErr(ctx.Err())
230-
}
231-
}
232-
233-
func newLookupPort(ctx context.Context, network, service string) (int, error) {
128+
func lookupPort(ctx context.Context, network, service string) (int, error) {
234129
// TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this.
235130
acquireThread()
236131
defer releaseThread()

0 commit comments

Comments
 (0)