diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-11 12:29:43 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-11 12:29:43 +0200 |
commit | ca46c321915798818d6716fb5c2be9f538f2e722 (patch) | |
tree | 2829c64a3ac37bb43133bc7cf8bd7b8dccc31048 /utils.c | |
parent | c07081da8f8faa400e28c3febcfb38430ec5d0ad (diff) |
Add some socket options to minecraft protocol sockets
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) { |