github.com/Cloud-Foundations/Dominator@v0.3.4/lib/net/tcpsockopt_darwin.go (about) 1 package net 2 3 import ( 4 "syscall" 5 "time" 6 ) 7 8 const sysTCP_KEEPINTVL = 0x101 9 10 func (conn *connection) SetKeepAlivePeriod(d time.Duration) error { 11 // The kernel expects seconds so round to next highest second. 12 d += (time.Second - time.Nanosecond) 13 secs := int(d.Seconds()) 14 err := syscall.SetsockoptInt(conn.fd, syscall.IPPROTO_TCP, 15 sysTCP_KEEPINTVL, secs) 16 if err != nil { 17 return err 18 } 19 return syscall.SetsockoptInt(conn.fd, syscall.IPPROTO_TCP, 20 syscall.TCP_KEEPALIVE, 2) 21 }