func (e *Engine) Handle(conn transport.Conn) bool {
	if conn == nil {
		panic("missing conn")
	}
	e.mutex.Lock()
	defer e.mutex.Unlock()
	if !e.tomb.Alive() {
		_ = conn.Close()
		return false
	}
	conn.SetReadLimit(e.ReadLimit)
	conn.SetMaxWriteDelay(e.MaxWriteDelay)
	conn.SetReadTimeout(e.ConnectTimeout)
	NewClient(e.Backend, conn)
	return true
}
Handle takes over responsibility and handles a transport.Conn. It returns
false if the engine is closing and the connection has been closed.
package broker
import (
	"net"
	"sync"
	"time"
	"github.com/256dpi/gomqtt/transport"
	"gopkg.in/tomb.v2"
)
type Engine struct {
	Backend Backend
	ReadLimit int64
	MaxWriteDelay time.Duration
	ConnectTimeout time.Duration
	OnError func(error)
	mutex sync.Mutex
	tomb  tomb.Tomb
}
func NewEngine(backend Backend) *Engine {
	return &Engine{
		Backend:        backend,
		ConnectTimeout: 10 * time.Second,
		ReadLimit:      8 * 1024 * 1024,  
		MaxWriteDelay:  10 * time.Millisecond,
	}
}
func (e *Engine) Accept(server transport.Server) {
	e.tomb.Go(func() error {
		for {
			if !e.tomb.Alive() {
				return tomb.ErrDying
			}
			conn, err := server.Accept()
			if err != nil {
				if e.OnError != nil {
					e.OnError(err)
				}
				return err
			}
			if !e.Handle(conn) {
				return nil
			}
		}
	})
}