Documentation
¶
Index ¶
- func NewConnPair() (*Conn, *Conn)
- type Conn
- func (c *Conn) CanRead() bool
- func (c *Conn) Close() error
- func (c *Conn) CloseRead() error
- func (c *Conn) CloseWrite() error
- func (c *Conn) IsClosed() bool
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Peer() *Conn
- func (c *Conn) Read(b []byte) (n int, err error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetCloseError(err error)
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetLocalAddr(addr net.Addr)
- func (c *Conn) SetReadBufferSize(size int)
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetReadError(err error)
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) SetWriteError(err error)
- func (c *Conn) Write(b []byte) (n int, err error)
- type Listener
- func (li *Listener) Accept() (net.Conn, error)
- func (li *Listener) Addr() net.Addr
- func (li *Listener) Close() error
- func (li *Listener) NewConn() *Conn
- func (li *Listener) NewConnConfig(f func(*Conn)) *Conn
- func (li *Listener) SetAcceptError(err error)
- func (li *Listener) SetAddr(addr net.Addr)
- func (li *Listener) SetCloseError(err error)
- type PacketConn
- func (p *PacketConn) CanRead() bool
- func (p *PacketConn) Close() error
- func (p *PacketConn) IsClosed() bool
- func (p *PacketConn) LocalAddr() net.Addr
- func (p *PacketConn) ReadFrom(b []byte) (n int, addr net.Addr, err error)
- func (c *PacketConn) SetCloseError(err error)
- func (p *PacketConn) SetDeadline(t time.Time) error
- func (p *PacketConn) SetReadDeadline(t time.Time) error
- func (c *PacketConn) SetReadError(err error)
- func (p *PacketConn) SetWriteDeadline(t time.Time) error
- func (c *PacketConn) SetWriteError(err error)
- func (p *PacketConn) WriteTo(b []byte, addr net.Addr) (n int, err error)
- type PacketNet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is an in-memory test implementation of net.Conn.
func (*Conn) CloseWrite ¶
CloseWrite shuts down the writing side of the connection.
func (*Conn) IsClosed ¶
IsClosed reports whether the connection has been closed. A connection is closed if [CloseRead] and [CloseWrite] are both called, or if [Close] is called.
To identify when the other side of the Conn has been closed, use Conn.Peer().IsClosed().
func (*Conn) RemoteAddr ¶
LocalAddr returns the (fake) remote network address.
func (*Conn) SetCloseError ¶
SetCloseError sets the error returned by Close. Close still closes the connection. A nil error restores the usual behavior.
func (*Conn) SetDeadline ¶
SetDeadline sets the read and write deadlines for the connection.
func (*Conn) SetLocalAddr ¶
SetLocalAddr sets the local address.
To set the remote address, set the local address of Conn's peer.
func (*Conn) SetReadBufferSize ¶
SetReadBufferSize sets the connection's read buffer. Writes to the other end of the connection will block so long as the buffer is full. Setting the size to 0 blocks all writes until the size is increased.
func (*Conn) SetReadDeadline ¶
SetReadDeadline sets the read deadline for the connection.
func (*Conn) SetReadError ¶
SetReadError causes any currently blocked and future Read calls to return a net.OpError wrapping err. It does not affect the other half of the connection. Reads will return any buffered data before returning the error, including data written after the error is set and io.EOF after the other end is closed. A nil error restores the usual behavior.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline sets the write deadline for the connection.
func (*Conn) SetWriteError ¶
SetWriteError causes any currently blocked and future Write calls to return a net.OpError wrapping err. It does not affect the other half of the connection. Writes will not write data to the connection buffer while an error is set. A nil error restores the usual behavior.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener is an in-memory test implementation of net.Listener.
func (*Listener) Accept ¶
Accept waits for and returns the next connection to the listener.
The connections returned by Accept are always [*Conn]s.
func (*Listener) Addr ¶
Addr returns the listener's network address.
The address is always a *net.TCPAddr.
func (*Listener) Close ¶
Close closes the listener. Any blocked Accept operations will be unblocked and return errors.
func (*Listener) NewConn ¶
NewConn returns a new connection to the listener.
Accept will return the other side of the conn.
func (*Listener) NewConnConfig ¶
NewConnConfig returns a new connection to the listener.
The function f is called with the new client connection. After f returns, Accept will return the other side of the connection.
For example, to create a connection from a specific IP address:
conn := li.NewConnConfig(func(conn *nettest.Conn) {
conn.SetLocalAddr(net.TCPAddrFromAddrPort(netip.MustParseAddrPort("10.0.0.1:1234")))
})
func (*Listener) SetAcceptError ¶
SetAcceptError causes any currently blocked and future Accept calls to return a net.OpError wrapping err. Accept will return any available connections before returning the error, including connections created after the error is set. A nil error restores the usual behavior.
func (*Listener) SetCloseError ¶
SetCloseError sets the error returned by Close. Close still closes the listener. A nil error restores the usual behavior.
type PacketConn ¶
type PacketConn struct {
// contains filtered or unexported fields
}
func (*PacketConn) CanRead ¶
func (p *PacketConn) CanRead() bool
CanRead reports whether [ReadFrom] can return at least one byte or an error. If [ReadFrom] would block, CanRead returns false.
func (*PacketConn) IsClosed ¶
func (p *PacketConn) IsClosed() bool
IsClosed reports whether the connection has been closed.
func (*PacketConn) LocalAddr ¶
func (p *PacketConn) LocalAddr() net.Addr
LocalAddr returns the (fake) local network address.
func (*PacketConn) ReadFrom ¶
ReadFrom reads a packet from the connection, copying the payload into b.
func (*PacketConn) SetCloseError ¶
func (c *PacketConn) SetCloseError(err error)
SetCloseError sets the error returned by Close. Close still closes the connection. A nil error restores the usual behavior.
func (*PacketConn) SetDeadline ¶
func (p *PacketConn) SetDeadline(t time.Time) error
SetReadDeadline sets the read deadline for the connection. PacketConns have no write deadline.
func (*PacketConn) SetReadDeadline ¶
func (p *PacketConn) SetReadDeadline(t time.Time) error
SetReadDeadline sets the read deadline for the connection.
func (*PacketConn) SetReadError ¶
func (c *PacketConn) SetReadError(err error)
SetReadError causes any currently blocked and future ReadFrom calls to return a net.OpError wrapping err. It does not affect the other half of the connection. Reads will return any buffered data before returning the error, including data written after the error is set. A nil error restores the usual behavior.
func (*PacketConn) SetWriteDeadline ¶
func (p *PacketConn) SetWriteDeadline(t time.Time) error
SetWriteDeadline has no effect. Writes to PacketConns never block.
func (*PacketConn) SetWriteError ¶
func (c *PacketConn) SetWriteError(err error)
SetWriteError causes any currently blocked and future WriteTo calls to return a net.OpError wrapping err. It does not affect the other half of the connection. Writes will not write data while an error is set. A nil error restores the usual behavior.
func (*PacketConn) WriteTo ¶
WriteTo writes a packet with payload b to addr. addr must be a *net.UDPAddr.
WriteTo appends the packet to the recipient's receive buffer. If no recipient is listening on addr or if the recipient's receive buffer is full, the packet is silently discarded.
type PacketNet ¶
type PacketNet struct {
// contains filtered or unexported fields
}
A PacketNet is a group of communicating [PacketConn]s.
func (*PacketNet) NewConn ¶
func (n *PacketNet) NewConn(a net.Addr) (*PacketConn, error)
NewConn returns a new PacketConn listening on the given address. It returns an error if there is an existing listener on this address.