package client
import "github.com/plgd-dev/go-coap/v3/tcp/client"
Index ¶
- Variables
- type Config
- type Conn
- func NewConn( connection *coapNet.Conn, createBlockWise func(cc *Conn) *blockwise.BlockWise[*Conn], inactivityMonitor InactivityMonitor, cfg *Config, ) *Conn
- func NewConnWithOpts(connection *coapNet.Conn, cfg *Config, opts ...Option) *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
- func WithBlockWise(createBlockWise func(cc *Conn) *blockwise.BlockWise[*Conn]) Option
- func WithInactivityMonitor(inactivityMonitor InactivityMonitor) Option
- func WithRequestMonitor(requestMonitor RequestMonitorFunc) Option
- type RequestMonitorFunc
- type Session
- func NewSession( ctx context.Context, connection *coapNet.Conn, maxMessageSize uint32, errors ErrorFunc, disableTCPSignalMessageCSM bool, closeSocket bool, inactivityMonitor InactivityMonitor, requestMonitor RequestMonitorFunc, connectionCacheSize uint16, messagePool *pool.Pool, ) *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
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 }()
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 ¶
func (*Conn) AcquireMessage ¶
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) Close ¶
Close closes connection without wait of ends Run function.
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) LocalAddr ¶
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 ¶
func (*Conn) ProcessReceivedMessageWithHandler ¶
func (cc *Conn) ProcessReceivedMessageWithHandler(req *pool.Message, handler HandlerFunc)
func (*Conn) ReleaseMessage ¶
func (*Conn) RemoteAddr ¶
RemoteAddr gets remote address.
func (*Conn) Run ¶
Run reads and process requests from a connection, until the connection is not closed.
func (*Conn) Sequence ¶
Sequence acquires sequence number.
func (*Conn) Session ¶
func (*Conn) SetContextValue ¶
func (cc *Conn) SetContextValue(key interface{}, val interface{})
SetContextValue stores the value associated with key to context of connection.
func (*Conn) WriteMessage ¶
WriteMessage sends an coap message.
type ConnOptions ¶
type ConnOptions struct { CreateBlockWise func(cc *Conn) *blockwise.BlockWise[*Conn] InactivityMonitor InactivityMonitor RequestMonitor RequestMonitorFunc }
type CreateInactivityMonitorFunc ¶
type CreateInactivityMonitorFunc = func() InactivityMonitor
type ErrorFunc ¶
type ErrorFunc = func(error)
type EventFunc ¶
type EventFunc = func()
type GetMIDFunc ¶
type GetMIDFunc = func() int32
type HandlerFunc ¶
type HandlerFunc = func(*responsewriter.ResponseWriter[*Conn], *pool.Message)
type InactivityMonitor ¶
type Notifier ¶
type Notifier interface {
Notify()
}
type Option ¶
type Option = func(opts *ConnOptions)
func WithBlockWise ¶
WithBlockWise enables block-wise transfer for the connection.
func WithInactivityMonitor ¶
func WithInactivityMonitor(inactivityMonitor InactivityMonitor) Option
WithInactivityMonitor enables inactivity monitor for the connection.
func WithRequestMonitor ¶
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 ¶
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSession ¶
func NewSession( ctx context.Context, connection *coapNet.Conn, maxMessageSize uint32, errors ErrorFunc, disableTCPSignalMessageCSM bool, closeSocket bool, inactivityMonitor InactivityMonitor, requestMonitor RequestMonitorFunc, connectionCacheSize uint16, messagePool *pool.Pool, ) *Session
func (*Session) AcquireMessage ¶
func (*Session) AddOnClose ¶
func (*Session) CheckExpirations ¶
CheckExpirations checks and remove expired items from caches.
func (*Session) Close ¶
func (*Session) Context ¶
func (*Session) Done ¶
func (s *Session) Done() <-chan struct{}
Done signalizes that connection is not more processed.
func (*Session) LocalAddr ¶
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) Sequence ¶
func (*Session) SetContextValue ¶
func (s *Session) SetContextValue(key interface{}, val interface{})
SetContextValue stores the value associated with key to context of connection.
func (*Session) WriteMessage ¶
Source Files ¶
- Version
- v3.3.6 (latest)
- Published
- Sep 18, 2024
- Platform
- linux/amd64
- Imports
- 24 packages
- Last checked
- 1 week ago –
Tools for package owners.