| 763 | |
| 764 | #ifdef _WIN32 |
| 765 | static BOOL CreatePipeOverlapped(HANDLE *outReadPipe, HANDLE *outWritePipe, |
| 766 | SECURITY_ATTRIBUTES *securityAttributes, DWORD size, DWORD readMode, DWORD writeMode) |
| 767 | { |
| 768 | static LONG pipeIndex = 0; |
| 769 | |
| 770 | if (size == 0) |
| 771 | size = 8192; |
| 772 | |
| 773 | LONG currentIndex = InterlockedIncrement(&pipeIndex); |
| 774 | |
| 775 | char pipeName[128]; |
| 776 | sprintf(pipeName, "\\\\.\\Pipe\\OverlappedPipe.%d.%d", (int)GetCurrentProcessId(), (int)currentIndex); |
| 777 | |
| 778 | *outReadPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_INBOUND | readMode, |
| 779 | PIPE_TYPE_BYTE | PIPE_WAIT, 1, size, size, 60 * 1000, securityAttributes); |
| 780 | |
| 781 | if (*outReadPipe == INVALID_HANDLE_VALUE) |
| 782 | return FALSE; |
| 783 | |
| 784 | *outWritePipe = CreateFile(pipeName, GENERIC_WRITE, 0, securityAttributes, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | writeMode, nullptr); |
| 785 | |
| 786 | if (*outWritePipe == INVALID_HANDLE_VALUE) { |
| 787 | DWORD error = GetLastError(); |
| 788 | CloseHandle(*outReadPipe); |
| 789 | SetLastError(error); |
| 790 | return FALSE; |
| 791 | } |
| 792 | |
| 793 | return TRUE; |
| 794 | } |
| 795 | #endif /* _WIN32 */ |
| 796 | |
| 797 | void Process::Run(const std::function<void(const ProcessResult&)>& callback) |