server

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package server provides server for Policy Information Point.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBound indicates that server has been already bound to a port or file.
	ErrBound = errors.New("server has been already bound to a port or file")
	// ErrNotBound indicates that server hasn't been bound yet.
	ErrNotBound = errors.New("server hasn't been bound yet")
	// ErrStarted indicates that server has been already started.
	ErrStarted = errors.New("server has been already started")
	// ErrNotStarted indicates that server hasn't been started yet.
	ErrNotStarted = errors.New("server hasn't been started yet")
)
View Source
var ErrMsgOverflow = errors.New("message buffer overflow")

ErrMsgOverflow indicates that message is too big for message buffer.

Functions

This section is empty.

Types

type ConnErrHandler

type ConnErrHandler func(net.Addr, error)

ConnErrHandler is a function to process errors within a connection.

type Option

type Option func(*options)

Option configures how we set up PIP server.

func WithAddress

func WithAddress(addr string) Option

WithAddress returns an Option which sets service endpoint.

func WithBufferSize

func WithBufferSize(n int) Option

WithBufferSize returns an Option which sets size of input and output buffers. By default or if n <= 0 it is 1 MB.

func WithConnErrHandler

func WithConnErrHandler(f ConnErrHandler) Option

WithConnErrHandler returns an Option which sets error handler for communication errors within a connection.

func WithHandler

func WithHandler(f ServiceHandler) Option

WithHandler returns an Option which sets handler for service requests. The handler must write response and return the same buffer it got. It must not change buffer capacity.

func WithMaxConnections

func WithMaxConnections(n int) Option

WithMaxConnections returns an Option which limits number of simultaneous connections. If n <= 0 server doesn't limit incoming connections.

func WithMaxMessageSize

func WithMaxMessageSize(n int) Option

WithMaxMessageSize returns an Option which sets limit on message size. Default 10 KB.

func WithNetwork

func WithNetwork(net string) Option

WithNetwork returns an Option which sets service network. It supports "tcp", "tcp4", "tcp6" and "unix" netwroks.

func WithWorkers

func WithWorkers(n int) Option

WithWorkers returns an Option which sets a number of workers per connection.

func WithWriteInterval

func WithWriteInterval(d time.Duration) Option

WithWriteInterval returns an Option which sets duration after which data from write buffer are sent to network even if write buffer isn't full.

type Server

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

Server structure represents PIP server.

func NewServer

func NewServer(opts ...Option) *Server

NewServer creates new Server instance.

func (*Server) Bind

func (s *Server) Bind() error

Bind links server to a port or file.

func (*Server) Serve

func (s *Server) Serve() error

Serve starts accepting incoming connections.

func (*Server) Stop

func (s *Server) Stop() error

Stop terminates server.

type ServiceHandler

type ServiceHandler func([]byte) []byte

ServiceHandler is a prototye for service handler function. The handler must write response and return the same buffer it got. It must not change buffer capacity.

Jump to

Keyboard shortcuts

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