github.com/cristalhq/netx@v0.0.0-20221116164110-442313ef3309/listener_other.go (about)

     1  //go:build !darwin
     2  
     3  package netx
     4  
     5  import (
     6  	"fmt"
     7  	"syscall"
     8  )
     9  
    10  func newSocketCloexec(domain, typ, proto int) (int, error) {
    11  	fd, err := syscall.Socket(domain, typ|syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC, proto)
    12  	if err == nil {
    13  		return fd, nil
    14  	}
    15  
    16  	if err == syscall.EPROTONOSUPPORT || err == syscall.EINVAL {
    17  		return newSocketCloexecDefault(domain, typ, proto)
    18  	}
    19  
    20  	return -1, fmt.Errorf("cannot create listening unblocked socket: %s", err)
    21  }