Add v2 network package

This commit is contained in:
9seconds
2026-02-27 15:50:21 +01:00
parent 282896be09
commit 42927c8bdc
15 changed files with 714 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
package network
import (
"fmt"
"net"
)
func setCommonSocketOptions(conn *net.TCPConn) error {
if err := conn.SetKeepAlivePeriod(DefaultTCPKeepAlivePeriod); err != nil {
return fmt.Errorf("cannot set time period of TCP keepalive probes: %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)
}
return nil
}