summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-11 12:29:43 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-11 12:29:43 +0200
commitca46c321915798818d6716fb5c2be9f538f2e722 (patch)
tree2829c64a3ac37bb43133bc7cf8bd7b8dccc31048 /utils.c
parentc07081da8f8faa400e28c3febcfb38430ec5d0ad (diff)
Add some socket options to minecraft protocol sockets
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index 39f91f1..93bc0b8 100644
--- a/utils.c
+++ b/utils.c
@@ -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) {