rwc

package
v0.12.5 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2023 License: Apache-2.0 Imports: 8 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 Conn added in v0.7.2

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

Conn implements a Conn with a buffered ReadWriteCloser.

func NewConn added in v0.7.2

func NewConn(
	ctx context.Context,
	rwc io.ReadWriteCloser,
	laddr, raddr net.Addr,
	bufferPacketN int,
) *Conn

NewConn constructs a new packet conn and starts the rx pump.

func (*Conn) Close added in v0.7.2

func (p *Conn) Close() error

Close closes the connection. Any blocked ReadFrom or WriteTo operations will be unblocked and return errors.

func (*Conn) LocalAddr added in v0.7.2

func (p *Conn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*Conn) Read added in v0.7.2

func (p *Conn) Read(b []byte) (n int, err error)

Read reads data from the connection. Read can be made to time out and return an error after a fixed time limit; see SetDeadline and SetReadDeadline.

func (*Conn) RemoteAddr added in v0.7.2

func (p *Conn) RemoteAddr() net.Addr

RemoteAddr returns the bound remote network address.

func (*Conn) SetDeadline added in v0.7.2

func (p *Conn) 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 (*Conn) SetReadDeadline added in v0.7.2

func (p *Conn) 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 (*Conn) SetWriteDeadline added in v0.7.2

func (p *Conn) 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 (*Conn) Write added in v0.7.2

func (p *Conn) Write(pkt []byte) (n int, err error)

Write writes data to the connection.

type ConnAddr added in v0.8.0

type ConnAddr struct {
	ConnAddrBase
	// contains filtered or unexported fields
}

ConnAddr overlays LocalAddr and RemoteAddr on a base Conn.

func NewConnAddr added in v0.8.0

func NewConnAddr(base ConnAddrBase, local, remote net.Addr) *ConnAddr

NewConnAddr constructs a new ConnAddr.

func (*ConnAddr) LocalAddr added in v0.8.0

func (c *ConnAddr) LocalAddr() net.Addr

LocalAddr returns the local network address, if known.

func (*ConnAddr) RemoteAddr added in v0.8.0

func (c *ConnAddr) RemoteAddr() net.Addr

RemoteAddr returns the remote network address, if known.

type ConnAddrBase added in v0.8.0

type ConnAddrBase interface {
	// Read can be made to time out and return an error after a fixed
	// time limit; see SetDeadline and SetReadDeadline.
	Read(b []byte) (n int, err error)

	// Write writes data to the connection.
	// Write can be made to time out and return an error after a fixed
	// time limit; see SetDeadline and SetWriteDeadline.
	Write(b []byte) (n int, err error)

	// Close closes the connection.
	// Any blocked Read or Write operations will be unblocked and return errors.
	Close() 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 Read or Write calls.
	//
	// A zero value for t means I/O operations will not time out.
	SetDeadline(t time.Time) error

	// SetReadDeadline sets the deadline for future Read calls
	// and any currently-blocked Read call.
	// A zero value for t means Read will not time out.
	SetReadDeadline(t time.Time) error

	// SetWriteDeadline sets the deadline for future Write calls
	// and any currently-blocked Write 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 Write will not time out.
	SetWriteDeadline(t time.Time) error
}

ConnAddrBase is the base type for ConnAddr.

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

type RwcOverlay added in v0.8.0

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

RwcOverlay overlays a io.ReadWriteCloser on a net.Conn.

func NewRwcOverlay added in v0.8.0

func NewRwcOverlay(rwc io.ReadWriteCloser, nc net.Conn) *RwcOverlay

NewRwcOverlay builds a ReadWriteCloser overlayed on a net.Conn.

func (*RwcOverlay) Close added in v0.8.0

func (r *RwcOverlay) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (*RwcOverlay) LocalAddr added in v0.8.0

func (r *RwcOverlay) LocalAddr() net.Addr

LocalAddr returns the local network address, if known.

func (*RwcOverlay) Read added in v0.8.0

func (r *RwcOverlay) Read(b []byte) (n int, err error)

Read reads data from the connection. Read can be made to time out and return an error after a fixed time limit; see SetDeadline and SetReadDeadline.

func (*RwcOverlay) RemoteAddr added in v0.8.0

func (r *RwcOverlay) RemoteAddr() net.Addr

RemoteAddr returns the remote network address, if known.

func (*RwcOverlay) SetDeadline added in v0.8.0

func (r *RwcOverlay) 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 Read or Write calls.

A zero value for t means I/O operations will not time out.

func (*RwcOverlay) SetReadDeadline added in v0.8.0

func (r *RwcOverlay) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out.

func (*RwcOverlay) SetWriteDeadline added in v0.8.0

func (r *RwcOverlay) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write 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 Write will not time out.

func (*RwcOverlay) Write added in v0.8.0

func (r *RwcOverlay) Write(b []byte) (n int, err error)

Write writes data to the connection. Write can be made to time out and return an error after a fixed time limit; see SetDeadline and SetWriteDeadline.

Jump to

Keyboard shortcuts

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