mqttserver

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultServeMux = NewServeMux(log.DefaultLogger)
View Source
var (
	ErrServerClosed = errors.New("mqtt: Server closed")
)

Functions

func ListenAndServe

func ListenAndServe(addr string, handler Handler) error

func ListenAndServeTLS

func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error

func NewLoggingConnFunc

func NewLoggingConnFunc(baseName string, logger log.Logger) func(c net.Conn) net.Conn

noinspection GoUnusedExportedFunction

func ReadMQTTMessage

func ReadMQTTMessage(reader io.Reader) (mqttcodec.ControlPacket, error)

Types

type Conn

type Conn interface {
	io.WriteCloser
	LocalAddr() net.Addr       // Returns the local IP
	RemoteAddr() net.Addr      // Returns the remote IP
	TLS() *tls.ConnectionState // TLS or nil when not using TLS
	Context() context.Context  // Returns the internal context
	Connection() net.Conn      // Returns network connection
	Properties() Properties    // Data set by handler during connection duration
}

Conn interface is used by a handler to send mqtt messages.

type ConnState

type ConnState int32
const (
	StateNew ConnState = iota
	StateActive
	StateIdle
	StateClosed
)

func (ConnState) String

func (c ConnState) String() string

type Handler

type Handler interface {
	ServeMQTT(Conn, mqttcodec.ControlPacket)
}

type HandlerFunc

type HandlerFunc func(Conn, mqttcodec.ControlPacket)

func (HandlerFunc) ServeMQTT

func (f HandlerFunc) ServeMQTT(c Conn, req mqttcodec.ControlPacket)

type Properties

type Properties interface {
	IdleTimeout() time.Duration   // Returns connection idle timeout
	SetIdleTimeout(time.Duration) // Store a new idle timeout

	Authenticated() bool   // Returns if the connection was authenticated
	SetAuthenticated(bool) // Store the authenticated flag
}

type ServeMux

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

func NewServeMux

func NewServeMux(logger log.Logger) *ServeMux

func (*ServeMux) Handle

func (mux *ServeMux) Handle(messageType byte, handler Handler)

func (*ServeMux) ServeMQTT

func (mux *ServeMux) ServeMQTT(c Conn, p mqttcodec.ControlPacket)

type Server

type Server struct {
	Network      string        // network of the address - empty string defaults to tcp
	Addr         string        // address to listen on, ":1883" if empty
	Handler      Handler       // handler to invoke, DefaultServeMux if nil
	ReadTimeout  time.Duration // maximum duration before timing out read of the request
	WriteTimeout time.Duration // maximum duration before timing out write of the response
	IdleTimeout  time.Duration // maximum amount of time to wait for the next request
	TLSConfig    *tls.Config   // optional TLS config, used by ListenAndServeTLS

	ReaderBufferSize int // read buffer size pro tcp connection (default 1024)
	WriterBufferSize int // write buffer size pro tcp connection (default 1024)

	ErrorLog log.Logger

	ConnDebug func(c net.Conn) net.Conn // optional logging wrapper for all server connections
	// contains filtered or unexported fields
}

A Server defines parameters for running a mqtt server.

func (*Server) Close

func (srv *Server) Close() error

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() (err error)

func (*Server) ListenAndServeTLS

func (srv *Server) ListenAndServeTLS(certFile, keyFile string) (err error)

func (*Server) NumActiveConn

func (srv *Server) NumActiveConn() int

Number of active connections

func (*Server) NumTotalConn

func (srv *Server) NumTotalConn() int64

Number of total connections

func (*Server) Serve

func (srv *Server) Serve(l net.Listener) (err error)

func (*Server) ServeTLS

func (srv *Server) ServeTLS(l net.Listener, certFile, keyFile string) error

func (*Server) Shutdown

func (srv *Server) Shutdown(ctx context.Context) error

Jump to

Keyboard shortcuts

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