mirror of
https://github.com/NixOS/nix
synced 2025-06-28 09:31:16 +02:00
Start building the scheduler for Windows
Building derivations is a lot harder, but the downloading goals is portable enough. The "common channel" code is due to Volth. I wonder if there is a way we can factor it out into separate functions / files to avoid some within-function CPP. Co-authored-by: volth <volth@volth.com>
This commit is contained in:
parent
87ab3c0ea4
commit
39b2a399ad
25 changed files with 285 additions and 94 deletions
43
src/libutil/windows/windows-async-pipe.cc
Normal file
43
src/libutil/windows/windows-async-pipe.cc
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "windows-async-pipe.hh"
|
||||
#include "windows-error.hh"
|
||||
|
||||
namespace nix::windows {
|
||||
|
||||
void AsyncPipe::createAsyncPipe(HANDLE iocp)
|
||||
{
|
||||
// std::cerr << (format("-----AsyncPipe::createAsyncPipe(%x)") % iocp) << std::endl;
|
||||
|
||||
buffer.resize(0x1000);
|
||||
memset(&overlapped, 0, sizeof(overlapped));
|
||||
|
||||
std::string pipeName = fmt("\\\\.\\pipe\\nix-%d-%p", GetCurrentProcessId(), (void *) this);
|
||||
|
||||
readSide = CreateNamedPipeA(
|
||||
pipeName.c_str(), PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, PIPE_UNLIMITED_INSTANCES, 0, 0,
|
||||
INFINITE, NULL);
|
||||
if (!readSide)
|
||||
throw WinError("CreateNamedPipeA(%s)", pipeName);
|
||||
|
||||
HANDLE hIocp = CreateIoCompletionPort(readSide.get(), iocp, (ULONG_PTR) (readSide.get()) ^ 0x5555, 0);
|
||||
if (hIocp != iocp)
|
||||
throw WinError("CreateIoCompletionPort(%x[%s], %x, ...) returned %x", readSide.get(), pipeName, iocp, hIocp);
|
||||
|
||||
if (!ConnectNamedPipe(readSide.get(), &overlapped) && GetLastError() != ERROR_IO_PENDING)
|
||||
throw WinError("ConnectNamedPipe(%s)", pipeName);
|
||||
|
||||
SECURITY_ATTRIBUTES psa2 = {0};
|
||||
psa2.nLength = sizeof(SECURITY_ATTRIBUTES);
|
||||
psa2.bInheritHandle = TRUE;
|
||||
|
||||
writeSide = CreateFileA(pipeName.c_str(), GENERIC_WRITE, 0, &psa2, OPEN_EXISTING, 0, NULL);
|
||||
if (!readSide)
|
||||
throw WinError("CreateFileA(%s)", pipeName);
|
||||
}
|
||||
|
||||
void AsyncPipe::close()
|
||||
{
|
||||
readSide.close();
|
||||
writeSide.close();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue