github.com/angenalZZZ/gofunc@v0.0.0-20210507121333-48ff1be3917b/net/internal/netpoll/netpoll_darwin.go (about) 1 package netpoll 2 3 import "golang.org/x/sys/unix" 4 5 // SetKeepAlive sets the keepalive for the connection. 6 func SetKeepAlive(fd, secs int) error { 7 if err := unix.SetsockoptInt(fd, unix.SOL_SOCKET, 0x8, 1); err != nil { 8 return err 9 } 10 switch err := unix.SetsockoptInt(fd, unix.IPPROTO_TCP, 0x101, secs); err { 11 case nil, unix.ENOPROTOOPT: // OS X 10.7 and earlier don't support this option 12 default: 13 return err 14 } 15 return unix.SetsockoptInt(fd, unix.IPPROTO_TCP, unix.TCP_KEEPALIVE, secs) 16 }