1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-12 06:35:08 +02:00

Merge pull request #11343 from DeterminateSystems/no-framedsink-threads

withFramedSink(): Don't use a thread to monitor the other side
This commit is contained in:
Eelco Dolstra 2024-08-22 14:23:19 +02:00 committed by GitHub
commit 915db74dbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 69 additions and 52 deletions

View file

@ -10,6 +10,8 @@
#ifdef _WIN32
# include <fileapi.h>
# include "windows-error.hh"
#else
# include <poll.h>
#endif
@ -158,6 +160,29 @@ bool FdSource::good()
}
bool FdSource::hasData()
{
if (BufferedSource::hasData()) return true;
while (true) {
fd_set fds;
FD_ZERO(&fds);
FD_SET(fd, &fds);
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 0;
auto n = select(fd + 1, &fds, nullptr, nullptr, &timeout);
if (n < 0) {
if (errno == EINTR) continue;
throw SysError("polling file descriptor");
}
return FD_ISSET(fd, &fds);
}
}
size_t StringSource::read(char * data, size_t len)
{
if (pos == s.size()) throw EndOfFile("end of string reached");