rwc

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

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

func (p *PacketConn) ReadFrom(pk []byte) (n int, addr net.Addr, err error)

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.

func (*PacketConn) WriteTo

func (p *PacketConn) WriteTo(pkt []byte, addr net.Addr) (n int, err error)

WriteTo writes a packet with payload p to addr. WriteTo can be made to time out and return an Error after a fixed time limit; see SetDeadline and SetWriteDeadline. On packet-oriented connections, write timeouts are rare.

type ReadWriteCloser

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

ReadWriteCloser implements ReadWriteCloser with a Reader and Writer.

func (*ReadWriteCloser) Close

func (r *ReadWriteCloser) Close() error

Close closes both streams.

func (*ReadWriteCloser) Read

func (r *ReadWriteCloser) Read(p []byte) (n int, err error)

Read implements io.Reader

func (*ReadWriteCloser) Write

func (r *ReadWriteCloser) Write(p []byte) (n int, err error)

Write implements io.Writer

Jump to

Keyboard shortcuts

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