Source file src/net/tcpsock_unix.go

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build (!windows && !solaris) || illumos
     6  
     7  package net
     8  
     9  import "syscall"
    10  
    11  // SetKeepAliveConfig configures keep-alive messages sent by the operating system.
    12  func (c *TCPConn) SetKeepAliveConfig(config KeepAliveConfig) error {
    13  	if !c.ok() {
    14  		return syscall.EINVAL
    15  	}
    16  
    17  	if err := setKeepAlive(c.fd, config.Enable); err != nil {
    18  		return &OpError{Op: "set", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
    19  	}
    20  	if err := setKeepAliveIdle(c.fd, config.Idle); err != nil {
    21  		return &OpError{Op: "set", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
    22  	}
    23  	if err := setKeepAliveInterval(c.fd, config.Interval); err != nil {
    24  		return &OpError{Op: "set", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
    25  	}
    26  	if err := setKeepAliveCount(c.fd, config.Count); err != nil {
    27  		return &OpError{Op: "set", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
    28  	}
    29  
    30  	return nil
    31  }
    32  

View as plain text