utils.go 533 B

1234567891011121314151617181920212223242526272829
  1. // Copyright (C) 2015 Audrius Butkevicius and Contributors.
  2. package main
  3. import (
  4. "errors"
  5. "net"
  6. )
  7. func setTCPOptions(conn net.Conn) error {
  8. tcpConn, ok := conn.(*net.TCPConn)
  9. if !ok {
  10. return errors.New("Not a TCP connection")
  11. }
  12. if err := tcpConn.SetLinger(0); err != nil {
  13. return err
  14. }
  15. if err := tcpConn.SetNoDelay(true); err != nil {
  16. return err
  17. }
  18. if err := tcpConn.SetKeepAlivePeriod(networkTimeout); err != nil {
  19. return err
  20. }
  21. if err := tcpConn.SetKeepAlive(true); err != nil {
  22. return err
  23. }
  24. return nil
  25. }