package store import ( "syscall" "time" "golang.org/x/sys/unix" ) // userTimeout sets TCP_USER_TIMEOUT: data sent and not acknowledged for that // long closes the connection, where keepalive probes wait for it to go idle. func userTimeout(d time.Duration) func(network, address string, c syscall.RawConn) error { return func(_, _ string, c syscall.RawConn) error { var serr error err := c.Control(func(fd uintptr) { serr = unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_USER_TIMEOUT, int(d.Milliseconds())) }) if err != nil { return err } return serr } }