server

package
v3.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 16 Imported by: 8 modules, 7 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

View Source
var DefaultConfig = func() Config {
	opts := Config{
		Common: config.NewCommon[*client.Conn](),
		CreateInactivityMonitor: func() client.InactivityMonitor {
			maxRetries := uint32(2)
			timeout := time.Second * 16
			onInactive := func(cc *client.Conn) {
				_ = cc.Close()
			}
			keepalive := inactivity.NewKeepAlive(maxRetries, onInactive, func(cc *client.Conn, receivePong func()) (func(), error) {
				return cc.AsyncPing(receivePong)
			})
			return inactivity.New(timeout/time.Duration(maxRetries+1), keepalive.OnInactive)
		},
		OnNewConn: func(*client.Conn) {

		},
		RequestMonitor: func(*client.Conn, *pool.Message) (bool, error) {
			return false, nil
		},
		ConnectionCacheSize: 2 * 1024,
	}
	opts.Handler = func(w *responsewriter.ResponseWriter[*client.Conn], _ *pool.Message) {
		if err := w.SetResponse(codes.NotFound, message.TextPlain, nil); err != nil {
			opts.Errors(fmt.Errorf("server handler: cannot set response: %w", err))
		}
	}
	return opts
}()

Functions

This section is empty.

Types

type Config

type Config struct {
	config.Common[*client.Conn]
	CreateInactivityMonitor         client.CreateInactivityMonitorFunc
	Handler                         HandlerFunc
	OnNewConn                       OnNewConnFunc
	RequestMonitor                  client.RequestMonitorFunc
	ConnectionCacheSize             uint16
	DisablePeerTCPSignalMessageCSMs bool
	DisableTCPSignalMessageCSM      bool
}

type ErrorFunc

type ErrorFunc = func(error)

type GoPoolFunc

type GoPoolFunc = func(func()) error

type HandlerFunc

type HandlerFunc = func(*responsewriter.ResponseWriter[*client.Conn], *pool.Message)

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

type Listener

type Listener interface {
	Close() error
	AcceptWithContext(ctx context.Context) (net.Conn, error)
}

Listener defined used by coap

type OnNewConnFunc

type OnNewConnFunc = func(*client.Conn)

OnNewConnFunc is the callback for new connections.

type Option

type Option interface {
	TCPServerApply(cfg *Config)
}

A Option sets options such as credentials, codec and keepalive parameters, etc.

type Server

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

func New

func New(opt ...Option) *Server

func (*Server) Serve

func (s *Server) Serve(l Listener) error

func (*Server) Stop

func (s *Server) Stop()

Stop stops server without wait of ends Serve function.

Jump to

Keyboard shortcuts

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