lib/connections: Support setting traffic class (fixes #3790)
This commit is contained in:
committed by
Jakob Borg
parent
9e7d50bc76
commit
9e0afb7d8a
@@ -10,6 +10,9 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/ipv4"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
// Dial tries dialing via proxy if a proxy is configured, and falls back to
|
||||
@@ -75,3 +78,22 @@ func SetTCPOptions(conn net.Conn) error {
|
||||
return fmt.Errorf("unknown connection type %T", conn)
|
||||
}
|
||||
}
|
||||
|
||||
func SetTrafficClass(conn net.Conn, class int) error {
|
||||
switch conn := conn.(type) {
|
||||
case *net.TCPConn:
|
||||
e1 := ipv4.NewConn(conn).SetTOS(class)
|
||||
e2 := ipv6.NewConn(conn).SetTrafficClass(class)
|
||||
|
||||
if e1 != nil {
|
||||
return e1
|
||||
}
|
||||
return e2
|
||||
|
||||
case dialerConn:
|
||||
return SetTrafficClass(conn.Conn, class)
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown connection type %T", conn)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user