11#include "llvm/ADT/SmallString.h"
12#include "llvm/Support/Process.h"
13#include "llvm/Support/raw_ostream.h"
29 :
m_read(INVALID_HANDLE_VALUE),
m_write(INVALID_HANDLE_VALUE),
48 m_read_fd = _open_osfhandle((intptr_t)read, _O_RDONLY);
51 m_read = INVALID_HANDLE_VALUE;
55 m_write_fd = _open_osfhandle((intptr_t)write, _O_WRONLY);
74 std::string pipe_name = llvm::formatv(
75 "lldb.pipe.{0}.{1}.{2}", GetCurrentProcessId(), &
g_pipe_serial, serial);
88 pipe_path.append(name.str());
92 SECURITY_ATTRIBUTES sa{
sizeof(SECURITY_ATTRIBUTES), 0, TRUE};
96 DWORD read_mode = FILE_FLAG_OVERLAPPED;
98 ::CreateNamedPipeA(pipe_path.c_str(), PIPE_ACCESS_INBOUND | read_mode,
99 PIPE_TYPE_BYTE | PIPE_WAIT, 1,
103 if (INVALID_HANDLE_VALUE ==
m_read)
122 llvm::SmallString<128> pipe_name;
125 RPC_CSTR unique_string;
126 RPC_STATUS status = ::UuidCreate(&unique_id);
127 if (status == RPC_S_OK || status == RPC_S_UUID_LOCAL_ONLY)
128 status = ::UuidToStringA(&unique_id, &unique_string);
129 if (status == RPC_S_OK) {
132 pipe_name +=
reinterpret_cast<char *
>(unique_string);
133 ::RpcStringFreeA(&unique_string);
153 return llvm::Error::success();
166 SECURITY_ATTRIBUTES attributes{
sizeof(SECURITY_ATTRIBUTES), 0, TRUE};
169 pipe_path.append(name.str());
172 m_read = ::CreateFileA(pipe_path.c_str(), GENERIC_READ, 0, &attributes,
173 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
174 if (INVALID_HANDLE_VALUE ==
m_read)
182 m_write = ::CreateFileA(pipe_path.c_str(), GENERIC_WRITE, 0, &attributes,
183 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
184 if (INVALID_HANDLE_VALUE ==
m_write)
207 m_read = INVALID_HANDLE_VALUE;
219 m_write = INVALID_HANDLE_VALUE;
232 m_read = INVALID_HANDLE_VALUE;
245 m_write = INVALID_HANDLE_VALUE;
272 DWORD bytes_read = 0;
277 DWORD failure_error = ::GetLastError();
278 if (failure_error != ERROR_IO_PENDING)
282 timeout ? std::chrono::ceil<std::chrono::milliseconds>(*timeout).count()
286 if (wait_result != WAIT_OBJECT_0) {
294 failure_error = ::GetLastError();
295 if (wait_result == WAIT_TIMEOUT) {
297 if (!cancel_result && ::GetLastError() == ERROR_NOT_FOUND)
317 DWORD bytes_written = 0;
321 return bytes_written;
323 DWORD failure_error = ::GetLastError();
324 if (failure_error != ERROR_IO_PENDING)
328 timeout ? std::chrono::ceil<std::chrono::milliseconds>(*timeout).count()
332 if (wait_result != WAIT_OBJECT_0) {
340 failure_error = ::GetLastError();
341 if (wait_result == WAIT_TIMEOUT) {
343 if (!cancel_result && ::GetLastError() == ERROR_NOT_FOUND)
356 return bytes_written;
static llvm::raw_ostream & error(Stream &strm)
static std::atomic< uint32_t > g_pipe_serial(0)
static constexpr llvm::StringLiteral g_pipe_name_prefix
bool CanWrite() const override
HANDLE GetWriteNativeHandle()
Status Delete(llvm::StringRef name) override
int ReleaseReadFileDescriptor() override
void CloseReadFileDescriptor() override
OVERLAPPED m_write_overlapped
Status OpenNamedPipe(llvm::StringRef name, bool is_read)
void CloseWriteFileDescriptor() override
OVERLAPPED m_read_overlapped
Status CreateNew() override
static const int kInvalidDescriptor
Status OpenAsReader(llvm::StringRef name) override
llvm::Expected< size_t > Read(void *buf, size_t size, const Timeout< std::micro > &timeout=std::nullopt) override
HANDLE GetReadNativeHandle()
llvm::Expected< size_t > Write(const void *buf, size_t size, const Timeout< std::micro > &timeout=std::nullopt) override
int ReleaseWriteFileDescriptor() override
int GetWriteFileDescriptor() const override
llvm::Error OpenAsWriter(llvm::StringRef name, const Timeout< std::micro > &timeout) override
int GetReadFileDescriptor() const override
Status CreateWithUniqueName(llvm::StringRef prefix, llvm::SmallVectorImpl< char > &name) override
bool CanRead() const override
bool Success() const
Test for success condition.
Represents UUID's of various sizes.
#define LLDB_INVALID_PIPE
A class that represents a running process on the host machine.
@ eErrorTypeWin32
Standard Win32 error codes.