mirror of
https://github.com/golang/go
synced 2024-11-06 02:36:15 -07:00
f60fcca5f1
My previous https://golang.org/cl/22101 to add context throughout the net package broke Plan 9, which isn't currently tested (#15251). It also broke some old unsupported version of Windows (Windows 2000?) which doesn't have the ConnectEx function, but that was only found visually, since our minimum supported Windows version has ConnectEx. This change simplifies the Windows and deletes the non-ConnectEx code path. Windows 2000 will work even less now, if it even worked before. Windows XP remains our minimum supported version. Specifically, the previous CL stopped using the "dial" function, which 0intro noted: https://github.com/golang/go/issues/15333#issuecomment-210842761 This CL removes the dial function instead and makes plan9's net implementation respect contexts, which likely fixes a number of t.Skipped tests. I'm leaving that to 0intro to investigate. In the process of propagating and respecting contexts for plan9, I had to change some signatures to add contexts to more places and ended up pushing contexts down into the Go-based DNS resolution as well, replacing the pure-Go DNS implementation's use of "timeout time.Duration" with a context instead. Updates #11932 Updates #15328 Fixes #15333 Change-Id: I6ad1e62f38271cdd86b3f40921f2d0f23374936a Reviewed-on: https://go-review.googlesource.com/22144 Reviewed-by: David du Colombier <0intro@gmail.com> Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package net
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
func (c *TCPConn) readFrom(r io.Reader) (int64, error) {
|
|
return genericReadFrom(c, r)
|
|
}
|
|
|
|
func dialTCP(ctx context.Context, net string, laddr, raddr *TCPAddr) (*TCPConn, error) {
|
|
if testHookDialTCP != nil {
|
|
return testHookDialTCP(ctx, net, laddr, raddr)
|
|
}
|
|
return doDialTCP(ctx, net, laddr, raddr)
|
|
}
|
|
|
|
func doDialTCP(ctx context.Context, net string, laddr, raddr *TCPAddr) (*TCPConn, error) {
|
|
switch net {
|
|
case "tcp", "tcp4", "tcp6":
|
|
default:
|
|
return nil, UnknownNetworkError(net)
|
|
}
|
|
if raddr == nil {
|
|
return nil, errMissingAddress
|
|
}
|
|
fd, err := dialPlan9(ctx, net, laddr, raddr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return newTCPConn(fd), nil
|
|
}
|
|
|
|
func (ln *TCPListener) ok() bool { return ln != nil && ln.fd != nil && ln.fd.ctl != nil }
|
|
|
|
func (ln *TCPListener) accept() (*TCPConn, error) {
|
|
fd, err := ln.fd.acceptPlan9()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return newTCPConn(fd), nil
|
|
}
|
|
|
|
func (ln *TCPListener) close() error {
|
|
if _, err := ln.fd.ctl.WriteString("hangup"); err != nil {
|
|
ln.fd.ctl.Close()
|
|
return err
|
|
}
|
|
if err := ln.fd.ctl.Close(); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (ln *TCPListener) file() (*os.File, error) {
|
|
f, err := ln.dup()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return f, nil
|
|
}
|
|
|
|
func listenTCP(ctx context.Context, network string, laddr *TCPAddr) (*TCPListener, error) {
|
|
fd, err := listenPlan9(ctx, network, laddr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &TCPListener{fd}, nil
|
|
}
|