15#include "llvm/ADT/STLExtras.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/ConvertUTF.h"
54 ::CreateEvent(NULL, TRUE, FALSE, NULL);
64 LLDB_LOGF(log,
"%p ConnectionGenericFile::Connect (url = '%s')",
65 static_cast<void *
>(
this), path.str().c_str());
67 if (!path.consume_front(
"file://")) {
70 "unsupported connection URL: '%s'", path.str().c_str());
85 if (!llvm::ConvertUTF8toWide(path, wpath)) {
90 m_file = ::CreateFileW(wpath.c_str(), GENERIC_READ | GENERIC_WRITE,
91 FILE_SHARE_READ, NULL, OPEN_ALWAYS,
92 FILE_FLAG_OVERLAPPED, NULL);
93 if (
m_file == INVALID_HANDLE_VALUE) {
106 LLDB_LOGF(log,
"%p ConnectionGenericFile::Disconnect ()",
107 static_cast<void *
>(
this));
115 m_file = INVALID_HANDLE_VALUE;
124 ::CloseHandle(old_file);
152 "%p ConnectionGenericFile::Read() handle = %p, dst = %p, "
153 "dst_len = %zu) => %zu, error = %s",
154 static_cast<void *
>(
this),
m_file, dst, dst_len, bytes,
163 BOOL read_result = FALSE;
164 DWORD read_error = ERROR_SUCCESS;
168 read_error = ::GetLastError();
171 if (!
m_read_pending && !read_result && read_error != ERROR_IO_PENDING) {
172 if (read_error == ERROR_BROKEN_PIPE) {
185 ? std::chrono::duration_cast<std::chrono::milliseconds>(*timeout)
188 DWORD wait_result = ::WaitForMultipleObjects(
192 switch (wait_result) {
205 DWORD bytes_read = 0;
207 DWORD result_error = ::GetLastError();
211 if (result_error == ERROR_HANDLE_EOF ||
212 result_error == ERROR_OPERATION_ABORTED ||
213 result_error == ERROR_BROKEN_PIPE)
236 "%p ConnectionGenericFile::Write() handle = %p, src = %p, "
237 "src_len = %zu) => %zu, error = %s",
238 static_cast<void *
>(
this),
m_file, src, src_len, bytes,
248 DWORD bytes_written = 0;
250 if (!result && ::GetLastError() != ERROR_IO_PENDING)
266 LARGE_INTEGER old_pos;
269 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.