func (e *Endpoint) listen() {
	log.Infof("listening on %s", e.listenAddr)
	for {
		conn, err := e.listener.Accept()
		if err != nil {
			var opErr *net.OpError
			if errors.As(err, &opErr) {
				if opErr.Op == "accept" {
					if strings.Contains(opErr.Err.Error(),
						"use of closed network connection") {
						return
					}
				}
			}
			log.Errorf("unable to accept client connection: %v", err)
			return
		}
		e.connCh <- &connection{
			Conn: conn,
			Done: make(chan bool),
		}
	}
}
listen accepts incoming client connections on the endpoint.
It must be run as a goroutine.
package pool
import (
	"context"
	"errors"
	"fmt"
	"net"
	"strings"
	"sync"
	"time"
	"github.com/decred/dcrd/chaincfg/v3"
	errs "github.com/decred/dcrpool/errors"
)
type EndpointConfig struct {
	ActiveNet *chaincfg.Params
	db Database
	SoloPool bool
	Blake256Pad []byte
	NonceIterations float64
	MaxConnectionsPerHost uint32
	MaxGenTime time.Duration
	HubWg *sync.WaitGroup
	FetchMinerDifficulty func(string) (*DifficultyInfo, error)
	SubmitWork func(context.Context, *string) (bool, error)
	FetchCurrentWork func() string
	WithinLimit func(string, int) bool
	AddConnection func(string)
	RemoveConnection func(string)
	FetchHostConnections func(string) uint32
	SignalCache func(event CacheUpdateEvent)
	MonitorCycle time.Duration
	MaxUpgradeTries uint32
	ClientTimeout time.Duration
}
type connection struct {
	Conn net.Conn
	Done chan bool
}
type Endpoint struct {
	listenAddr string
	connCh     chan *connection
	discCh     chan struct{}
	listener   net.Listener
	cfg        *EndpointConfig
	clients    map[string]*Client
	clientsMtx sync.Mutex
	wg         sync.WaitGroup
}
func NewEndpoint(eCfg *EndpointConfig, listenAddr string) (*Endpoint, error) {
	endpoint := &Endpoint{
		listenAddr: listenAddr,
		cfg:        eCfg,
		clients:    make(map[string]*Client),
		connCh:     make(chan *connection, bufferSize),
		discCh:     make(chan struct{}, bufferSize),
	}
	listener, err := net.Listen("tcp", listenAddr)
	if err != nil {
		desc := fmt.Sprintf("unable to create endpoint on %s", listenAddr)
		return nil, errs.PoolError(errs.Listener, desc)
	}
	endpoint.listener = listener
	return endpoint, nil
}
func (e *Endpoint) removeClient(c *Client) {
	e.clientsMtx.Lock()
	delete(e.clients, c.extraNonce1)
	e.clientsMtx.Unlock()
	e.cfg.RemoveConnection(c.addr.IP.String())
}