// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build aix || dragonfly || freebsd || illumos || linux || netbsd

package net

import (
	
	
	
)

func setKeepAliveIdle( *netFD,  time.Duration) error {
	if  == 0 {
		 = defaultTCPKeepAliveIdle
	} else if  < 0 {
		return nil
	}

	// The kernel expects seconds so round to next highest second.
	 := int(roundDurationUp(, time.Second))
	 := .pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE, )
	runtime.KeepAlive()
	return wrapSyscallError("setsockopt", )
}

func setKeepAliveInterval( *netFD,  time.Duration) error {
	if  == 0 {
		 = defaultTCPKeepAliveInterval
	} else if  < 0 {
		return nil
	}

	// The kernel expects seconds so round to next highest second.
	 := int(roundDurationUp(, time.Second))
	 := .pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, )
	runtime.KeepAlive()
	return wrapSyscallError("setsockopt", )
}

func setKeepAliveCount( *netFD,  int) error {
	if  == 0 {
		 = defaultTCPKeepAliveCount
	} else if  < 0 {
		return nil
	}

	 := .pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPCNT, )
	runtime.KeepAlive()
	return wrapSyscallError("setsockopt", )
}