net

package
v0.0.0-...-f8c0f81 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2011 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package net provides a portable interface to Unix networks sockets, including TCP/IP, UDP, domain name resolution, and Unix domain sockets.

Index

Constants

View Source
const (
	IPv4len = 4
	IPv6len = 16
)

IP address lengths (bytes).

Variables

View Source
var (
	IPv4bcast     = IPv4(255, 255, 255, 255) // broadcast
	IPv4allsys    = IPv4(224, 0, 0, 1)       // all systems
	IPv4allrouter = IPv4(224, 0, 0, 2)       // all routers
	IPv4zero      = IPv4(0, 0, 0, 0)         // all zeros
)

Well-known IPv4 addresses

View Source
var (
	IPv6zero                   = IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
	IPv6unspecified            = IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
	IPv6loopback               = IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
	IPv6interfacelocalallnodes = IP{0xff, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01}
	IPv6linklocalallnodes      = IP{0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01}
	IPv6linklocalallrouters    = IP{0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x02}
)

Well-known IPv6 addresses

Functions

func JoinHostPort

func JoinHostPort(host, port string) string

JoinHostPort combines host and port into a network address of the form "host:port" or, if host contains a colon, "[host]:port".

func LookupAddr

func LookupAddr(addr string) (name []string, err os.Error)

LookupAddr performs a reverse lookup for the given address, returning a list of names mapping to that address.

func LookupCNAME

func LookupCNAME(name string) (cname string, err os.Error)

LookupCNAME returns the canonical DNS host for the given name. Callers that do not care about the canonical name can call LookupHost or LookupIP directly; both take care of resolving the canonical name as part of the lookup.

func LookupHost

func LookupHost(host string) (addrs []string, err os.Error)

LookupHost looks up the given host using the local resolver. It returns an array of that host's addresses.

func LookupPort

func LookupPort(network, service string) (port int, err os.Error)

LookupPort looks up the port for the given network and service.

func ParseCIDR

func ParseCIDR(s string) (ip IP, mask IPMask, err os.Error)

ParseCIDR parses s as a CIDR notation IP address and mask, like "192.168.100.1/24", "2001:DB8::/48", as defined in RFC 4632 and RFC 4291.

func Pipe

func Pipe() (Conn, Conn)

Pipe creates a synchronous, in-memory, full duplex network connection; both ends implement the Conn interface. Reads on one end are matched with writes on the other, copying data directly between the two; there is no internal buffering.

func SplitHostPort

func SplitHostPort(hostport string) (host, port string, err os.Error)

SplitHostPort splits a network address of the form "host:port" or "[host]:port" into host and port. The latter form must be used when host contains a colon.

Types

type Addr

type Addr interface {
	Network() string // name of the network
	String() string  // string form of address
}

Addr represents a network end point address.

func InterfaceAddrs

func InterfaceAddrs() ([]Addr, os.Error)

InterfaceAddrs returns a list of the system's network interface addresses.

type AddrError

type AddrError struct {
	Error string
	Addr  string
}

func (*AddrError) String

func (e *AddrError) String() string

func (*AddrError) Temporary

func (e *AddrError) Temporary() bool

func (*AddrError) Timeout

func (e *AddrError) Timeout() bool

type Conn

type Conn interface {
	// Read reads data from the connection.
	// Read can be made to time out and return a net.Error with Timeout() == true
	// after a fixed time limit; see SetTimeout and SetReadTimeout.
	Read(b []byte) (n int, err os.Error)

	// Write writes data to the connection.
	// Write can be made to time out and return a net.Error with Timeout() == true
	// after a fixed time limit; see SetTimeout and SetWriteTimeout.
	Write(b []byte) (n int, err os.Error)

	// Close closes the connection.
	Close() os.Error

	// LocalAddr returns the local network address.
	LocalAddr() Addr

	// RemoteAddr returns the remote network address.
	RemoteAddr() Addr

	// SetTimeout sets the read and write deadlines associated
	// with the connection.
	SetTimeout(nsec int64) os.Error

	// SetReadTimeout sets the time (in nanoseconds) that
	// Read will wait for data before returning an error with Timeout() == true.
	// Setting nsec == 0 (the default) disables the deadline.
	SetReadTimeout(nsec int64) os.Error

	// SetWriteTimeout sets the time (in nanoseconds) that
	// Write will wait to send its data before returning an error with Timeout() == true.
	// Setting nsec == 0 (the default) disables the deadline.
	// Even if write times out, it may return n > 0, indicating that
	// some of the data was successfully written.
	SetWriteTimeout(nsec int64) os.Error
}

Conn is a generic stream-oriented network connection.

func Dial

func Dial(net, addr string) (c Conn, err os.Error)

Dial connects to the address addr on the network net.

Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4" (IPv4-only), "ip6" (IPv6-only), "unix" and "unixgram".

For IP networks, addresses have the form host:port. If host is a literal IPv6 address, it must be enclosed in square brackets. The functions JoinHostPort and SplitHostPort manipulate addresses in this form.

Examples:

Dial("tcp", "12.34.56.78:80")
Dial("tcp", "google.com:80")
Dial("tcp", "[de:ad:be:ef::ca:fe]:80")

func FileConn

func FileConn(f *os.File) (c Conn, err os.Error)

FileConn returns a copy of the network connection corresponding to the open file f. It is the caller's responsibility to close f when finished. Closing c does not affect f, and closing f does not affect c.

type DNSConfigError

type DNSConfigError struct {
	Error os.Error
}

func (*DNSConfigError) String

func (e *DNSConfigError) String() string

func (*DNSConfigError) Temporary

func (e *DNSConfigError) Temporary() bool

func (*DNSConfigError) Timeout

func (e *DNSConfigError) Timeout() bool

type DNSError

type DNSError struct {
	Error     string // description of the error
	Name      string // name looked for
	Server    string // server used
	IsTimeout bool
}

DNSError represents a DNS lookup error.

func (*DNSError) String

func (e *DNSError) String() string

func (*DNSError) Temporary

func (e *DNSError) Temporary() bool

func (*DNSError) Timeout

func (e *DNSError) Timeout() bool

type Error

type Error interface {
	os.Error
	Timeout() bool   // Is the error a timeout?
	Temporary() bool // Is the error temporary?
}

An Error represents a network error.

type Flags

type Flags uint
const (
	FlagUp           Flags = 1 << iota // interface is up
	FlagBroadcast                      // interface supports broadcast access capability
	FlagLoopback                       // interface is a loopback interface
	FlagPointToPoint                   // interface belongs to a point-to-point link
	FlagMulticast                      // interface supports multicast access capability
)

func (Flags) String

func (f Flags) String() string

type HardwareAddr

type HardwareAddr []byte

A HardwareAddr represents a physical hardware address.

func ParseMAC

func ParseMAC(s string) (hw HardwareAddr, err os.Error)

ParseMAC parses s as an IEEE 802 MAC-48, EUI-48, or EUI-64 using one of the following formats:

01:23:45:67:89:ab
01:23:45:67:89:ab:cd:ef
01-23-45-67-89-ab
01-23-45-67-89-ab-cd-ef
0123.4567.89ab
0123.4567.89ab.cdef

func (HardwareAddr) String

func (a HardwareAddr) String() string

type IP

type IP []byte

An IP is a single IP address, an array of bytes. Functions in this package accept either 4-byte (IP v4) or 16-byte (IP v6) arrays as input. Unless otherwise specified, functions in this package always return IP addresses in 16-byte form using the canonical embedding.

Note that in this documentation, referring to an IP address as an IPv4 address or an IPv6 address is a semantic property of the address, not just the length of the byte array: a 16-byte array can still be an IPv4 address.

func IPv4

func IPv4(a, b, c, d byte) IP

IPv4 returns the IP address (in 16-byte form) of the IPv4 address a.b.c.d.

func LookupIP

func LookupIP(host string) (addrs []IP, err os.Error)

LookupIP looks up host using the local resolver. It returns an array of that host's IPv4 and IPv6 addresses.

func ParseIP

func ParseIP(s string) IP

ParseIP parses s as an IP address, returning the result. The string s can be in dotted decimal ("74.125.19.99") or IPv6 ("2001:4860:0:2001::68") form. If s is not a valid textual representation of an IP address, ParseIP returns nil.

func (IP) DefaultMask

func (ip IP) DefaultMask() IPMask

DefaultMask returns the default IP mask for the IP address ip. Only IPv4 addresses have default masks; DefaultMask returns nil if ip is not a valid IPv4 address.

func (IP) Equal

func (ip IP) Equal(x IP) bool

Equal returns true if ip and x are the same IP address. An IPv4 address and that same address in IPv6 form are considered to be equal.

func (IP) IsGlobalUnicast

func (ip IP) IsGlobalUnicast() bool

IsGlobalUnicast returns true if ip is a global unicast address.

func (IP) IsInterfaceLocalMulticast

func (ip IP) IsInterfaceLocalMulticast() bool

IsInterfaceLinkLocalMulticast returns true if ip is an interface-local multicast address.

func (IP) IsLinkLocalMulticast

func (ip IP) IsLinkLocalMulticast() bool

IsLinkLocalMulticast returns true if ip is a link-local multicast address.

func (IP) IsLinkLocalUnicast

func (ip IP) IsLinkLocalUnicast() bool

IsLinkLocalUnicast returns true if ip is a link-local unicast address.

func (IP) IsLoopback

func (ip IP) IsLoopback() bool

IsLoopback returns true if ip is a loopback address.

func (IP) IsMulticast

func (ip IP) IsMulticast() bool

IsMulticast returns true if ip is a multicast address.

func (IP) IsUnspecified

func (ip IP) IsUnspecified() bool

IsUnspecified returns true if ip is an unspecified address.

func (IP) Mask

func (ip IP) Mask(mask IPMask) IP

Mask returns the result of masking the IP address ip with mask.

func (IP) String

func (ip IP) String() string

String returns the string form of the IP address ip. If the address is an IPv4 address, the string representation is dotted decimal ("74.125.19.99"). Otherwise the representation is IPv6 ("2001:4860:0:2001::68").

func (IP) To16

func (ip IP) To16() IP

To16 converts the IP address ip to a 16-byte representation. If ip is not an IP address (it is the wrong length), To16 returns nil.

func (IP) To4

func (ip IP) To4() IP

To4 converts the IPv4 address ip to a 4-byte representation. If ip is not an IPv4 address, To4 returns nil.

type IPAddr

type IPAddr struct {
	IP IP
}

IPAddr represents the address of a IP end point.

func ResolveIPAddr

func ResolveIPAddr(net, addr string) (*IPAddr, os.Error)

ResolveIPAddr parses addr as a IP address and resolves domain names to numeric addresses on the network net, which must be "ip", "ip4" or "ip6". A literal IPv6 host address must be enclosed in square brackets, as in "[::]".

func (*IPAddr) Network

func (a *IPAddr) Network() string

Network returns the address's network name, "ip".

func (*IPAddr) String

func (a *IPAddr) String() string

type IPConn

type IPConn struct {
	// contains filtered or unexported fields
}

IPConn is the implementation of the Conn and PacketConn interfaces for IP network connections.

func DialIP

func DialIP(netProto string, laddr, raddr *IPAddr) (c *IPConn, err os.Error)

DialIP connects to the remote address raddr on the network net, which must be "ip", "ip4", or "ip6".

func ListenIP

func ListenIP(netProto string, laddr *IPAddr) (c *IPConn, err os.Error)

ListenIP listens for incoming IP packets addressed to the local address laddr. The returned connection c's ReadFrom and WriteTo methods can be used to receive and send IP packets with per-packet addressing.

func (*IPConn) BindToDevice

func (c *IPConn) BindToDevice(device string) os.Error

BindToDevice binds an IPConn to a network interface.

func (*IPConn) Close

func (c *IPConn) Close() os.Error

Close closes the IP connection.

func (*IPConn) LocalAddr

func (c *IPConn) LocalAddr() Addr

LocalAddr returns the local network address.

func (*IPConn) Read

func (c *IPConn) Read(b []byte) (n int, err os.Error)

Read implements the net.Conn Read method.

func (*IPConn) ReadFrom

func (c *IPConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error)

ReadFrom implements the net.PacketConn ReadFrom method.

func (*IPConn) ReadFromIP

func (c *IPConn) ReadFromIP(b []byte) (n int, addr *IPAddr, err os.Error)

ReadFromIP reads a IP packet from c, copying the payload into b. It returns the number of bytes copied into b and the return address that was on the packet.

ReadFromIP can be made to time out and return an error with Timeout() == true after a fixed time limit; see SetTimeout and SetReadTimeout.

func (*IPConn) RemoteAddr

func (c *IPConn) RemoteAddr() Addr

RemoteAddr returns the remote network address, a *IPAddr.

func (*IPConn) SetReadBuffer

func (c *IPConn) SetReadBuffer(bytes int) os.Error

SetReadBuffer sets the size of the operating system's receive buffer associated with the connection.

func (*IPConn) SetReadTimeout

func (c *IPConn) SetReadTimeout(nsec int64) os.Error

SetReadTimeout implements the net.Conn SetReadTimeout method.

func (*IPConn) SetTimeout

func (c *IPConn) SetTimeout(nsec int64) os.Error

SetTimeout implements the net.Conn SetTimeout method.

func (*IPConn) SetWriteBuffer

func (c *IPConn) SetWriteBuffer(bytes int) os.Error

SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.

func (*IPConn) SetWriteTimeout

func (c *IPConn) SetWriteTimeout(nsec int64) os.Error

SetWriteTimeout implements the net.Conn SetWriteTimeout method.

func (*IPConn) Write

func (c *IPConn) Write(b []byte) (n int, err os.Error)

Write implements the net.Conn Write method.

func (*IPConn) WriteTo

func (c *IPConn) WriteTo(b []byte, addr Addr) (n int, err os.Error)

WriteTo implements the net.PacketConn WriteTo method.

func (*IPConn) WriteToIP

func (c *IPConn) WriteToIP(b []byte, addr *IPAddr) (n int, err os.Error)

WriteToIP writes a IP packet to addr via c, copying the payload from b.

WriteToIP can be made to time out and return an error with Timeout() == true after a fixed time limit; see SetTimeout and SetWriteTimeout. On packet-oriented connections, write timeouts are rare.

type IPMask

type IPMask []byte

An IP mask is an IP address.

func IPv4Mask

func IPv4Mask(a, b, c, d byte) IPMask

IPv4Mask returns the IP mask (in 16-byte form) of the IPv4 mask a.b.c.d.

func (IPMask) String

func (mask IPMask) String() string

String returns the string representation of mask. If the mask is in the canonical form--ones followed by zeros--the string representation is just the decimal number of ones. If the mask is in a non-canonical form, it is formatted as an IP address.

type Interface

type Interface struct {
	Index        int          // positive integer that starts at one, zero is never used
	MTU          int          // maximum transmission unit
	Name         string       // e.g., "en0", "lo0", "eth0.100"
	HardwareAddr HardwareAddr // IEEE MAC-48, EUI-48 and EUI-64 form
	Flags        Flags        // e.g., FlagUp, FlagLoopback, FlagMulticast
}

Interface represents a mapping between network interface name and index. It also represents network interface facility information.

func InterfaceByIndex

func InterfaceByIndex(index int) (*Interface, os.Error)

InterfaceByIndex returns the interface specified by index.

func InterfaceByName

func InterfaceByName(name string) (*Interface, os.Error)

InterfaceByName returns the interface specified by name.

func Interfaces

func Interfaces() ([]Interface, os.Error)

Interfaces returns a list of the systems's network interfaces.

func (*Interface) Addrs

func (ifi *Interface) Addrs() ([]Addr, os.Error)

Addrs returns interface addresses for a specific interface.

func (*Interface) MulticastAddrs

func (ifi *Interface) MulticastAddrs() ([]Addr, os.Error)

MulticastAddrs returns multicast, joined group addresses for a specific interface.

type InvalidAddrError

type InvalidAddrError string

func (InvalidAddrError) String

func (e InvalidAddrError) String() string

func (InvalidAddrError) Temporary

func (e InvalidAddrError) Temporary() bool

func (InvalidAddrError) Timeout

func (e InvalidAddrError) Timeout() bool

type InvalidConnError

type InvalidConnError struct{}

func (*InvalidConnError) String

func (e *InvalidConnError) String() string

func (*InvalidConnError) Temporary

func (e *InvalidConnError) Temporary() bool

func (*InvalidConnError) Timeout

func (e *InvalidConnError) Timeout() bool

type Listener

type Listener interface {
	// Accept waits for and returns the next connection to the listener.
	Accept() (c Conn, err os.Error)

	// Close closes the listener.
	Close() os.Error

	// Addr returns the listener's network address.
	Addr() Addr
}

A Listener is a generic network listener for stream-oriented protocols.

func FileListener

func FileListener(f *os.File) (l Listener, err os.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.

func Listen

func Listen(net, laddr string) (l Listener, err os.Error)

Listen announces on the local network address laddr. The network string net must be a stream-oriented network: "tcp", "tcp4", "tcp6", or "unix", or "unixpacket".

type MX

type MX struct {
	Host string
	Pref uint16
}

An MX represents a single DNS MX record.

func LookupMX

func LookupMX(name string) (mx []*MX, err os.Error)

LookupMX returns the DNS MX records for the given domain name sorted by preference.

type OpError

type OpError struct {
	Op    string
	Net   string
	Addr  Addr
	Error os.Error
}

func (*OpError) String

func (e *OpError) String() string

func (*OpError) Temporary

func (e *OpError) Temporary() bool

func (*OpError) Timeout

func (e *OpError) Timeout() bool

type PacketConn

type PacketConn interface {
	// ReadFrom reads a packet from the connection,
	// copying the payload into b.  It returns the number of
	// bytes copied into b and the return address that
	// was on the packet.
	// ReadFrom can be made to time out and return
	// an error with Timeout() == true after a fixed time limit;
	// see SetTimeout and SetReadTimeout.
	ReadFrom(b []byte) (n int, addr Addr, err os.Error)

	// WriteTo writes a packet with payload b to addr.
	// WriteTo can be made to time out and return
	// an error with Timeout() == true after a fixed time limit;
	// see SetTimeout and SetWriteTimeout.
	// On packet-oriented connections, write timeouts are rare.
	WriteTo(b []byte, addr Addr) (n int, err os.Error)

	// Close closes the connection.
	Close() os.Error

	// LocalAddr returns the local network address.
	LocalAddr() Addr

	// SetTimeout sets the read and write deadlines associated
	// with the connection.
	SetTimeout(nsec int64) os.Error

	// SetReadTimeout sets the time (in nanoseconds) that
	// Read will wait for data before returning an error with Timeout() == true.
	// Setting nsec == 0 (the default) disables the deadline.
	SetReadTimeout(nsec int64) os.Error

	// SetWriteTimeout sets the time (in nanoseconds) that
	// Write will wait to send its data before returning an error with Timeout() == true.
	// Setting nsec == 0 (the default) disables the deadline.
	// Even if write times out, it may return n > 0, indicating that
	// some of the data was successfully written.
	SetWriteTimeout(nsec int64) os.Error
}

PacketConn is a generic packet-oriented network connection.

func FilePacketConn

func FilePacketConn(f *os.File) (c PacketConn, err os.Error)

FilePacketConn returns a copy of the packet network connection corresponding to the open file f. 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 ListenPacket

func ListenPacket(net, laddr string) (c PacketConn, err os.Error)

ListenPacket announces on the local network address laddr. The network string net must be a packet-oriented network: "udp", "udp4", "udp6", or "unixgram".

type ParseError

type ParseError struct {
	Type string
	Text string
}

A ParseError represents a malformed text string and the type of string that was expected.

func (*ParseError) String

func (e *ParseError) String() string

type SRV

type SRV struct {
	Target   string
	Port     uint16
	Priority uint16
	Weight   uint16
}

An SRV represents a single DNS SRV record.

func LookupSRV

func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err os.Error)

LookupSRV tries to resolve an SRV query of the given service, protocol, and domain name, as specified in RFC 2782. In most cases the proto argument can be the same as the corresponding Addr.Network(). The returned records are sorted by priority and randomized by weight within a priority.

type TCPAddr

type TCPAddr struct {
	IP   IP
	Port int
}

TCPAddr represents the address of a TCP end point.

func ResolveTCPAddr

func ResolveTCPAddr(net, addr string) (*TCPAddr, os.Error)

ResolveTCPAddr parses addr as a TCP address of the form host:port and resolves domain names or port names to numeric addresses on the network net, which must be "tcp", "tcp4" or "tcp6". A literal IPv6 host address must be enclosed in square brackets, as in "[::]:80".

func (*TCPAddr) Network

func (a *TCPAddr) Network() string

Network returns the address's network name, "tcp".

func (*TCPAddr) String

func (a *TCPAddr) String() string

type TCPConn

type TCPConn struct {
	// contains filtered or unexported fields
}

TCPConn is an implementation of the Conn interface for TCP network connections.

func DialTCP

func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err os.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 (*TCPConn) Close

func (c *TCPConn) Close() os.Error

Close closes the TCP connection.

func (*TCPConn) File

func (c *TCPConn) File() (f *os.File, err os.Error)

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 (*TCPConn) LocalAddr

func (c *TCPConn) LocalAddr() Addr

LocalAddr returns the local network address, a *TCPAddr.

func (*TCPConn) Read

func (c *TCPConn) Read(b []byte) (n int, err os.Error)

Read implements the net.Conn Read method.

func (*TCPConn) ReadFrom

func (c *TCPConn) ReadFrom(r io.Reader) (int64, os.Error)

ReadFrom implements the io.ReaderFrom ReadFrom method.

func (*TCPConn) RemoteAddr

func (c *TCPConn) RemoteAddr() Addr

RemoteAddr returns the remote network address, a *TCPAddr.

func (*TCPConn) SetKeepAlive

func (c *TCPConn) SetKeepAlive(keepalive bool) os.Error

SetKeepAlive sets whether the operating system should send keepalive messages on the connection.

func (*TCPConn) SetLinger

func (c *TCPConn) SetLinger(sec int) os.Error

SetLinger sets the behavior of Close() on a connection which still has data waiting to be sent or to be acknowledged.

If sec < 0 (the default), Close returns immediately and the operating system finishes sending the data in the background.

If sec == 0, Close returns immediately and the operating system discards any unsent or unacknowledged data.

If sec > 0, Close blocks for at most sec seconds waiting for data to be sent and acknowledged.

func (*TCPConn) SetNoDelay

func (c *TCPConn) SetNoDelay(noDelay bool) os.Error

SetNoDelay controls whether the operating system should delay packet transmission in hopes of sending fewer packets (Nagle's algorithm). The default is true (no delay), meaning that data is sent as soon as possible after a Write.

func (*TCPConn) SetReadBuffer

func (c *TCPConn) SetReadBuffer(bytes int) os.Error

SetReadBuffer sets the size of the operating system's receive buffer associated with the connection.

func (*TCPConn) SetReadTimeout

func (c *TCPConn) SetReadTimeout(nsec int64) os.Error

SetReadTimeout implements the net.Conn SetReadTimeout method.

func (*TCPConn) SetTimeout

func (c *TCPConn) SetTimeout(nsec int64) os.Error

SetTimeout implements the net.Conn SetTimeout method.

func (*TCPConn) SetWriteBuffer

func (c *TCPConn) SetWriteBuffer(bytes int) os.Error

SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.

func (*TCPConn) SetWriteTimeout

func (c *TCPConn) SetWriteTimeout(nsec int64) os.Error

SetWriteTimeout implements the net.Conn SetWriteTimeout method.

func (*TCPConn) Write

func (c *TCPConn) Write(b []byte) (n int, err os.Error)

Write implements the net.Conn Write method.

type TCPListener

type TCPListener struct {
	// contains filtered or unexported fields
}

TCPListener is a TCP network listener. Clients should typically use variables of type Listener instead of assuming TCP.

func ListenTCP

func ListenTCP(net string, laddr *TCPAddr) (l *TCPListener, err os.Error)

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. The caller can use l.Addr() to retrieve the chosen address.

func (*TCPListener) Accept

func (l *TCPListener) Accept() (c Conn, err os.Error)

Accept implements the Accept method in the Listener interface; it waits for the next call and returns a generic Conn.

func (*TCPListener) AcceptTCP

func (l *TCPListener) AcceptTCP() (c *TCPConn, err os.Error)

AcceptTCP accepts the next incoming call and returns the new connection and the remote address.

func (*TCPListener) Addr

func (l *TCPListener) Addr() Addr

Addr returns the listener's network address, a *TCPAddr.

func (*TCPListener) Close

func (l *TCPListener) Close() os.Error

Close stops listening on the TCP address. Already Accepted connections are not closed.

func (*TCPListener) File

func (l *TCPListener) File() (f *os.File, err os.Error)

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 (*TCPListener) SetTimeout

func (l *TCPListener) SetTimeout(nsec int64) os.Error

SetTimeout sets the deadline associated with the listener

type UDPAddr

type UDPAddr struct {
	IP   IP
	Port int
}

UDPAddr represents the address of a UDP end point.

func ResolveUDPAddr

func ResolveUDPAddr(net, addr string) (*UDPAddr, os.Error)

ResolveUDPAddr parses addr as a UDP address of the form host:port and resolves domain names or port names to numeric addresses on the network net, which must be "udp", "udp4" or "udp6". A literal IPv6 host address must be enclosed in square brackets, as in "[::]:80".

func (*UDPAddr) Network

func (a *UDPAddr) Network() string

Network returns the address's network name, "udp".

func (*UDPAddr) String

func (a *UDPAddr) String() string

type UDPConn

type UDPConn struct {
	// contains filtered or unexported fields
}

UDPConn is the implementation of the Conn and PacketConn interfaces for UDP network connections.

func DialUDP

func DialUDP(net string, laddr, raddr *UDPAddr) (c *UDPConn, err os.Error)

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 ListenUDP

func ListenUDP(net string, laddr *UDPAddr) (c *UDPConn, err os.Error)

ListenUDP listens for incoming UDP packets addressed to the local address laddr. The returned connection c's ReadFrom and WriteTo methods can be used to receive and send UDP packets with per-packet addressing.

func ListenUnixgram

func ListenUnixgram(net string, laddr *UnixAddr) (c *UDPConn, err os.Error)

ListenUnixgram listens for incoming Unix datagram packets addressed to the local address laddr. The returned connection c's ReadFrom and WriteTo methods can be used to receive and send UDP packets with per-packet addressing. The network net must be "unixgram".

func (*UDPConn) BindToDevice

func (c *UDPConn) BindToDevice(device string) os.Error

BindToDevice binds a UDPConn to a network interface.

func (*UDPConn) Close

func (c *UDPConn) Close() os.Error

Close closes the UDP connection.

func (*UDPConn) File

func (c *UDPConn) File() (f *os.File, err os.Error)

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 (*UDPConn) JoinGroup

func (c *UDPConn) JoinGroup(ifi *Interface, addr IP) os.Error

JoinGroup joins the IP multicast group named by addr on ifi, which specifies the interface to join. JoinGroup uses the default multicast interface if ifi is nil.

func (*UDPConn) LeaveGroup

func (c *UDPConn) LeaveGroup(ifi *Interface, addr IP) os.Error

LeaveGroup exits the IP multicast group named by addr on ifi.

func (*UDPConn) LocalAddr

func (c *UDPConn) LocalAddr() Addr

LocalAddr returns the local network address.

func (*UDPConn) Read

func (c *UDPConn) Read(b []byte) (n int, err os.Error)

Read implements the net.Conn Read method.

func (*UDPConn) ReadFrom

func (c *UDPConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error)

ReadFrom implements the net.PacketConn ReadFrom method.

func (*UDPConn) ReadFromUDP

func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err os.Error)

ReadFromUDP reads a UDP packet from c, copying the payload into b. It returns the number of bytes copied into b and the return address that was on the packet.

ReadFromUDP can be made to time out and return an error with Timeout() == true after a fixed time limit; see SetTimeout and SetReadTimeout.

func (*UDPConn) RemoteAddr

func (c *UDPConn) RemoteAddr() Addr

RemoteAddr returns the remote network address, a *UDPAddr.

func (*UDPConn) SetReadBuffer

func (c *UDPConn) SetReadBuffer(bytes int) os.Error

SetReadBuffer sets the size of the operating system's receive buffer associated with the connection.

func (*UDPConn) SetReadTimeout

func (c *UDPConn) SetReadTimeout(nsec int64) os.Error

SetReadTimeout implements the net.Conn SetReadTimeout method.

func (*UDPConn) SetTimeout

func (c *UDPConn) SetTimeout(nsec int64) os.Error

SetTimeout implements the net.Conn SetTimeout method.

func (*UDPConn) SetWriteBuffer

func (c *UDPConn) SetWriteBuffer(bytes int) os.Error

SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.

func (*UDPConn) SetWriteTimeout

func (c *UDPConn) SetWriteTimeout(nsec int64) os.Error

SetWriteTimeout implements the net.Conn SetWriteTimeout method.

func (*UDPConn) Write

func (c *UDPConn) Write(b []byte) (n int, err os.Error)

Write implements the net.Conn Write method.

func (*UDPConn) WriteTo

func (c *UDPConn) WriteTo(b []byte, addr Addr) (n int, err os.Error)

WriteTo implements the net.PacketConn WriteTo method.

func (*UDPConn) WriteToUDP

func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (n int, err os.Error)

WriteToUDP writes a UDP packet to addr via c, copying the payload from b.

WriteToUDP can be made to time out and return an error with Timeout() == true after a fixed time limit; see SetTimeout and SetWriteTimeout. On packet-oriented connections, write timeouts are rare.

type UnixAddr

type UnixAddr struct {
	Name string
	Net  string
}

UnixAddr represents the address of a Unix domain socket end point.

func ResolveUnixAddr

func ResolveUnixAddr(net, addr string) (*UnixAddr, os.Error)

ResolveUnixAddr parses addr as a Unix domain socket address. The string net gives the network name, "unix", "unixgram" or "unixpacket".

func (*UnixAddr) Network

func (a *UnixAddr) Network() string

Network returns the address's network name, "unix" or "unixgram".

func (*UnixAddr) String

func (a *UnixAddr) String() string

type UnixConn

type UnixConn struct {
	// contains filtered or unexported fields
}

UnixConn is an implementation of the Conn interface for connections to Unix domain sockets.

func DialUnix

func DialUnix(net string, laddr, raddr *UnixAddr) (c *UnixConn, err os.Error)

DialUnix connects to the remote address raddr on the network net, which must be "unix" or "unixgram". If laddr is not nil, it is used as the local address for the connection.

func (*UnixConn) Close

func (c *UnixConn) Close() os.Error

Close closes the Unix domain connection.

func (*UnixConn) File

func (c *UnixConn) File() (f *os.File, err os.Error)

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 (*UnixConn) LocalAddr

func (c *UnixConn) LocalAddr() Addr

LocalAddr returns the local network address, a *UnixAddr. Unlike in other protocols, LocalAddr is usually nil for dialed connections.

func (*UnixConn) Read

func (c *UnixConn) Read(b []byte) (n int, err os.Error)

Read implements the net.Conn Read method.

func (*UnixConn) ReadFrom

func (c *UnixConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error)

ReadFrom implements the net.PacketConn ReadFrom method.

func (*UnixConn) ReadFromUnix

func (c *UnixConn) ReadFromUnix(b []byte) (n int, addr *UnixAddr, err os.Error)

ReadFromUnix reads a packet from c, copying the payload into b. It returns the number of bytes copied into b and the return address that was on the packet.

ReadFromUnix can be made to time out and return an error with Timeout() == true after a fixed time limit; see SetTimeout and SetReadTimeout.

func (*UnixConn) ReadMsgUnix

func (c *UnixConn) ReadMsgUnix(b, oob []byte) (n, oobn, flags int, addr *UnixAddr, err os.Error)

func (*UnixConn) RemoteAddr

func (c *UnixConn) RemoteAddr() Addr

RemoteAddr returns the remote network address, a *UnixAddr. Unlike in other protocols, RemoteAddr is usually nil for connections accepted by a listener.

func (*UnixConn) SetReadBuffer

func (c *UnixConn) SetReadBuffer(bytes int) os.Error

SetReadBuffer sets the size of the operating system's receive buffer associated with the connection.

func (*UnixConn) SetReadTimeout

func (c *UnixConn) SetReadTimeout(nsec int64) os.Error

SetReadTimeout implements the net.Conn SetReadTimeout method.

func (*UnixConn) SetTimeout

func (c *UnixConn) SetTimeout(nsec int64) os.Error

SetTimeout implements the net.Conn SetTimeout method.

func (*UnixConn) SetWriteBuffer

func (c *UnixConn) SetWriteBuffer(bytes int) os.Error

SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.

func (*UnixConn) SetWriteTimeout

func (c *UnixConn) SetWriteTimeout(nsec int64) os.Error

SetWriteTimeout implements the net.Conn SetWriteTimeout method.

func (*UnixConn) Write

func (c *UnixConn) Write(b []byte) (n int, err os.Error)

Write implements the net.Conn Write method.

func (*UnixConn) WriteMsgUnix

func (c *UnixConn) WriteMsgUnix(b, oob []byte, addr *UnixAddr) (n, oobn int, err os.Error)

func (*UnixConn) WriteTo

func (c *UnixConn) WriteTo(b []byte, addr Addr) (n int, err os.Error)

WriteTo implements the net.PacketConn WriteTo method.

func (*UnixConn) WriteToUnix

func (c *UnixConn) WriteToUnix(b []byte, addr *UnixAddr) (n int, err os.Error)

WriteToUnix writes a packet to addr via c, copying the payload from b.

WriteToUnix can be made to time out and return an error with Timeout() == true after a fixed time limit; see SetTimeout and SetWriteTimeout. On packet-oriented connections, write timeouts are rare.

type UnixListener

type UnixListener struct {
	// contains filtered or unexported fields
}

UnixListener is a Unix domain socket listener. Clients should typically use variables of type Listener instead of assuming Unix domain sockets.

func ListenUnix

func ListenUnix(net string, laddr *UnixAddr) (l *UnixListener, err os.Error)

ListenUnix announces on the Unix domain socket laddr and returns a Unix listener. Net must be "unix" (stream sockets).

func (*UnixListener) Accept

func (l *UnixListener) Accept() (c Conn, err os.Error)

Accept implements the Accept method in the Listener interface; it waits for the next call and returns a generic Conn.

func (*UnixListener) AcceptUnix

func (l *UnixListener) AcceptUnix() (c *UnixConn, err os.Error)

AcceptUnix accepts the next incoming call and returns the new connection and the remote address.

func (*UnixListener) Addr

func (l *UnixListener) Addr() Addr

Addr returns the listener's network address.

func (*UnixListener) Close

func (l *UnixListener) Close() os.Error

Close stops listening on the Unix address. Already accepted connections are not closed.

func (*UnixListener) File

func (l *UnixListener) File() (f *os.File, err os.Error)

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 (*UnixListener) SetTimeout

func (l *UnixListener) SetTimeout(nsec int64) (err os.Error)

SetTimeout sets the deadline associated wuth the listener

type UnknownNetworkError

type UnknownNetworkError string

func (UnknownNetworkError) String

func (e UnknownNetworkError) String() string

func (UnknownNetworkError) Temporary

func (e UnknownNetworkError) Temporary() bool

func (UnknownNetworkError) Timeout

func (e UnknownNetworkError) Timeout() bool

type UnknownSocketError

type UnknownSocketError struct {
	// contains filtered or unexported fields
}

func (*UnknownSocketError) String

func (e *UnknownSocketError) String() string

Directories

Path Synopsis
Package dict implements the Dictionary Server Protocol as defined in RFC 2229.
Package dict implements the Dictionary Server Protocol as defined in RFC 2229.
Package textproto implements generic support for text-based request/response protocols in the style of HTTP, NNTP, and SMTP.
Package textproto implements generic support for text-based request/response protocols in the style of HTTP, NNTP, and SMTP.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL