transport.go 500 Bytes
Newer Older
Steven Allen's avatar
Steven Allen committed
1 2 3 4 5 6
package tcpreuse

import (
	"errors"
	"sync"

tavit ohanian's avatar
tavit ohanian committed
7
	logging "gitlab.dms3.io/dms3/public/go-log"
Steven Allen's avatar
Steven Allen committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
)

var log = logging.Logger("reuseport-transport")

// ErrWrongProto is returned when dialing a protocol other than tcp.
var ErrWrongProto = errors.New("can only dial TCP over IPv4 or IPv6")

// Transport is a TCP reuse transport that reuses listener ports.
type Transport struct {
	v4 network
	v6 network
}

type network struct {
	mu        sync.RWMutex
	listeners map[*listener]struct{}
	dialer    dialer
}