Commit 42a76efc authored by Fazlul Shahriar's avatar Fazlul Shahriar Committed by Russ Cox

net: pass tests on Plan 9 again

R=golang-dev
CC=golang-dev
https://golang.org/cl/6280045
parent ede6718c
...@@ -130,7 +130,7 @@ func TestSelfConnect(t *testing.T) { ...@@ -130,7 +130,7 @@ func TestSelfConnect(t *testing.T) {
n = 1000 n = 1000
} }
switch runtime.GOOS { switch runtime.GOOS {
case "darwin", "freebsd", "netbsd", "openbsd", "windows": case "darwin", "freebsd", "netbsd", "openbsd", "plan9", "windows":
// Non-Linux systems take a long time to figure // Non-Linux systems take a long time to figure
// out that there is nothing listening on localhost. // out that there is nothing listening on localhost.
n = 100 n = 100
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build !plan9
package net package net
import ( import (
......
...@@ -14,6 +14,9 @@ import ( ...@@ -14,6 +14,9 @@ import (
"time" "time"
) )
// /sys/include/ape/sys/socket.h:/SOMAXCONN
var listenerBacklog = 5
// probeIPv6Stack returns two boolean values. If the first boolean value is // probeIPv6Stack returns two boolean values. If the first boolean value is
// true, kernel supports basic IPv6 functionality. If the second // true, kernel supports basic IPv6 functionality. If the second
// boolean value is true, kernel supports IPv6 IPv4-mapping. // boolean value is true, kernel supports IPv6 IPv4-mapping.
...@@ -48,6 +51,7 @@ func readPlan9Addr(proto, filename string) (addr Addr, err error) { ...@@ -48,6 +51,7 @@ func readPlan9Addr(proto, filename string) (addr Addr, err error) {
if err != nil { if err != nil {
return return
} }
defer f.Close()
n, err := f.Read(buf[:]) n, err := f.Read(buf[:])
if err != nil { if err != nil {
return return
...@@ -192,6 +196,7 @@ func startPlan9(net string, addr Addr) (ctl *os.File, dest, proto, name string, ...@@ -192,6 +196,7 @@ func startPlan9(net string, addr Addr) (ctl *os.File, dest, proto, name string,
var buf [16]byte var buf [16]byte
n, err := f.Read(buf[:]) n, err := f.Read(buf[:])
if err != nil { if err != nil {
f.Close()
return return
} }
return f, dest, proto, string(buf[:n]), nil return f, dest, proto, string(buf[:n]), nil
...@@ -204,14 +209,17 @@ func dialPlan9(net string, laddr, raddr Addr) (c *plan9Conn, err error) { ...@@ -204,14 +209,17 @@ func dialPlan9(net string, laddr, raddr Addr) (c *plan9Conn, err error) {
} }
_, err = f.WriteString("connect " + dest) _, err = f.WriteString("connect " + dest)
if err != nil { if err != nil {
f.Close()
return return
} }
laddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/local") laddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/local")
if err != nil { if err != nil {
f.Close()
return return
} }
raddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/remote") raddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/remote")
if err != nil { if err != nil {
f.Close()
return return
} }
return newPlan9Conn(proto, name, f, laddr, raddr), nil return newPlan9Conn(proto, name, f, laddr, raddr), nil
...@@ -230,10 +238,12 @@ func listenPlan9(net string, laddr Addr) (l *plan9Listener, err error) { ...@@ -230,10 +238,12 @@ func listenPlan9(net string, laddr Addr) (l *plan9Listener, err error) {
} }
_, err = f.WriteString("announce " + dest) _, err = f.WriteString("announce " + dest)
if err != nil { if err != nil {
f.Close()
return return
} }
laddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/local") laddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/local")
if err != nil { if err != nil {
f.Close()
return return
} }
l = new(plan9Listener) l = new(plan9Listener)
...@@ -257,15 +267,18 @@ func (l *plan9Listener) acceptPlan9() (c *plan9Conn, err error) { ...@@ -257,15 +267,18 @@ func (l *plan9Listener) acceptPlan9() (c *plan9Conn, err error) {
var buf [16]byte var buf [16]byte
n, err := f.Read(buf[:]) n, err := f.Read(buf[:])
if err != nil { if err != nil {
f.Close()
return return
} }
name := string(buf[:n]) name := string(buf[:n])
laddr, err := readPlan9Addr(l.proto, l.dir+"/local") laddr, err := readPlan9Addr(l.proto, l.dir+"/local")
if err != nil { if err != nil {
f.Close()
return return
} }
raddr, err := readPlan9Addr(l.proto, l.dir+"/remote") raddr, err := readPlan9Addr(l.proto, l.dir+"/remote")
if err != nil { if err != nil {
f.Close()
return return
} }
return newPlan9Conn(l.proto, name, f, laddr, raddr), nil return newPlan9Conn(l.proto, name, f, laddr, raddr), nil
...@@ -287,3 +300,9 @@ func (l *plan9Listener) Close() error { ...@@ -287,3 +300,9 @@ func (l *plan9Listener) Close() error {
} }
func (l *plan9Listener) Addr() Addr { return l.laddr } func (l *plan9Listener) Addr() Addr { return l.laddr }
// SetDeadline sets the deadline associated with the listener.
// A zero time value disables the deadline.
func (l *plan9Listener) SetDeadline(t time.Time) error {
return syscall.EPLAN9
}
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build !plan9
package net package net
import ( import (
......
...@@ -143,6 +143,11 @@ func TestTCPListenClose(t *testing.T) { ...@@ -143,6 +143,11 @@ func TestTCPListenClose(t *testing.T) {
} }
func TestUDPListenClose(t *testing.T) { func TestUDPListenClose(t *testing.T) {
switch runtime.GOOS {
case "plan9":
t.Logf("skipping test on %q", runtime.GOOS)
return
}
ln, err := ListenPacket("udp", "127.0.0.1:0") ln, err := ListenPacket("udp", "127.0.0.1:0")
if err != nil { if err != nil {
t.Fatalf("Listen failed: %v", err) t.Fatalf("Listen failed: %v", err)
......
...@@ -6,10 +6,7 @@ ...@@ -6,10 +6,7 @@
package net package net
import ( import "syscall"
"syscall"
"time"
)
// TCPConn is an implementation of the Conn interface // TCPConn is an implementation of the Conn interface
// for TCP network connections. // for TCP network connections.
...@@ -17,21 +14,6 @@ type TCPConn struct { ...@@ -17,21 +14,6 @@ type TCPConn struct {
plan9Conn plan9Conn
} }
// SetDeadline implements the Conn SetDeadline method.
func (c *TCPConn) SetDeadline(t time.Time) error {
return syscall.EPLAN9
}
// SetReadDeadline implements the Conn SetReadDeadline method.
func (c *TCPConn) SetReadDeadline(t time.Time) error {
return syscall.EPLAN9
}
// SetWriteDeadline implements the Conn SetWriteDeadline method.
func (c *TCPConn) SetWriteDeadline(t time.Time) error {
return syscall.EPLAN9
}
// CloseRead shuts down the reading side of the TCP connection. // CloseRead shuts down the reading side of the TCP connection.
// Most callers should just use Close. // Most callers should just use Close.
func (c *TCPConn) CloseRead() error { func (c *TCPConn) CloseRead() error {
...@@ -76,6 +58,17 @@ type TCPListener struct { ...@@ -76,6 +58,17 @@ type TCPListener struct {
plan9Listener plan9Listener
} }
func (l *TCPListener) Close() error {
if l == nil || l.ctl == nil {
return syscall.EINVAL
}
if _, err := l.ctl.WriteString("hangup"); err != nil {
l.ctl.Close()
return err
}
return l.ctl.Close()
}
// ListenTCP announces on the TCP address laddr and returns a TCP listener. // ListenTCP announces on the TCP address laddr and returns a TCP listener.
// Net must be "tcp", "tcp4", or "tcp6". // Net must be "tcp", "tcp4", or "tcp6".
// If laddr has a port of 0, it means to listen on some available port. // If laddr has a port of 0, it means to listen on some available port.
......
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
package net package net
import "errors"
var ErrWriteToConnected = errors.New("use of WriteTo with pre-connected UDP")
// UDPAddr represents the address of a UDP end point. // UDPAddr represents the address of a UDP end point.
type UDPAddr struct { type UDPAddr struct {
IP IP IP IP
......
...@@ -10,7 +10,6 @@ import ( ...@@ -10,7 +10,6 @@ import (
"errors" "errors"
"os" "os"
"syscall" "syscall"
"time"
) )
// UDPConn is the implementation of the Conn and PacketConn // UDPConn is the implementation of the Conn and PacketConn
...@@ -19,21 +18,6 @@ type UDPConn struct { ...@@ -19,21 +18,6 @@ type UDPConn struct {
plan9Conn plan9Conn
} }
// SetDeadline implements the Conn SetDeadline method.
func (c *UDPConn) SetDeadline(t time.Time) error {
return syscall.EPLAN9
}
// SetReadDeadline implements the Conn SetReadDeadline method.
func (c *UDPConn) SetReadDeadline(t time.Time) error {
return syscall.EPLAN9
}
// SetWriteDeadline implements the Conn SetWriteDeadline method.
func (c *UDPConn) SetWriteDeadline(t time.Time) error {
return syscall.EPLAN9
}
// UDP-specific methods. // UDP-specific methods.
// ReadFromUDP reads a UDP packet from c, copying the payload into b. // ReadFromUDP reads a UDP packet from c, copying the payload into b.
......
...@@ -8,12 +8,7 @@ ...@@ -8,12 +8,7 @@
package net package net
import ( import "syscall"
"errors"
"syscall"
)
var ErrWriteToConnected = errors.New("use of WriteTo with pre-connected UDP")
func sockaddrToUDP(sa syscall.Sockaddr) Addr { func sockaddrToUDP(sa syscall.Sockaddr) Addr {
switch sa := sa.(type) { switch sa := sa.(type) {
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build !plan9
package net package net
import ( import (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment