git-subtree-dir: lib/relaysrv git-subtree-mainline: 4316992d95df9ece6d90d5a9993243050a79e6b6 git-subtree-split: 6e126fb97e2ff566d35f8d8824e86793d22b2147
29 lines
561 B
Go
29 lines
561 B
Go
// Copyright (C) 2015 Audrius Butkevicius and Contributors (see the CONTRIBUTORS file).
|
|
|
|
package main
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
)
|
|
|
|
func setTCPOptions(conn net.Conn) error {
|
|
tcpConn, ok := conn.(*net.TCPConn)
|
|
if !ok {
|
|
return errors.New("Not a TCP connection")
|
|
}
|
|
if err := tcpConn.SetLinger(0); err != nil {
|
|
return err
|
|
}
|
|
if err := tcpConn.SetNoDelay(true); err != nil {
|
|
return err
|
|
}
|
|
if err := tcpConn.SetKeepAlivePeriod(networkTimeout); err != nil {
|
|
return err
|
|
}
|
|
if err := tcpConn.SetKeepAlive(true); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|