From 1ae6378d857c5ff4f0ee8dbc6165b5337f139290 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 10 Jan 2022 17:59:38 +0100 Subject: [PATCH] event/ServerSocket: add ip_tos setting --- src/event/ServerSocket.cxx | 12 ++++++++++-- src/event/ServerSocket.hxx | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/event/ServerSocket.cxx b/src/event/ServerSocket.cxx index a5d9abec3..77557db1d 100644 --- a/src/event/ServerSocket.cxx +++ b/src/event/ServerSocket.cxx @@ -17,7 +17,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "config.h" #include "ServerSocket.hxx" #include "lib/fmt/ExceptionFormatter.hxx" #include "net/IPv4Address.hxx" @@ -36,7 +35,6 @@ #include "util/Domain.hxx" #include "Log.hxx" -#include #include #include @@ -183,6 +181,16 @@ ServerSocket::OneServerSocket::Open() SOCK_STREAM, 0, address, 5); +#ifdef HAVE_TCP + if (parent.ip_tos >= 0 && address.GetFamily() == AF_INET && + !_fd.SetIntOption(IPPROTO_IP, IP_TOS, parent.ip_tos)) { + const SocketErrorMessage msg; + FmtError(server_socket_domain, + "Could not set TOS option: {}", + (const char *)msg); + } +#endif + #ifdef HAVE_UN /* allow everybody to connect */ diff --git a/src/event/ServerSocket.hxx b/src/event/ServerSocket.hxx index b34eb70ea..56bdf40d7 100644 --- a/src/event/ServerSocket.hxx +++ b/src/event/ServerSocket.hxx @@ -20,6 +20,9 @@ #ifndef MPD_SERVER_SOCKET_HXX #define MPD_SERVER_SOCKET_HXX +#include "config.h" + +#include #include class SocketAddress; @@ -38,6 +41,14 @@ class ServerSocket { std::list sockets; +#ifdef HAVE_TCP + /** + * A non-negative value sets the IPPROTO_IP/IP_TOS socket + * option. + */ + int ip_tos = -1; +#endif + unsigned next_serial = 1; public: @@ -48,6 +59,14 @@ public: return loop; } +#ifdef HAVE_TCP + void SetIpTos(int _ip_tos) noexcept { + assert(sockets.empty()); + + ip_tos = _ip_tos; + } +#endif + private: template OneServerSocket &AddAddress(A &&address) noexcept;