clientmap

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientMap

type ClientMap struct {
	IdleTimeout       time.Duration
	IdleCheckInterval time.Duration
	// contains filtered or unexported fields
}

ClientMap provides a goroutine-safe map of UDP connections to a remote address keyed by the client address, with a built-in idle TTL that closes and removes entries that remain idle beyond it.

func New

func New(idleTimeout time.Duration, idleCheckInterval time.Duration) *ClientMap

func (*ClientMap) Close

func (cm *ClientMap) Close()

Close cleans up all clients

func (*ClientMap) Get

func (cm *ClientMap) Get(
	clientAddr net.Addr,
	remote *net.UDPAddr,
	handler ServerConnHandler,
) (*net.UDPConn, error)

Get gets or creates a new UDP connection to the remote server and stores it in a map, matching clients to remote server connections. This way, we keep one UDP connection open to the server for each client. The handler parameter is invoked when a new connection needs to be created (for a new client) to defer that behavior to the caller.

type ServerConnHandler

type ServerConnHandler func(*net.UDPConn)

Jump to

Keyboard shortcuts

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