Documentation
¶
Index ¶
- func NewReadWriteCloser(reader io.ReadCloser, writer io.WriteCloser) io.ReadWriteCloser
- type PacketConn
- func (p *PacketConn) Close() error
- func (p *PacketConn) LocalAddr() net.Addr
- func (p *PacketConn) ReadFrom(pk []byte) (n int, addr net.Addr, err error)
- func (p *PacketConn) RemoteAddr() net.Addr
- func (p *PacketConn) SetDeadline(t time.Time) error
- func (p *PacketConn) SetReadDeadline(t time.Time) error
- func (p *PacketConn) SetWriteDeadline(t time.Time) error
- func (p *PacketConn) WriteTo(pkt []byte, addr net.Addr) (n int, err error)
- type ReadWriteCloser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewReadWriteCloser ¶
func NewReadWriteCloser( reader io.ReadCloser, writer io.WriteCloser, ) io.ReadWriteCloser
NewReadWriteCloser builds a new ReadWriteCloser.
Types ¶
type PacketConn ¶
type PacketConn struct {
// contains filtered or unexported fields
}
PacketConn implements a PacketConn with a Read-Write-Closer.
Writes a little-endian 4 byte length prefix before each packet. All messages sent to/from the wrong addresses are dropped.
func NewPacketConn ¶
func NewPacketConn( ctx context.Context, rwc io.ReadWriteCloser, laddr, raddr net.Addr, maxPacketSize uint32, bufferPacketN int, ) *PacketConn
NewPacketConn constructs a new packet conn and starts the rx pump.
func (*PacketConn) Close ¶
func (p *PacketConn) Close() error
Close closes the connection. Any blocked ReadFrom or WriteTo operations will be unblocked and return errors.
func (*PacketConn) LocalAddr ¶
func (p *PacketConn) LocalAddr() net.Addr
LocalAddr returns the local network address.
func (*PacketConn) ReadFrom ¶
ReadFrom reads a packet from the connection, copying the payload into p. It returns the number of bytes copied into p and the return address that was on the packet. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered. Callers should always process the n > 0 bytes returned before considering the error err. ReadFrom can be made to time out and return an error after a fixed time limit; see SetDeadline and SetReadDeadline.
func (*PacketConn) RemoteAddr ¶
func (p *PacketConn) RemoteAddr() net.Addr
RemoteAddr returns the bound remote network address.
func (*PacketConn) SetDeadline ¶
func (p *PacketConn) SetDeadline(t time.Time) error
SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.
A deadline is an absolute time after which I/O operations fail instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.
If the deadline is exceeded a call to Read or Write or to other I/O methods will return an error that wraps os.ErrDeadlineExceeded. This can be tested using errors.Is(err, os.ErrDeadlineExceeded). The error's Timeout method will return true, but note that there are other possible errors for which the Timeout method will return true even if the deadline has not been exceeded.
An idle timeout can be implemented by repeatedly extending the deadline after successful ReadFrom or WriteTo calls.
A zero value for t means I/O operations will not time out.
func (*PacketConn) SetReadDeadline ¶
func (p *PacketConn) SetReadDeadline(t time.Time) error
SetReadDeadline sets the deadline for future ReadFrom calls and any currently-blocked ReadFrom call. A zero value for t means ReadFrom will not time out.
func (*PacketConn) SetWriteDeadline ¶
func (p *PacketConn) SetWriteDeadline(t time.Time) error
SetWriteDeadline sets the deadline for future WriteTo calls and any currently-blocked WriteTo call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means WriteTo will not time out.
type ReadWriteCloser ¶
type ReadWriteCloser struct {
// contains filtered or unexported fields
}
ReadWriteCloser implements ReadWriteCloser with a Reader and Writer.