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),
49 m_read_fd = _open_osfhandle((intptr_t)read, _O_RDONLY);
52 m_read = INVALID_HANDLE_VALUE;
56 m_write_fd = _open_osfhandle((intptr_t)write, _O_WRONLY);
75 std::string pipe_name = llvm::formatv(
76 "lldb.pipe.{0}.{1}.{2}", GetCurrentProcessId(), &
g_pipe_serial, serial);
89 pipe_path.append(name.str());
93 SECURITY_ATTRIBUTES sa{
sizeof(SECURITY_ATTRIBUTES), 0, TRUE};
97 DWORD read_mode = FILE_FLAG_OVERLAPPED;
99 ::CreateNamedPipeA(pipe_path.c_str(), PIPE_ACCESS_INBOUND | read_mode,
100 PIPE_TYPE_BYTE | PIPE_WAIT, 1,
104 if (INVALID_HANDLE_VALUE ==
m_read)
109 m_read = INVALID_HANDLE_VALUE;
128 llvm::SmallString<128> pipe_name;
131 RPC_CSTR unique_string;
132 RPC_STATUS status = ::UuidCreate(&unique_id);
133 if (status == RPC_S_OK || status == RPC_S_UUID_LOCAL_ONLY)
134 status = ::UuidToStringA(&unique_id, &unique_string);
135 if (status == RPC_S_OK) {
138 pipe_name +=
reinterpret_cast<char *
>(unique_string);
139 ::RpcStringFreeA(&unique_string);
159 return llvm::Error::success();
172 SECURITY_ATTRIBUTES attributes{
sizeof(SECURITY_ATTRIBUTES), 0, TRUE};
175 pipe_path.append(name.str());
178 m_read = ::CreateFileA(pipe_path.c_str(), GENERIC_READ, 0, &attributes,
179 OPEN_EXISTING, FILE_FLAG_OVERLAPPED,
nullptr);
180 if (INVALID_HANDLE_VALUE ==
m_read)
186 m_read = INVALID_HANDLE_VALUE;
193 m_write = ::CreateFileA(pipe_path.c_str(), GENERIC_WRITE, 0, &attributes,
194 OPEN_EXISTING, FILE_FLAG_OVERLAPPED,
nullptr);
195 if (INVALID_HANDLE_VALUE ==
m_write)
201 m_write = INVALID_HANDLE_VALUE;
223 m_read = INVALID_HANDLE_VALUE;
235 m_write = INVALID_HANDLE_VALUE;
248 m_read = INVALID_HANDLE_VALUE;
261 m_write = INVALID_HANDLE_VALUE;
288 DWORD bytes_read = 0;
293 DWORD failure_error = ::GetLastError();
294 if (failure_error != ERROR_IO_PENDING)
298 timeout ? std::chrono::ceil<std::chrono::milliseconds>(*timeout).count()
302 if (wait_result != WAIT_OBJECT_0) {
310 failure_error = ::GetLastError();
311 if (wait_result == WAIT_TIMEOUT) {
313 if (!cancel_result && ::GetLastError() == ERROR_NOT_FOUND)
333 DWORD bytes_written = 0;
337 return bytes_written;
339 DWORD failure_error = ::GetLastError();
340 if (failure_error != ERROR_IO_PENDING)
344 timeout ? std::chrono::ceil<std::chrono::milliseconds>(*timeout).count()
348 if (wait_result != WAIT_OBJECT_0) {
356 failure_error = ::GetLastError();
357 if (wait_result == WAIT_TIMEOUT) {
359 if (!cancel_result && ::GetLastError() == ERROR_NOT_FOUND)
372 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.