mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 22:24:02 +03:00
FILE / ScuroNeko/mtg
network/v2/sockopts.go
Исходный файл и его история в репозитории.
31 lines
733 B
Go
31 lines
733 B
Go
package network
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
func setCommonSocketOptions(conn *net.TCPConn, keepAliveConfig net.KeepAliveConfig) error {
|
|
if err := conn.SetKeepAliveConfig(keepAliveConfig); err != nil {
|
|
return fmt.Errorf("cannot configure TCP keepalive: %w", err)
|
|
}
|
|
|
|
if err := conn.SetLinger(tcpLingerTimeout); err != nil {
|
|
return fmt.Errorf("cannot set TCP linger timeout: %w", err)
|
|
}
|
|
|
|
rawConn, err := conn.SyscallConn()
|
|
if err != nil {
|
|
return fmt.Errorf("cannot get underlying raw connection: %w", err)
|
|
}
|
|
|
|
if err := setSocketReuseAddrPort(rawConn); err != nil {
|
|
return fmt.Errorf("cannot setup SO_REUSEADDR/PORT: %w", err)
|
|
}
|
|
|
|
setCongestionControl(rawConn)
|
|
setTCPUserTimeout(rawConn, keepAliveConfig)
|
|
|
|
return nil
|
|
}
|