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:
commit
915db74dbf
7 changed files with 69 additions and 52 deletions
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue