func (conn *ProtectedConnBase) cleanup() {
	conn.mutex.Lock()
	defer conn.mutex.Unlock()
	if conn.socketFd != socketError {
		syscall.Close(conn.socketFd)
		conn.socketFd = socketError
	}
}
cleanup is ran whenever we encounter a socket error
we use a mutex since this connection is active in a variety
of goroutines and to prevent any possible race conditions
package protector
import (
	"context"
	"errors"
	"fmt"
	"io"
	"log"
	"net"
	"os"
	"strconv"
	"sync"
	"syscall"
	"time"
	"golang.org/x/sys/unix"
)
const (
	SO_MARK = 0x24
)
var SocketMark int
func SupportReusePort() bool {
	fd, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
	if nil != err {
		return false
	}
	defer syscall.Close(fd)
	err = unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
	if nil != err {
		return false
	}
	return true
}
type ProtectedConnBase struct {
	mutex    sync.Mutex
	isClosed bool
	socketFd int
	ip       net.IP
	port int
}
func (conn *ProtectedConnBase) convertLisener() (net.Listener, error) {
	conn.mutex.Lock()
	file := os.NewFile(uintptr(conn.socketFd), "")
	fileLis, err := net.FileListener(file)
	file.Close()
	conn.socketFd = socketError
	if err != nil {
		conn.mutex.Unlock()
		return nil, err
	}
	conn.mutex.Unlock()
	return fileLis, nil
}
func (conn *ProtectedConnBase) bindSocket(ip net.IP, port int, ipv6 bool) error {
	var sockAddr syscall.Sockaddr
	if !ipv6 {
		sockAddr4 := &syscall.SockaddrInet4{Port: port}
		copy(sockAddr4.Addr[:], ip.To4()[0:4])
		sockAddr = sockAddr4
	} else {
		sockAddr6 := &syscall.SockaddrInet6{Port: port}
		copy(sockAddr6.Addr[:], ip.To16()[0:16])
		sockAddr = sockAddr6
	}
	err := syscall.Bind(conn.socketFd, sockAddr)
	if nil != err {
		return err
	}
	return err
}