summaryrefslogtreecommitdiff
path: root/ot_socket.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-30 13:23:39 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-30 13:23:39 +0100
commit31d2586e3296d424e51848ada963299b0da89324 (patch)
tree203190931bc0d189653570d2ce526b1eb0695cb9 /ot_socket.c
parentcbf4b60df6c6c8c7208dc29708677d24b2724deb (diff)
Defer accepts until some data actually is there
Diffstat (limited to 'ot_socket.c')
-rw-r--r--ot_socket.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/ot_socket.c b/ot_socket.c
index 47ed26d..78a16d2 100644
--- a/ot_socket.c
+++ b/ot_socket.c
@@ -8,6 +8,7 @@
8#include <errno.h> 8#include <errno.h>
9#include <fcntl.h> 9#include <fcntl.h>
10#include <netinet/in.h> 10#include <netinet/in.h>
11#include <netinet/tcp.h>
11#include <string.h> 12#include <string.h>
12#include <sys/socket.h> 13#include <sys/socket.h>
13#include <unistd.h> 14#include <unistd.h>
@@ -120,6 +121,25 @@ static int socket_bind_v6(int s, const ot_ip6 ip, uint16_t port, socket_sharing
120 return bind(s, (struct sockaddr *)&sa, sizeof(sa)); 121 return bind(s, (struct sockaddr *)&sa, sizeof(sa));
121} 122}
122 123
124/* Defer the listening socket reporting it to be ready to accept until enough
125 sensible data is available for an accept+read pair. Where available. */
126int socket_defer_accept(int s) {
127#if defined(TCP_DEFER_ACCEPT)
128 int patience = OT_CLIENT_TIMEOUT;
129
130 return setsockopt(s, IPPROTO_TCP, TCP_DEFER_ACCEPT, &patience, sizeof(patience));
131#elif defined(SO_ACCEPTFILTER)
132 struct accept_filter_arg filter;
133
134 memset(&filter, 0, sizeof(filter));
135 strcpy(filter.af_name, "httpready");
136 return setsockopt(s, SOL_SOCKET, SO_ACCEPTFILTER, &filter, sizeof(filter));
137#else
138 (void)s;
139 return -1;
140#endif
141}
142
123int socket_tcp_listen(const ot_ip6 ip, uint16_t port, socket_sharing sharing) { 143int socket_tcp_listen(const ot_ip6 ip, uint16_t port, socket_sharing sharing) {
124 int s = socket_v6(SOCK_STREAM); 144 int s = socket_v6(SOCK_STREAM);
125 145