Documentation ¶
Index ¶
- Variables
- type Config
- type Conn
- func (cc *Conn) AcquireMessage(ctx context.Context) *pool.Message
- func (cc *Conn) AddOnClose(f EventFunc)
- func (cc *Conn) AsyncPing(receivedPong func()) (func(), error)
- func (cc *Conn) CheckExpirations(now time.Time)
- func (cc *Conn) Close() error
- func (cc *Conn) Context() context.Context
- func (cc *Conn) Done() <-chan struct{}
- func (cc *Conn) LocalAddr() net.Addr
- func (cc *Conn) NetConn() net.Conn
- func (cc *Conn) ProcessReceivedMessage(req *pool.Message)
- func (cc *Conn) ProcessReceivedMessageWithHandler(req *pool.Message, handler HandlerFunc)
- func (cc *Conn) ReleaseMessage(m *pool.Message)
- func (cc *Conn) RemoteAddr() net.Addr
- func (cc *Conn) Run() (err error)
- func (cc *Conn) Sequence() uint64
- func (cc *Conn) Session() *Session
- func (cc *Conn) SetContextValue(key interface{}, val interface{})
- func (cc *Conn) WriteMessage(req *pool.Message) error
- type ConnOptions
- type CreateInactivityMonitorFunc
- type ErrorFunc
- type EventFunc
- type GetMIDFunc
- type HandlerFunc
- type InactivityMonitor
- type Notifier
- type Option
- type RequestMonitorFunc
- type Session
- func (s *Session) AcquireMessage(ctx context.Context) *pool.Message
- func (s *Session) AddOnClose(f EventFunc)
- func (s *Session) CheckExpirations(now time.Time, cc *Conn)
- func (s *Session) Close() error
- func (s *Session) Context() context.Context
- func (s *Session) Done() <-chan struct{}
- func (s *Session) LocalAddr() net.Addr
- func (s *Session) NetConn() net.Conn
- func (s *Session) ReleaseMessage(m *pool.Message)
- func (s *Session) RemoteAddr() net.Addr
- func (s *Session) Run(cc *Conn) (err error)
- func (s *Session) Sequence() uint64
- func (s *Session) SetContextValue(key interface{}, val interface{})
- func (s *Session) WriteMessage(req *pool.Message) error
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = func() Config { opts := Config{ Common: config.NewCommon[*Conn](), CreateInactivityMonitor: func() InactivityMonitor { return inactivity.NewNilMonitor[*Conn]() }, RequestMonitor: func(*Conn, *pool.Message) (bool, error) { return false, nil }, Dialer: &net.Dialer{Timeout: time.Second * 3}, Net: "tcp", ConnectionCacheSize: 2048, } opts.Handler = func(w *responsewriter.ResponseWriter[*Conn], r *pool.Message) { switch r.Code() { case codes.POST, codes.PUT, codes.GET, codes.DELETE: if err := w.SetResponse(codes.NotFound, message.TextPlain, nil); err != nil { opts.Errors(fmt.Errorf("client handler: cannot set response: %w", err)) } } } return opts }()
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { config.Common[*Conn] CreateInactivityMonitor CreateInactivityMonitorFunc RequestMonitor RequestMonitorFunc Net string Dialer *net.Dialer TLSCfg *tls.Config Handler HandlerFunc ConnectionCacheSize uint16 DisablePeerTCPSignalMessageCSMs bool CloseSocket bool DisableTCPSignalMessageCSM bool }
type Conn ¶
Conn represents a virtual connection to a conceptual endpoint, to perform COAPs commands.
func NewConn ¶
func NewConn( connection *coapNet.Conn, createBlockWise func(cc *Conn) *blockwise.BlockWise[*Conn], inactivityMonitor InactivityMonitor, cfg *Config, ) *Conn
NewConn creates connection over session and observation.
func NewConnWithOpts ¶ added in v3.3.0
func (*Conn) AddOnClose ¶
AddOnClose calls function on close connection event.
func (*Conn) AsyncPing ¶
AsyncPing sends ping and receivedPong will be called when pong arrives. It returns cancellation of ping operation.
func (*Conn) CheckExpirations ¶
CheckExpirations checks and remove expired items from caches.
func (*Conn) Context ¶
Context returns the client's context.
If connections was closed context is cancelled.
func (*Conn) Done ¶
func (cc *Conn) Done() <-chan struct{}
Done signalizes that connection is not more processed.
func (*Conn) NetConn ¶
NetConn returns the underlying connection that is wrapped by cc. The Conn returned is shared by all invocations of NetConn, so do not modify it.
func (*Conn) ProcessReceivedMessage ¶ added in v3.1.0
func (*Conn) ProcessReceivedMessageWithHandler ¶ added in v3.1.0
func (cc *Conn) ProcessReceivedMessageWithHandler(req *pool.Message, handler HandlerFunc)
func (*Conn) ReleaseMessage ¶
func (*Conn) Run ¶
Run reads and process requests from a connection, until the connection is not closed.
func (*Conn) SetContextValue ¶
func (cc *Conn) SetContextValue(key interface{}, val interface{})
SetContextValue stores the value associated with key to context of connection.
type ConnOptions ¶ added in v3.3.0
type ConnOptions struct { CreateBlockWise func(cc *Conn) *blockwise.BlockWise[*Conn] InactivityMonitor InactivityMonitor RequestMonitor RequestMonitorFunc }
type CreateInactivityMonitorFunc ¶
type CreateInactivityMonitorFunc = func() InactivityMonitor
type GetMIDFunc ¶
type GetMIDFunc = func() int32
type HandlerFunc ¶
type HandlerFunc = func(*responsewriter.ResponseWriter[*Conn], *pool.Message)
type InactivityMonitor ¶
type Option ¶ added in v3.3.0
type Option = func(opts *ConnOptions)
func WithBlockWise ¶ added in v3.3.0
WithBlockWise enables block-wise transfer for the connection.
func WithInactivityMonitor ¶ added in v3.3.0
func WithInactivityMonitor(inactivityMonitor InactivityMonitor) Option
WithInactivityMonitor enables inactivity monitor for the connection.
func WithRequestMonitor ¶ added in v3.3.0
func WithRequestMonitor(requestMonitor RequestMonitorFunc) Option
WithRequestMonitor enables request monitoring for the connection. It is called for each CoAP message received from the peer before it is processed. If it returns an error, the connection is closed. If it returns true, the message is dropped.
type RequestMonitorFunc ¶ added in v3.3.0
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSession ¶
func (*Session) AcquireMessage ¶
func (*Session) AddOnClose ¶
func (*Session) CheckExpirations ¶
CheckExpirations checks and remove expired items from caches.
func (*Session) Done ¶
func (s *Session) Done() <-chan struct{}
Done signalizes that connection is not more processed.
func (*Session) NetConn ¶
NetConn returns the underlying connection that is wrapped by s. The Conn returned is shared by all invocations of NetConn, so do not modify it.
func (*Session) ReleaseMessage ¶
func (*Session) RemoteAddr ¶
RemoteAddr gets remote address.
func (*Session) Run ¶
Run reads and process requests from a connection, until the connection is not closed.
func (*Session) SetContextValue ¶
func (s *Session) SetContextValue(key interface{}, val interface{})
SetContextValue stores the value associated with key to context of connection.