udp

package
v2.2.11 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn represents an on-going session with a client, over UDP packets.

func (*Conn) Close

func (c *Conn) Close() error

Close releases resources related to the Conn.

func (*Conn) Read

func (c *Conn) Read(p []byte) (int, error)

Read implements io.Reader for a Conn.

func (*Conn) Write

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

Write implements io.Writer for a Conn.

type Handler

type Handler interface {
	ServeUDP(conn *Conn)
}

Handler is the UDP counterpart of the usual HTTP handler.

type HandlerFunc

type HandlerFunc func(conn *Conn)

The HandlerFunc type is an adapter to allow the use of ordinary functions as handlers.

func (HandlerFunc) ServeUDP

func (f HandlerFunc) ServeUDP(conn *Conn)

ServeUDP implements the Handler interface for UDP.

type HandlerSwitcher

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

HandlerSwitcher is a switcher implementation of the Handler interface.

func (*HandlerSwitcher) ServeUDP

func (s *HandlerSwitcher) ServeUDP(conn *Conn)

ServeUDP implements the Handler interface.

func (*HandlerSwitcher) Switch

func (s *HandlerSwitcher) Switch(handler Handler)

Switch replaces s handler with the given handler.

type Listener

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

Listener augments a session-oriented Listener over a UDP PacketConn.

func Listen

func Listen(network string, laddr *net.UDPAddr) (*Listener, error)

Listen creates a new listener.

func (*Listener) Accept

func (l *Listener) Accept() (*Conn, error)

Accept waits for and returns the next connection to the listener.

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns the listener's network address.

func (*Listener) Close

func (l *Listener) Close() error

Close closes the listener. It is like Shutdown with a zero graceTimeout.

func (*Listener) Shutdown

func (l *Listener) Shutdown(graceTimeout time.Duration) error

Shutdown closes the listener. It immediately stops accepting new sessions, and it waits for all existing sessions to terminate, and a maximum of graceTimeout. Then it forces close any session left.

type Proxy

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

Proxy is a reverse-proxy implementation of the Handler interface.

func NewProxy

func NewProxy(address string) (*Proxy, error)

NewProxy creates a new Proxy.

func (*Proxy) ServeUDP

func (p *Proxy) ServeUDP(conn *Conn)

ServeUDP implements the Handler interface.

type WRRLoadBalancer

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

WRRLoadBalancer is a naive RoundRobin load balancer for UDP services.

func NewWRRLoadBalancer

func NewWRRLoadBalancer() *WRRLoadBalancer

NewWRRLoadBalancer creates a new WRRLoadBalancer.

func (*WRRLoadBalancer) AddServer

func (b *WRRLoadBalancer) AddServer(serverHandler Handler)

AddServer appends a handler to the existing list.

func (*WRRLoadBalancer) AddWeightedServer

func (b *WRRLoadBalancer) AddWeightedServer(serverHandler Handler, weight *int)

AddWeightedServer appends a handler to the existing list with a weight.

func (*WRRLoadBalancer) ServeUDP

func (b *WRRLoadBalancer) ServeUDP(conn *Conn)

ServeUDP forwards the connection to the right service.

Jump to

Keyboard shortcuts

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