Documentation ¶
Overview ¶
Package reconnect implements transparent logic for reconnecting to the dispatcher.
Index ¶
- Variables
- type AtomicBool
- type BaseOperation
- type DispatcherService
- type IOOperation
- type PacketConn
- func (conn *PacketConn) Close() error
- func (conn *PacketConn) DoIO(op IOOperation) error
- func (conn *PacketConn) LocalAddr() net.Addr
- func (conn *PacketConn) ReadFrom(b []byte) (int, net.Addr, error)
- func (conn *PacketConn) Reconnect() (net.PacketConn, error)
- func (conn *PacketConn) SetDeadline(deadline time.Time) error
- func (conn *PacketConn) SetReadDeadline(deadline time.Time) error
- func (conn *PacketConn) SetWriteDeadline(deadline time.Time) error
- func (conn *PacketConn) WriteTo(b []byte, address net.Addr) (int, error)
- type ReadFromOperation
- type ReadOperation
- type Reconnecter
- type State
- type TickingReconnecter
- type WriteOperation
- type WriteToOperation
Constants ¶
This section is empty.
Variables ¶
var ( ErrDispatcherDead = serrors.New("dispatcher dead") // FIXME(scrye): Change this s.t. it's serrors.IsTimeout compatible. ErrReconnecterTimeoutExpired = serrors.New("timeout expired") ErrReconnecterStopped = serrors.New("stop method was called") ErrClosed = serrors.New("closed") )
var (
DefaultTickerInterval = time.Second
)
Use a var here to allow tests to inject shorter intervals for fast testing.
Functions ¶
This section is empty.
Types ¶
type AtomicBool ¶
type AtomicBool struct {
// contains filtered or unexported fields
}
func (*AtomicBool) IsFalse ¶
func (f *AtomicBool) IsFalse() bool
func (*AtomicBool) IsTrue ¶
func (f *AtomicBool) IsTrue() bool
func (*AtomicBool) Set ¶
func (f *AtomicBool) Set(v bool)
type BaseOperation ¶
type BaseOperation struct {
// contains filtered or unexported fields
}
type DispatcherService ¶
type DispatcherService struct {
// contains filtered or unexported fields
}
DispatcherService is a dispatcher wrapper that creates conns with transparent reconnection capabilities. Connections created by DispatcherService also validate that dispatcher registrations do not change addresses.
Callers interested in providing their own reconnection callbacks and validating the new connection themselves should use the connection constructors directly.
func NewDispatcherService ¶
func NewDispatcherService(dispatcher reliable.Dispatcher) *DispatcherService
NewDispatcherService adds transparent reconnection capabilities to dispatcher connections.
type IOOperation ¶
type IOOperation interface { // Runs the I/O operation on conn Do(conn net.PacketConn) error // IsWrite returns true for types implementing write operations IsWrite() bool }
IOOperation provides an abstraction around any Conn reads and writes. Types that implement this interface contain the Read/Write arguments and return values as fields, thus allowing the reconnection loop to run any I/O function without caring what it is.
type PacketConn ¶
type PacketConn struct {
// contains filtered or unexported fields
}
func NewPacketConn ¶
func NewPacketConn(dispConn net.PacketConn, reconnecter Reconnecter) *PacketConn
func (*PacketConn) Close ¶
func (conn *PacketConn) Close() error
func (*PacketConn) DoIO ¶
func (conn *PacketConn) DoIO(op IOOperation) error
func (*PacketConn) LocalAddr ¶
func (conn *PacketConn) LocalAddr() net.Addr
func (*PacketConn) Reconnect ¶
func (conn *PacketConn) Reconnect() (net.PacketConn, error)
Reconnect is only used internally and should never be called from outside the package.
func (*PacketConn) SetDeadline ¶
func (conn *PacketConn) SetDeadline(deadline time.Time) error
func (*PacketConn) SetReadDeadline ¶
func (conn *PacketConn) SetReadDeadline(deadline time.Time) error
func (*PacketConn) SetWriteDeadline ¶
func (conn *PacketConn) SetWriteDeadline(deadline time.Time) error
type ReadFromOperation ¶
type ReadFromOperation struct { ReadOperation // contains filtered or unexported fields }
func (*ReadFromOperation) Do ¶
func (op *ReadFromOperation) Do(conn net.PacketConn) error
type ReadOperation ¶
type ReadOperation struct {
BaseOperation
}
func (*ReadOperation) IsWrite ¶
func (_ *ReadOperation) IsWrite() bool
type Reconnecter ¶
type State ¶
type State struct {
// contains filtered or unexported fields
}
A State objects encodes an up or down state in a way that can be used directly in selects. Note that not all methods are safe for concurrent use (see their documentation for more information).
func NewState ¶
func NewState() *State
NewState returns a new state. The state is initially set to up.
func (*State) SetDown ¶
func (s *State) SetDown()
SetDown sets the state to down.
It is not safe to call SetDown concurrently with other methods.
type TickingReconnecter ¶
type TickingReconnecter struct {
// contains filtered or unexported fields
}
func NewTickingReconnecter ¶
func NewTickingReconnecter( f func(timeout time.Duration) (net.PacketConn, uint16, error)) *TickingReconnecter
NewTickingReconnecter creates a new dispatcher reconnecter. Calling Reconnect in turn calls f periodically to obtain a new connection to the dispatcher,
func (*TickingReconnecter) Reconnect ¶
func (r *TickingReconnecter) Reconnect(ctx context.Context) (net.PacketConn, uint16, error)
Reconnect repeatedly attempts to reestablish a connection to the dispatcher, subject to timeout. Attempts that receive dispatcher connection errors are followed by reattempts. Critical errors (e.g., port mismatches) return immediately.
func (*TickingReconnecter) Stop ¶
func (r *TickingReconnecter) Stop()
Stop shuts down the reconnection attempt (if any), and waits for the reconnecting goroutine to finish.
It is safe to call Stop while Reconnect is running.
type WriteOperation ¶
type WriteOperation struct {
BaseOperation
}
func (*WriteOperation) IsWrite ¶
func (_ *WriteOperation) IsWrite() bool
type WriteToOperation ¶
type WriteToOperation struct { WriteOperation // contains filtered or unexported fields }
func (*WriteToOperation) Do ¶
func (op *WriteToOperation) Do(conn net.PacketConn) error
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
Package mock_reconnect is a generated GoMock package.
|
Package mock_reconnect is a generated GoMock package. |