15#include "llvm/ADT/STLExtras.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/ConvertUTF.h"
46 CreateEvent(
nullptr, FALSE, FALSE,
nullptr);
55 ::CreateEvent(
nullptr, TRUE, FALSE,
nullptr);
65 LLDB_LOGF(log,
"%p ConnectionGenericFile::Connect (url = '%s')",
66 static_cast<void *
>(
this), path.str().c_str());
68 if (!path.consume_front(
"file://")) {
71 "unsupported connection URL: '%s'", path.str().c_str());
86 if (!llvm::ConvertUTF8toWide(path, wpath)) {
91 m_file = ::CreateFileW(wpath.c_str(), GENERIC_READ | GENERIC_WRITE,
92 FILE_SHARE_READ,
nullptr, OPEN_ALWAYS,
93 FILE_FLAG_OVERLAPPED,
nullptr);
94 if (
m_file == INVALID_HANDLE_VALUE) {
107 LLDB_LOGF(log,
"%p ConnectionGenericFile::Disconnect ()",
108 static_cast<void *
>(
this));
116 m_file = INVALID_HANDLE_VALUE;
125 ::CloseHandle(old_file);
153 "%p ConnectionGenericFile::Read() handle = %p, dst = %p, "
154 "dst_len = %zu) => %zu, error = %s",
155 static_cast<void *
>(
this),
m_file, dst, dst_len, bytes,
164 BOOL read_result = FALSE;
165 DWORD read_error = ERROR_SUCCESS;
169 read_error = ::GetLastError();
172 if (!
m_read_pending && !read_result && read_error != ERROR_IO_PENDING) {
173 if (read_error == ERROR_BROKEN_PIPE) {
186 ? std::chrono::duration_cast<std::chrono::milliseconds>(*timeout)
189 DWORD wait_result = ::WaitForMultipleObjects(
193 switch (wait_result) {
206 DWORD bytes_read = 0;
208 DWORD result_error = ::GetLastError();
212 if (result_error == ERROR_HANDLE_EOF ||
213 result_error == ERROR_OPERATION_ABORTED ||
214 result_error == ERROR_BROKEN_PIPE)
237 "%p ConnectionGenericFile::Write() handle = %p, src = %p, "
238 "src_len = %zu) => %zu, error = %s",
239 static_cast<void *
>(
this),
m_file, src, src_len, bytes,
249 DWORD bytes_written = 0;
251 if (!result && ::GetLastError() != ERROR_IO_PENDING)
267 LARGE_INTEGER old_pos;
270 old_pos.QuadPart += amount;
#define LLDB_LOGF(log,...)
lldb::ConnectionStatus Disconnect(Status *error_ptr) override
Disconnect the communications connection if one is currently connected.
void InitializeEventHandles()
~ConnectionGenericFile() override
lldb::ConnectionStatus Connect(llvm::StringRef s, Status *error_ptr) override
Connect using the connect string url.
size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr) override
The actual write function that attempts to write to the communications protocol.
LARGE_INTEGER m_file_position
void IncrementFilePointer(DWORD amount)
size_t Read(void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr) override
The read function that attempts to read from the connection.
bool IsConnected() const override
Check if the connection is valid.
bool InterruptRead() override
Interrupts an ongoing Read() operation.
HANDLE m_event_handles[2]
std::string GetURI() override
Returns a URI that describes this connection object.
void Clear()
Clear the object state.
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
ConnectionStatus
Connection Status Types.
@ eConnectionStatusError
Check GetError() for details.
@ eConnectionStatusInterrupted
Interrupted read.
@ eConnectionStatusTimedOut
Request timed out.
@ eConnectionStatusEndOfFile
End-of-file encountered.
@ eConnectionStatusSuccess
Success.
@ eConnectionStatusNoConnection
No connection.
@ eErrorTypeGeneric
Generic errors that can be any value.
@ eErrorTypeWin32
Standard Win32 error codes.