mirror of
https://github.com/golang/go
synced 2024-11-18 11:24:41 -07:00
syscall: fix nacl listener to not accept connections once closed
Change-Id: I3ba6e97089ef6e69ba31dfb632df465859906a74 Reviewed-on: https://go-review.googlesource.com/15940 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
42c7929c04
commit
19aa4209ae
@ -208,7 +208,6 @@ func TestListenerClose(t *testing.T) {
|
||||
case "unix", "unixpacket":
|
||||
defer os.Remove(ln.Addr().String())
|
||||
}
|
||||
defer ln.Close()
|
||||
|
||||
if err := ln.Close(); err != nil {
|
||||
if perr := parseCloseError(err); perr != nil {
|
||||
@ -221,6 +220,14 @@ func TestListenerClose(t *testing.T) {
|
||||
c.Close()
|
||||
t.Fatal("should fail")
|
||||
}
|
||||
|
||||
if network == "tcp" {
|
||||
cc, err := Dial("tcp", ln.Addr().String())
|
||||
if err == nil {
|
||||
t.Error("Dial to closed TCP listener succeeeded.")
|
||||
cc.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -577,7 +577,7 @@ func (f *netFile) connect(sa Sockaddr) error {
|
||||
return EISCONN
|
||||
}
|
||||
l, ok := net.listener[netAddr{f.proto, f.sotype, sa.key()}]
|
||||
if !ok {
|
||||
if !ok || l.listenerClosed() {
|
||||
net.Unlock()
|
||||
return ECONNREFUSED
|
||||
}
|
||||
@ -676,6 +676,12 @@ func (f *netFile) sendto(p []byte, flags int, to Sockaddr) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *netFile) listenerClosed() bool {
|
||||
f.listener.Lock()
|
||||
defer f.listener.Unlock()
|
||||
return f.listener.closed
|
||||
}
|
||||
|
||||
func (f *netFile) close() error {
|
||||
if f.listener != nil {
|
||||
f.listener.close()
|
||||
|
Loading…
Reference in New Issue
Block a user