Documentation ¶
Overview ¶
package rpt (Reliable Packet Transport) implements a simple packet-oriented protocol with ACKs on top of net.PacketConn.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RPT ¶
type RPT struct {
// contains filtered or unexported fields
}
RPT (Reliable Packet Transport) implements a simple packet-oriented protocol with ACKs on top of net.PacketConn.
Two sending primitives are available:
SendUnreliableMsgTo sends a message and returns without waiting for an ACK.
SendMsgTo sends a message and waits for a limited amount of time for an ACK; if time allows, also resends the message. Once the parent context is canceled, the function returns immediately with an error.
Header format:
0B 1 2 3 4 5 6 7 +--------+--------+--------+--------+--------+--------+--------+--------+ | Flags | PacketID | +--------+--------+--------+--------+--------+--------+--------+--------+
RPT can be safely used by concurrent goroutines.
All methods receive a context argument. If the context is canceled prior to completing work, ErrContextDone is returned. If the net.PacketConn connection is closed, running functions terminate with ErrClosed.
func New ¶
func New(conn net.PacketConn, logger log.Logger) *RPT
New creates a new RPT connection by wrapping around a PacketConn.
New also spawns a background receiving goroutine that continuously reads from conn and keeps track of ACKs and messages.
func (*RPT) Close ¶
Close closes the net.PacketConn connection and shuts down the background goroutine. If Close blocks for too long while waiting for the goroutine to terminate, it returns ErrContextDone.