mirror of https://github.com/golang/go.git
net: update docs and sync API for Plan 9
R=golang-dev, dave, mikioh.mikioh, bradfitz, rsc CC=golang-dev https://golang.org/cl/6674043
This commit is contained in:
parent
279199ebcc
commit
253ed02918
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
|
|
|
|||
Loading…
Reference in New Issue