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 <cassert>
 #include <string>
 #include <utility>
 
@@ -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 <cassert>
 #include <list>
 
 class SocketAddress;
@@ -38,6 +41,14 @@ class ServerSocket {
 
 	std::list<OneServerSocket> 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<typename A>
 	OneServerSocket &AddAddress(A &&address) noexcept;