]> Cypherpunks repositories - gostls13.git/commitdiff
net: update docs and sync API for Plan 9
authorAnthony Martin <ality@pbrane.org>
Fri, 30 Nov 2012 19:41:50 +0000 (11:41 -0800)
committerAnthony Martin <ality@pbrane.org>
Fri, 30 Nov 2012 19:41:50 +0000 (11:41 -0800)
R=golang-dev, dave, mikioh.mikioh, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/6674043

src/pkg/net/file_plan9.go
src/pkg/net/iprawsock_plan9.go
src/pkg/net/net.go
src/pkg/net/sock_posix.go
src/pkg/net/tcpsock_plan9.go
src/pkg/net/udpsock_plan9.go
src/pkg/net/unixsock_plan9.go

index 04f7ee0401b7f86a7fe0e6b71b00705aa00dffea..ae3ac156b9878d02dc23ada735475e07f4a7d67c 100644 (file)
@@ -19,8 +19,8 @@ func FileConn(f *os.File) (c Conn, err error) {
 
 // FileListener returns a copy of the network listener corresponding
 // to the open file f.  It is the caller's responsibility to close l
-// when finished.  Closing c does not affect l, and closing l does not
-// affect c.
+// when finished.  Closing l does not affect f, and closing f does not
+// affect l.
 func FileListener(f *os.File) (l Listener, err error) {
        return nil, syscall.EPLAN9
 }
index 9a28256251ef241a326a91eb0683fdb64b3b9047..88e3b2c60b5df4c825fd62079b7aadec8ffad45a 100644 (file)
@@ -7,74 +7,14 @@
 package net
 
 import (
-       "os"
        "syscall"
        "time"
 )
 
 // IPConn is the implementation of the Conn and PacketConn interfaces
 // for IP network connections.
-type IPConn bool
-
-// Implementation of the Conn interface - see Conn for documentation.
-
-// Read implements the Conn Read method.
-func (c *IPConn) Read(b []byte) (int, error) {
-       return 0, syscall.EPLAN9
-}
-
-// Write implements the Conn Write method.
-func (c *IPConn) Write(b []byte) (int, error) {
-       return 0, syscall.EPLAN9
-}
-
-// LocalAddr returns the local network address.
-func (c *IPConn) LocalAddr() Addr {
-       return nil
-}
-
-// RemoteAddr returns the remote network address.
-func (c *IPConn) RemoteAddr() Addr {
-       return nil
-}
-
-// SetDeadline implements the Conn SetDeadline method.
-func (c *IPConn) SetDeadline(t time.Time) error {
-       return syscall.EPLAN9
-}
-
-// SetReadDeadline implements the Conn SetReadDeadline method.
-func (c *IPConn) SetReadDeadline(t time.Time) error {
-       return syscall.EPLAN9
-}
-
-// SetWriteDeadline implements the Conn SetWriteDeadline method.
-func (c *IPConn) SetWriteDeadline(t time.Time) error {
-       return syscall.EPLAN9
-}
-
-// SetReadBuffer sets the size of the operating system's receive
-// buffer associated with the connection.
-func (c *IPConn) SetReadBuffer(bytes int) error {
-       return syscall.EPLAN9
-}
-
-// SetWriteBuffer sets the size of the operating system's transmit
-// buffer associated with the connection.
-func (c *IPConn) SetWriteBuffer(bytes int) error {
-       return syscall.EPLAN9
-}
-
-// File returns a copy of the underlying os.File, set to blocking
-// mode.  It is the caller's responsibility to close f when finished.
-// Closing c does not affect f, and closing f does not affect c.
-func (c *IPConn) File() (f *os.File, err error) {
-       return nil, syscall.EPLAN9
-}
-
-// Close closes the IP connection.
-func (c *IPConn) Close() error {
-       return syscall.EPLAN9
+type IPConn struct {
+       conn
 }
 
 // ReadFromIP reads an IP packet from c, copying the payload into b.
index feb92a2737d5623fc57c3997d044d1b79bd78eb8..9af0514908fcc10caeab2d2e193bca7d35d8d201 100644 (file)
@@ -44,6 +44,7 @@ package net
 
 import (
        "errors"
+       "io"
        "os"
        "syscall"
        "time"
@@ -363,3 +364,14 @@ func (e *DNSConfigError) Error() string {
 
 func (e *DNSConfigError) Timeout() bool   { return false }
 func (e *DNSConfigError) Temporary() bool { return false }
+
+type writerOnly struct {
+       io.Writer
+}
+
+// Fallback implementation of io.ReaderFrom's ReadFrom, when sendfile isn't
+// applicable.
+func genericReadFrom(w io.Writer, r io.Reader) (n int64, err error) {
+       // Use wrapper to hide existing r.ReadFrom from io.Copy.
+       return io.Copy(writerOnly{w}, r)
+}
index 78417fd2ee7f95547ec09a05b55102167fc6410b..ecaf71705e746d6f9cdc9200587456a35e200028 100644 (file)
@@ -9,7 +9,6 @@
 package net
 
 import (
-       "io"
        "syscall"
        "time"
 )
@@ -76,14 +75,3 @@ func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr,
        fd.setAddr(laddr, raddr)
        return fd, nil
 }
-
-type writerOnly struct {
-       io.Writer
-}
-
-// Fallback implementation of io.ReaderFrom's ReadFrom, when sendfile isn't
-// applicable.
-func genericReadFrom(w io.Writer, r io.Reader) (n int64, err error) {
-       // Use wrapper to hide existing r.ReadFrom from io.Copy.
-       return io.Copy(writerOnly{w}, r)
-}
index cec5bd2aa5ea3e0a3574f4bd67fa23e8acac8dfc..954c99a2d8191347f0adee34d07dd5e8822cdbbf 100644 (file)
@@ -25,7 +25,7 @@ func newTCPConn(fd *netFD) *TCPConn {
 
 // ReadFrom implements the io.ReaderFrom ReadFrom method.
 func (c *TCPConn) ReadFrom(r io.Reader) (int64, error) {
-       return 0, syscall.EPLAN9
+       return genericReadFrom(c, r)
 }
 
 // CloseRead shuts down the reading side of the TCP connection.
@@ -78,7 +78,7 @@ func (c *TCPConn) SetNoDelay(noDelay bool) error {
 // DialTCP connects to the remote address raddr on the network net,
 // which must be "tcp", "tcp4", or "tcp6".  If laddr is not nil, it is
 // used as the local address for the connection.
-func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err error) {
+func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) {
        return dialTCP(net, laddr, raddr, noDeadline)
 }
 
index 46d2de2380f42d9fd53108a99990406a397ba335..b9ade48bec97065fdb932b8c1f4205dc0023585d 100644 (file)
@@ -52,7 +52,7 @@ func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err error) {
 }
 
 // ReadFrom implements the PacketConn ReadFrom method.
-func (c *UDPConn) ReadFrom(b []byte) (n int, addr Addr, err error) {
+func (c *UDPConn) ReadFrom(b []byte) (int, Addr, error) {
        if !c.ok() {
                return 0, nil, syscall.EINVAL
        }
@@ -75,15 +75,16 @@ func (c *UDPConn) ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *UDPAddr,
 // Timeout() == true after a fixed time limit; see SetDeadline and
 // SetWriteDeadline.  On packet-oriented connections, write timeouts
 // are rare.
-func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (n int, err error) {
+func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (int, error) {
        if !c.ok() {
                return 0, syscall.EINVAL
        }
        if c.fd.data == nil {
-               c.fd.data, err = os.OpenFile(c.fd.dir+"/data", os.O_RDWR, 0)
+               f, err := os.OpenFile(c.fd.dir+"/data", os.O_RDWR, 0)
                if err != nil {
                        return 0, err
                }
+               c.fd.data = f
        }
        h := new(udpHeader)
        h.raddr = addr.IP.To16()
@@ -99,7 +100,7 @@ func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (n int, err error) {
 }
 
 // WriteTo implements the PacketConn WriteTo method.
-func (c *UDPConn) WriteTo(b []byte, addr Addr) (n int, err error) {
+func (c *UDPConn) WriteTo(b []byte, addr Addr) (int, error) {
        if !c.ok() {
                return 0, syscall.EINVAL
        }
@@ -120,7 +121,7 @@ func (c *UDPConn) WriteMsgUDP(b, oob []byte, addr *UDPAddr) (n, oobn int, err er
 // DialUDP connects to the remote address raddr on the network net,
 // which must be "udp", "udp4", or "udp6".  If laddr is not nil, it is
 // used as the local address for the connection.
-func DialUDP(net string, laddr, raddr *UDPAddr) (c *UDPConn, err error) {
+func DialUDP(net string, laddr, raddr *UDPAddr) (*UDPConn, error) {
        return dialUDP(net, laddr, raddr, noDeadline)
 }
 
index 342e26fce0239ba8d2533cbffb352c57f22714a3..f7be5d2e9ae0f5c4d45b3138ecaacd9c08d3a2ad 100644 (file)
@@ -14,67 +14,8 @@ import (
 
 // UnixConn is an implementation of the Conn interface for connections
 // to Unix domain sockets.
-type UnixConn bool
-
-// Implementation of the Conn interface - see Conn for documentation.
-
-// Read implements the Conn Read method.
-func (c *UnixConn) Read(b []byte) (int, error) {
-       return 0, syscall.EPLAN9
-}
-
-// Write implements the Conn Write method.
-func (c *UnixConn) Write(b []byte) (int, error) {
-       return 0, syscall.EPLAN9
-}
-
-// LocalAddr returns the local network address.
-func (c *UnixConn) LocalAddr() Addr {
-       return nil
-}
-
-// RemoteAddr returns the remote network address.
-func (c *UnixConn) RemoteAddr() Addr {
-       return nil
-}
-
-// SetDeadline implements the Conn SetDeadline method.
-func (c *UnixConn) SetDeadline(t time.Time) error {
-       return syscall.EPLAN9
-}
-
-// SetReadDeadline implements the Conn SetReadDeadline method.
-func (c *UnixConn) SetReadDeadline(t time.Time) error {
-       return syscall.EPLAN9
-}
-
-// SetWriteDeadline implements the Conn SetWriteDeadline method.
-func (c *UnixConn) SetWriteDeadline(t time.Time) error {
-       return syscall.EPLAN9
-}
-
-// SetReadBuffer sets the size of the operating system's receive
-// buffer associated with the connection.
-func (c *UnixConn) SetReadBuffer(bytes int) error {
-       return syscall.EPLAN9
-}
-
-// SetWriteBuffer sets the size of the operating system's transmit
-// buffer associated with the connection.
-func (c *UnixConn) SetWriteBuffer(bytes int) error {
-       return syscall.EPLAN9
-}
-
-// File returns a copy of the underlying os.File, set to blocking
-// mode.  It is the caller's responsibility to close f when finished.
-// Closing c does not affect f, and closing f does not affect c.
-func (c *UnixConn) File() (f *os.File, err error) {
-       return nil, syscall.EPLAN9
-}
-
-// Close closes the Unix domain connection.
-func (c *UnixConn) Close() error {
-       return syscall.EPLAN9
+type UnixConn struct {
+       conn
 }
 
 // ReadFromUnix reads a packet from c, copying the payload into b.  It
@@ -149,7 +90,7 @@ func dialUnix(net string, laddr, raddr *UnixAddr, deadline time.Time) (*UnixConn
 // UnixListener is a Unix domain socket listener.  Clients should
 // typically use variables of type Listener instead of assuming Unix
 // domain sockets.
-type UnixListener bool
+type UnixListener struct{}
 
 // ListenUnix announces on the Unix domain socket laddr and returns a
 // Unix listener.  Net must be "unix" (stream sockets).