1 Star 0 Fork 0

leonxiong/xtool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
keepalive_linux.go 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
leonxiong 提交于 3个月前 . update xtool
//go:build linux
// +build linux
package xnet
import (
"net"
"os"
"syscall"
)
// SetKeepAliveIdle sets the time (in seconds) the connection needs to remain
// idle before TCP starts sending keepalive probes.
func setAliveIdle(tcp *net.TCPConn, secs int) error {
file, err := tcp.File()
if err != nil {
return err
}
fd := int(file.Fd())
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE, secs))
}
// SetKeepAliveCount sets the maximum number of keepalive probes TCP should
// send before dropping the connection.
func setAliveCount(tcp *net.TCPConn, n int) error {
file, err := tcp.File()
if err != nil {
return err
}
fd := int(file.Fd())
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPCNT, n))
}
// SetKeepAliveInterval sets the time (in seconds) between individual keepalive
// probes.
func setAliveInterval(tcp *net.TCPConn, secs int) error {
file, err := tcp.File()
if err != nil {
return err
}
fd := int(file.Fd())
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, secs))
}
func setNonblock(fd int) error {
return os.NewSyscallError("setsockopt", syscall.SetNonblock(fd, true))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xlm516/xtool.git
git@gitee.com:xlm516/xtool.git
xlm516
xtool
xtool
20d904fd3223

搜索帮助