2016-06-02 12:16:02 +00:00
|
|
|
// Copyright (C) 2015 Audrius Butkevicius and Contributors.
|
2015-06-24 11:39:46 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2015-06-28 00:52:01 +00:00
|
|
|
if err := tcpConn.SetKeepAlivePeriod(networkTimeout); err != nil {
|
2015-06-24 11:39:46 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tcpConn.SetKeepAlive(true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|