diff --git a/c/builtins.c b/c/builtins.c index b736b7c..993d4bd 100644 --- a/c/builtins.c +++ b/c/builtins.c @@ -1224,6 +1224,12 @@ static Value bi_tcp_listen(Value *a, int n, Env *e) { if (fd < 0) return VAL_FALSE; int one = 1; setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); + /* SO_REUSEPORT lets N processes bind() the same port. Kernel hashes + incoming connections across the listening sockets so each accept() + returns a fresh client to whichever process is ready. Used by bend + to run multiple workers behind one port without an external + distributor. */ + setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)); struct sockaddr_in addr = {0}; addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY);