mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-06 05:17:49 +00:00
6ff74cfcab
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3371
29 lines
533 B
Go
29 lines
533 B
Go
// Copyright (C) 2015 Audrius Butkevicius and Contributors.
|
|
|
|
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
|
|
}
|