From ca46c321915798818d6716fb5c2be9f538f2e722 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Thu, 11 Jun 2020 12:29:43 +0200 Subject: Add some socket options to minecraft protocol sockets --- utils.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'utils.c') diff --git a/utils.c b/utils.c index 39f91f1..93bc0b8 100644 --- a/utils.c +++ b/utils.c @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #include "main.h" #include "utils.h" @@ -155,6 +158,30 @@ debug_resource_usage() } } +void +socket_set_gaming_options(struct cfg *cfg, int sfd) +{ + int option; + + if (sfd <= 0) + return; + + /* FIXME: could make this configurable */ + option = true; + if (setsockopt(sfd, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option)) < 0) + perror("setsockopt"); + + /* Doubtful if it has much effect, but can't hurt */ + option = IPTOS_LOWDELAY; + if (setsockopt(sfd, IPPROTO_IP, IP_TOS, &option, sizeof(option)) < 0) + perror("setsockopt"); + + /* Nagle's algorithm is a poor fit for gaming */ + option = true; + if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, &option, sizeof(option)) < 0) + perror("setsockopt"); +} + uint16_t sockaddr_port(struct sockaddr_in46 *addr) { switch (addr->storage.ss_family) { -- cgit v1.2.3