ref: dafd86d6327602cb4c66d80f4e64488c03cd01e8
parent: c5c3a280df977057089d9c5574f01368def7c35c
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Jun 27 20:56:46 EDT 2022
9gc: disable Nagle
--- a/9gc.c
+++ b/9gc.c
@@ -3,6 +3,7 @@
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -117,7 +118,7 @@
{
struct addrinfo *r, *a, hint = {.ai_flags = AI_ADDRCONFIG, .ai_family = AF_UNSPEC, 0};
char host[64], *port;
- int e, f;
+ int e, f, yes;
if (strncmp(s, "udp!", 4) == 0) {
hint.ai_socktype = SOCK_DGRAM;
@@ -143,11 +144,14 @@
return -1;
}
f = -1;
+ yes = 1;
for (a = r; a != NULL; a = a->ai_next) {
if ((f = socket(a->ai_family, a->ai_socktype, a->ai_protocol)) < 0)
continue;
- if (connect(f, a->ai_addr, a->ai_addrlen) == 0)
+ if (connect(f, a->ai_addr, a->ai_addrlen) == 0) {
+ setsockopt(f, SOL_TCP, TCP_NODELAY, &yes, sizeof(yes));
break;
+ }
close(f);
f = -1;
}