event/ServerSocket: rename ip_tos to dscp_class and support IPv6

This commit is contained in:
Max Kellermann 2022-01-11 20:10:42 +01:00
parent 16f7ec9950
commit 219c416a1e
2 changed files with 17 additions and 11 deletions

View File

@ -182,12 +182,18 @@ ServerSocket::OneServerSocket::Open()
address, 5); address, 5);
#ifdef HAVE_TCP #ifdef HAVE_TCP
if (parent.ip_tos >= 0 && address.GetFamily() == AF_INET && if (parent.dscp_class >= 0) {
!_fd.SetIntOption(IPPROTO_IP, IP_TOS, parent.ip_tos)) { const int family = address.GetFamily();
const SocketErrorMessage msg; if ((family == AF_INET &&
FmtError(server_socket_domain, !_fd.SetIntOption(IPPROTO_IP, IP_TOS, parent.dscp_class)) ||
"Could not set TOS option: {}", (family == AF_INET6 &&
(const char *)msg); !_fd.SetIntOption(IPPROTO_IPV6, IPV6_TCLASS,
parent.dscp_class))) {
const SocketErrorMessage msg;
FmtError(server_socket_domain,
"Could not set DSCP class: {}",
(const char *)msg);
}
} }
#endif #endif

View File

@ -43,10 +43,10 @@ class ServerSocket {
#ifdef HAVE_TCP #ifdef HAVE_TCP
/** /**
* A non-negative value sets the IPPROTO_IP/IP_TOS socket * A non-negative value sets the IPPROTO_IP/IP_TOS or
* option. * IPPROTO_IPV6/IPV6_TCLASS socket option.
*/ */
int ip_tos = -1; int dscp_class = -1;
#endif #endif
unsigned next_serial = 1; unsigned next_serial = 1;
@ -60,10 +60,10 @@ public:
} }
#ifdef HAVE_TCP #ifdef HAVE_TCP
void SetIpTos(int _ip_tos) noexcept { void SetDscpClass(int _dscp_class) noexcept {
assert(sockets.empty()); assert(sockets.empty());
ip_tos = _ip_tos; dscp_class = _dscp_class;
} }
#endif #endif