udp

package
v2.11.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 7 Imported by: 0

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 reads up to len(p) bytes into p from the connection. Each call corresponds to at most one datagram. If p is smaller than the datagram, the extra bytes will be discarded.

func (*Conn) Write

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

Write writes len(p) bytes from p to the underlying connection. Each call sends at most one datagram. It is an error to send a message larger than the system's max UDP datagram size.

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, timeout time.Duration) (*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