From 208ed3c538e9ea2f4027b6976c4f689ba28035fd Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 17 Dec 2025 12:25:25 -0500 Subject: [PATCH] Fix `select` / `fdset` usage on Windows These functions use `SOCKET` not `int`, despite them being unix functions. --- src/libutil/serialise.cc | 10 +++++----- src/nix/unix/daemon.cc | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index 9791b4fed..e71ec66d2 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -1,6 +1,7 @@ #include "nix/util/serialise.hh" #include "nix/util/compression.hh" #include "nix/util/signals.hh" +#include "nix/util/socket.hh" #include "nix/util/util.hh" #include @@ -11,7 +12,6 @@ #ifdef _WIN32 # include -# include # include "nix/util/windows-error.hh" #else # include @@ -184,20 +184,20 @@ bool FdSource::hasData() while (true) { fd_set fds; FD_ZERO(&fds); - int fd_ = fromDescriptorReadOnly(fd); - FD_SET(fd_, &fds); + Socket sock = toSocket(fd); + FD_SET(sock, &fds); struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 0; - auto n = select(fd_ + 1, &fds, nullptr, nullptr, &timeout); + auto n = select(sock + 1, &fds, nullptr, nullptr, &timeout); if (n < 0) { if (errno == EINTR) continue; throw SysError("polling file descriptor"); } - return FD_ISSET(fd, &fds); + return FD_ISSET(sock, &fds); } } diff --git a/src/nix/unix/daemon.cc b/src/nix/unix/daemon.cc index 406258ff8..661488c56 100644 --- a/src/nix/unix/daemon.cc +++ b/src/nix/unix/daemon.cc @@ -437,22 +437,23 @@ static void forwardStdioConnection(RemoteStore & store) int from = conn->from.fd; int to = conn->to.fd; - auto nfds = std::max(from, STDIN_FILENO) + 1; + Socket fromSock = toSocket(from), stdinSock = toSocket(getStandardInput()); + auto nfds = std::max(fromSock, stdinSock) + 1; while (true) { fd_set fds; FD_ZERO(&fds); - FD_SET(from, &fds); - FD_SET(STDIN_FILENO, &fds); + FD_SET(fromSock, &fds); + FD_SET(stdinSock, &fds); if (select(nfds, &fds, nullptr, nullptr, nullptr) == -1) throw SysError("waiting for data from client or server"); - if (FD_ISSET(from, &fds)) { + if (FD_ISSET(fromSock, &fds)) { auto res = splice(from, nullptr, STDOUT_FILENO, nullptr, SSIZE_MAX, SPLICE_F_MOVE); if (res == -1) throw SysError("splicing data from daemon socket to stdout"); else if (res == 0) throw EndOfFile("unexpected EOF from daemon socket"); } - if (FD_ISSET(STDIN_FILENO, &fds)) { + if (FD_ISSET(stdinSock, &fds)) { auto res = splice(STDIN_FILENO, nullptr, to, nullptr, SSIZE_MAX, SPLICE_F_MOVE); if (res == -1) throw SysError("splicing data from stdin to daemon socket");