diff options
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -8,6 +8,9 @@ #include <dirent.h> #include <fcntl.h> #include <unistd.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netinet/tcp.h> #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) { |