1
0
mirror of https://github.com/golang/go synced 2024-11-13 20:10:32 -07:00
go/src/net/tcpsock_plan9.go
David du Colombier 8a4087aee6 net: fix close on closed listener on Plan 9
Since close errors have been cleaned up in CL 39997,
TestCloseError is failing on Plan 9, because
TCPListener.Close didn't check that the listener
has already been closed before writing the "hangup"
string to the listener control file.

This change fixes TCPListener.Close on Plan 9,
by closing poll.FD before writing the "hangup"
string.

Fixes #20128.

Change-Id: I13862b23a9055dd1be658acef7066707d98c591f
Reviewed-on: https://go-review.googlesource.com/41850
Run-TryBot: David du Colombier <0intro@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-04-26 15:04:43 +00:00

79 lines
1.7 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.pfd.Close(); err != nil {
return err
}
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
}