1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
//go:build !js && !wasm && (linux || dragonfly || freebsd || netbsd || openbsd || rumprun)
package tcplisten
import (
"fmt"
"golang.org/x/sys/unix"
)
func newSocketCloexec(domain, typ, proto int) (int, error) {
fd, err := unix.Socket(domain, typ|unix.SOCK_NONBLOCK|unix.SOCK_CLOEXEC, proto)
if err == nil {
return fd, nil
}
if err == unix.EPROTONOSUPPORT || err == unix.EINVAL {
return newSocketCloexecOld(domain, typ, proto)
}
return -1, fmt.Errorf("cannot create listening unblocked socket: %w", err)
}
|