server

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2022 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Debug = iota
	Conn
	Error
	Fatal
)

Message levels control which messages will be sent to h.Msgr

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.34.0

type Config struct {
	// Sockname is the location/IP+port of the socket. For Unix
	// sockets, it takes the form "/path/to/socket". For TCP, it is an
	// IPv4 or IPv6 address followed by the desired port number
	// ("127.0.0.1:9090", "[::1]:9090").
	Sockname string

	// Timeout is the number of milliseconds the Server will wait
	// when performing network ops before timing out. Default
	// (zero) is no timeout. Each connection to the server is
	// handled in a separate goroutine, however, so one blocked
	// connection does not affect any others (unless you run out of
	// file descriptors for new conns).
	Timeout int64

	// Reqlen is the maximum number of bytes in a single read from
	// the network. If a request exceeds this limit, the
	// connection will be dropped. Use this to prevent memory
	// exhaustion by arbitrarily long network reads. The default
	// (0) is unlimited.
	Reqlen uint32

	// Buffer sets how many instances of Msg may be queued in
	// Server.Msgr. Non-Fatal Msgs which arrive while the buffer
	// is full are dropped on the floor to prevent the Server from
	// blocking. Defaults to 32.
	Buffer int

	// Msglvl determines which messages will be sent to the
	// Server's message channel. Valid values: debug, conn, error,
	// fatal.
	Msglvl string

	// LogIP determines if the IP of clients is logged on
	// connect. Enabling IP logging creates a bit of overhead on
	// each connect. If this isn't needed, or if the client can be
	// identified at the application layer, leaving this off will
	// somewhat improve performance in high-usage scenarios.
	LogIP bool

	//HMACKey is the secret key used to generate MACs for signing
	//and verifying messages. Default (nil) means MACs will not be
	//generated for messages sent, or expected for messages
	//received. Enabling message authentication adds significant
	//overhead for each message sent and received, so use this
	//when security outweighs performance.
	HMACKey []byte
}

Config holds values to be passed to server constuctors.

type Msg

type Msg struct {
	// Conn is the connection ID that the Msg is coming from.
	Conn uint32
	// Req is the request number that resulted in the Msg.
	Req uint32
	// Code is the numeric status indicator.
	Code int
	// Txt is the content/description.
	Txt string
	// Err is the error (if any) passed upward as part of the Msg.
	Err error
}

Msg is the format which Petrel uses to communicate informational messages and errors to its host program via the s.Msgr channel.

func (*Msg) Error

func (m *Msg) Error() string

Error implements the error interface for Msg, returning a nicely (if blandly) formatted string containing all information present.

type Responder

type Responder func([]byte) ([]byte, error)

Responder is the type which functions passed to Server.Register must match: taking a slice of bytes as an argument and returning a slice of bytes and an error.

type Server

type Server struct {
	// Msgr is the channel which receives notifications from
	// connections.
	Msgr chan *Msg
	// Sig is p.Sigchan, made available so apps can waatch it
	Sig chan os.Signal
	// contains filtered or unexported fields
}

Server is a Petrel server instance.

func TCPServer

func TCPServer(c *Config) (*Server, error)

TCPServer returns a Server which uses TCP networking.

func TLSServer

func TLSServer(c *Config, t *tls.Config) (*Server, error)

TLSServer returns a Server which uses TCP networking, secured with TLS.

func UnixServer

func UnixServer(c *Config, p uint32) (*Server, error)

UnixServer returns a Server which uses Unix domain sockets. Argument `p` is the Unix permissions to set on the socket (e.g. 770)

func (*Server) Quit

func (s *Server) Quit()

Quit handles shutdown and cleanup, including waiting for any connections to terminate. When it returns, all connections are fully shut down and no more work will be done.

func (*Server) Register

func (s *Server) Register(name string, r Responder) error

Register adds a Responder function to a Server.

'name' is the command you wish this function do be the responder for.

'r' is the name of the Responder function which will be called on dispatch.

Jump to

Keyboard shortcuts

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