summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViktor Szakats <commit@vsz.me>2025-08-03 23:48:53 +0200
committerViktor Szakats <commit@vsz.me>2025-08-05 00:34:24 +0200
commit06c12cc08b24cf74dc2c8b92ec9d545cb829f12a (patch)
tree862b8bb588f53a6d054da9f4c4894adc71acd9dc
parent74ba04f5b2f41f158919d6c5c6c04164b0a915ec (diff)
build: disable `TCP_NODELAY` for emscriptenHEADorigin/masterorigin/HEADmasterfor-upstream
In WebAssembly, using `TCP_NODELAY` fails with: ``` * Could not set TCP_NODELAY: Protocol not available ``` Add a new feature macro in `curl_setup.h` telling whether `TCP_NODELAY` is known to be supported at runtime, when defined at compile-time. Keep `TCP_NODELAY` guards at their current positions to ensure the necessary headers (e.g. `netinet/tcp.h` and `netinet/in.h`) define it. Reported-by: Jeroen Ooms Fixes #17974 Closes #18155
-rw-r--r--lib/cf-socket.c2
-rw-r--r--lib/curl_setup.h5
-rw-r--r--tests/server/rtspd.c2
-rw-r--r--tests/server/sws.c8
4 files changed, 11 insertions, 6 deletions
diff --git a/lib/cf-socket.c b/lib/cf-socket.c
index 7f3f8e60f..426caf82d 100644
--- a/lib/cf-socket.c
+++ b/lib/cf-socket.c
@@ -109,7 +109,7 @@ static void set_ipv6_v6only(curl_socket_t sockfd, int on)
static void tcpnodelay(struct Curl_easy *data, curl_socket_t sockfd)
{
-#ifdef TCP_NODELAY
+#if defined(TCP_NODELAY) && defined(CURL_TCP_NODELAY_SUPPORTED)
curl_socklen_t onoff = (curl_socklen_t) 1;
int level = IPPROTO_TCP;
char buffer[STRERROR_LEN];
diff --git a/lib/curl_setup.h b/lib/curl_setup.h
index 9b663fcb7..0a6591db8 100644
--- a/lib/curl_setup.h
+++ b/lib/curl_setup.h
@@ -1125,6 +1125,11 @@ int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
#define USE_HTTP3
#endif
+/* WebAssembly builds have TCP_NODELAY, but runtime support is missing. */
+#ifndef __EMSCRIPTEN__
+#define CURL_TCP_NODELAY_SUPPORTED
+#endif
+
/* Certain Windows implementations are not aligned with what curl expects,
so always use the local one on this platform. E.g. the mingw-w64
implementation can return wrong results for non-ASCII inputs. */
diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c
index d046fdf42..67829922d 100644
--- a/tests/server/rtspd.c
+++ b/tests/server/rtspd.c
@@ -1224,7 +1224,7 @@ static int test_rtspd(int argc, char *argv[])
logmsg("====> Client connect");
-#ifdef TCP_NODELAY
+#if defined(TCP_NODELAY) && !defined(__EMSCRIPTEN__)
/*
* Disable the Nagle algorithm to make it easier to send out a large
* response in many small segments to torture the clients more.
diff --git a/tests/server/sws.c b/tests/server/sws.c
index 2ae4727ad..2b94e5293 100644
--- a/tests/server/sws.c
+++ b/tests/server/sws.c
@@ -158,7 +158,7 @@ static const char *doc404 = "HTTP/1.1 404 Not Found\r\n"
/* work around for handling trailing headers */
static int already_recv_zeroed_chunk = FALSE;
-#ifdef TCP_NODELAY
+#if defined(TCP_NODELAY) && defined(CURL_TCP_NODELAY_SUPPORTED)
/* returns true if the current socket is an IP one */
static bool socket_domain_is_ip(void)
{
@@ -1239,7 +1239,7 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
return CURL_SOCKET_BAD;
}
-#ifdef TCP_NODELAY
+#if defined(TCP_NODELAY) && defined(CURL_TCP_NODELAY_SUPPORTED)
if(socket_domain_is_ip()) {
/* Disable the Nagle algorithm */
curl_socklen_t flag = 1;
@@ -1545,7 +1545,7 @@ static void http_connect(curl_socket_t *infdp,
}
memset(req2, 0, sizeof(*req2));
logmsg("====> Client connect DATA");
-#ifdef TCP_NODELAY
+#if defined(TCP_NODELAY) && defined(CURL_TCP_NODELAY_SUPPORTED)
if(socket_domain_is_ip()) {
/* Disable the Nagle algorithm */
curl_socklen_t flag = 1;
@@ -1871,7 +1871,7 @@ static curl_socket_t accept_connection(curl_socket_t sock)
all_sockets[num_sockets] = msgsock;
num_sockets += 1;
-#ifdef TCP_NODELAY
+#if defined(TCP_NODELAY) && defined(CURL_TCP_NODELAY_SUPPORTED)
if(socket_domain_is_ip()) {
/*
* Disable the Nagle algorithm to make it easier to send out a large