summaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 95350421..8f444336 100644
--- a/src/util.c
+++ b/src/util.c
@@ -7,6 +7,8 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
+#include <netinet/tcp.h>
+#include <netinet/ip.h>
#include "util.h"
@@ -83,3 +85,42 @@ fail:
rmdir(dir);
return -1;
}
+
+int make_socket_low_delay(int fd) {
+ int ret = 0, buf_size, priority;
+
+ assert(fd >= 0);
+
+ buf_size = 1024;
+ if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &buf_size, sizeof(buf_size)) < 0)
+ ret = -1;
+
+ buf_size = 1024;
+ if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &buf_size, sizeof(buf_size)) < 0)
+ ret = -1;
+
+ priority = 7;
+ if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority)) < 0)
+ ret = -1;
+
+ return ret;
+}
+
+int make_tcp_socket_low_delay(int fd) {
+ int ret, tos, on;
+
+ assert(fd >= 0);
+
+ ret = make_socket_low_delay(fd);
+
+ on = 1;
+ if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &on, sizeof(on)) < 0)
+ ret = -1;
+
+ tos = IPTOS_LOWDELAY;
+ if (setsockopt(fd, SOL_IP, IP_TOS, &tos, sizeof(tos)) < 0)
+ ret = -1;
+
+ return ret;
+
+}