// 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
}
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.
import (
"errors"
+ "io"
"os"
"syscall"
"time"
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)
+}
package net
import (
- "io"
"syscall"
"time"
)
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)
-}
// 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.
// 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)
}
}
// 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
}
// 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()
}
// 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
}
// 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)
}
// 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
// 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).