socket_activation_unix.go 462 B

12345678910111213141516171819202122
  1. //go:build unix
  2. // +build unix
  3. package internet
  4. import (
  5. "os"
  6. "strconv"
  7. "syscall"
  8. "github.com/v2fly/v2ray-core/v5/common/net"
  9. )
  10. func activate_socket(address string) (net.Listener, error) {
  11. fd, err := strconv.Atoi(address[8:])
  12. if err != nil {
  13. return nil, err
  14. }
  15. // Ignore the fail of SetNonblock: it's merely an optimization so that Go can poll this fd.
  16. _ = syscall.SetNonblock(fd, true)
  17. return net.FileListener(os.NewFile(uintptr(fd), address))
  18. }