]> Cypherpunks repositories - gostls13.git/commitdiff
net: pass tests on Plan 9 again
authorFazlul Shahriar <fshahriar@gmail.com>
Wed, 6 Jun 2012 22:38:56 +0000 (18:38 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 6 Jun 2012 22:38:56 +0000 (18:38 -0400)
R=golang-dev
CC=golang-dev
https://golang.org/cl/6280045

src/pkg/net/dial_test.go
src/pkg/net/ipraw_test.go
src/pkg/net/ipsock_plan9.go
src/pkg/net/multicast_test.go
src/pkg/net/net_test.go
src/pkg/net/tcpsock_plan9.go
src/pkg/net/udpsock.go
src/pkg/net/udpsock_plan9.go
src/pkg/net/udpsock_posix.go
src/pkg/net/unicast_test.go

index f64cc6c955adeac38de496173d66ea2cb6c325c4..09ff5e739a3364cc0c47b29e950a8be2ae1a6323 100644 (file)
@@ -130,7 +130,7 @@ func TestSelfConnect(t *testing.T) {
                n = 1000
        }
        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
                // out that there is nothing listening on localhost.
                n = 100
index 6136202727cfc70a4e5e4d1eea79564f1b670c1c..0a28827e330d38917c93af755fb2001a575b81a7 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build !plan9
+
 package net
 
 import (
index eab0bf3e899b5e291a9931884278ff80af25d787..1199e48678a3f9e134eb0323955d1350a81e28e0 100644 (file)
@@ -14,6 +14,9 @@ import (
        "time"
 )
 
+// /sys/include/ape/sys/socket.h:/SOMAXCONN
+var listenerBacklog = 5
+
 // probeIPv6Stack returns two boolean values.  If the first boolean value is
 // true, kernel supports basic IPv6 functionality.  If the second
 // boolean value is true, kernel supports IPv6 IPv4-mapping.
@@ -48,6 +51,7 @@ func readPlan9Addr(proto, filename string) (addr Addr, err error) {
        if err != nil {
                return
        }
+       defer f.Close()
        n, err := f.Read(buf[:])
        if err != nil {
                return
@@ -192,6 +196,7 @@ func startPlan9(net string, addr Addr) (ctl *os.File, dest, proto, name string,
        var buf [16]byte
        n, err := f.Read(buf[:])
        if err != nil {
+               f.Close()
                return
        }
        return f, dest, proto, string(buf[:n]), nil
@@ -204,14 +209,17 @@ func dialPlan9(net string, laddr, raddr Addr) (c *plan9Conn, err error) {
        }
        _, err = f.WriteString("connect " + dest)
        if err != nil {
+               f.Close()
                return
        }
        laddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/local")
        if err != nil {
+               f.Close()
                return
        }
        raddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/remote")
        if err != nil {
+               f.Close()
                return
        }
        return newPlan9Conn(proto, name, f, laddr, raddr), nil
@@ -230,10 +238,12 @@ func listenPlan9(net string, laddr Addr) (l *plan9Listener, err error) {
        }
        _, err = f.WriteString("announce " + dest)
        if err != nil {
+               f.Close()
                return
        }
        laddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/local")
        if err != nil {
+               f.Close()
                return
        }
        l = new(plan9Listener)
@@ -257,15 +267,18 @@ func (l *plan9Listener) acceptPlan9() (c *plan9Conn, err error) {
        var buf [16]byte
        n, err := f.Read(buf[:])
        if err != nil {
+               f.Close()
                return
        }
        name := string(buf[:n])
        laddr, err := readPlan9Addr(l.proto, l.dir+"/local")
        if err != nil {
+               f.Close()
                return
        }
        raddr, err := readPlan9Addr(l.proto, l.dir+"/remote")
        if err != nil {
+               f.Close()
                return
        }
        return newPlan9Conn(l.proto, name, f, laddr, raddr), nil
@@ -287,3 +300,9 @@ func (l *plan9Listener) Close() error {
 }
 
 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
+}
index 67261b1ee775dea2da9f5a9d95656c0034e32535..2c61dca549f730e743123752508bff5fbb363007 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build !plan9
+
 package net
 
 import (
index 8a299245dace2408cabf9e90354ce0b0e70ac3aa..623a788f9ab89df6223df92653f3eb6a4c6263cf 100644 (file)
@@ -143,6 +143,11 @@ func TestTCPListenClose(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")
        if err != nil {
                t.Fatalf("Listen failed: %v", err)
index 35f56966eae66336bcd84d01735cf0906d60626b..b225ca25dc3bcf58c4d29773a47701a37952d152 100644 (file)
@@ -6,10 +6,7 @@
 
 package net
 
-import (
-       "syscall"
-       "time"
-)
+import "syscall"
 
 // TCPConn is an implementation of the Conn interface
 // for TCP network connections.
@@ -17,21 +14,6 @@ type TCPConn struct {
        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.
 // Most callers should just use Close.
 func (c *TCPConn) CloseRead() error {
@@ -76,6 +58,17 @@ type TCPListener struct {
        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.
 // Net must be "tcp", "tcp4", or "tcp6".
 // If laddr has a port of 0, it means to listen on some available port.
index b3520cf09f3c21e464d67b3d580b2fe4b8e18e37..62b27d95e9c48390b686e27f670e6fcbef2931ed 100644 (file)
@@ -6,6 +6,10 @@
 
 package net
 
+import "errors"
+
+var ErrWriteToConnected = errors.New("use of WriteTo with pre-connected UDP")
+
 // UDPAddr represents the address of a UDP end point.
 type UDPAddr struct {
        IP   IP
index 4f298a42f878737bbfc0b6d4c694aeb08cf144fd..5ac0b4d263cbb2bc73e8254869cfa3c37d2dd09f 100644 (file)
@@ -10,7 +10,6 @@ import (
        "errors"
        "os"
        "syscall"
-       "time"
 )
 
 // UDPConn is the implementation of the Conn and PacketConn
@@ -19,21 +18,6 @@ type UDPConn struct {
        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.
 
 // ReadFromUDP reads a UDP packet from c, copying the payload into b.
index f29d570e1cf4196e89725dc058edbd5cd05a27cf..10e1e1cf2b9393b9fed62b7be994550850859b4c 100644 (file)
@@ -8,12 +8,7 @@
 
 package net
 
-import (
-       "errors"
-       "syscall"
-)
-
-var ErrWriteToConnected = errors.New("use of WriteTo with pre-connected UDP")
+import "syscall"
 
 func sockaddrToUDP(sa syscall.Sockaddr) Addr {
        switch sa := sa.(type) {
index 326e36195ef019d84eb93752a99f172be11afbc4..b2ac5dd458388cb90a4100e3ee18bb3026503056 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build !plan9
+
 package net
 
 import (