15#include "llvm/ADT/STLExtras.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/ConvertUTF.h"
37 m_error.SetErrorString(error_msg.data());
42 size_t GetBytes()
const {
return m_bytes; }
44 const Status &GetError()
const {
return m_error; }
54 : m_file(INVALID_HANDLE_VALUE), m_owns_file(false) {
61 : m_file(file), m_owns_file(owns_file) {
85 ::CreateEvent(NULL, TRUE, FALSE, NULL);
95 LLDB_LOGF(log,
"%p ConnectionGenericFile::Connect (url = '%s')",
96 static_cast<void *
>(
this), path.str().c_str());
98 if (!path.consume_front(
"file://")) {
116 if (!llvm::ConvertUTF8toWide(path, wpath)) {
121 m_file = ::CreateFileW(wpath.c_str(), GENERIC_READ | GENERIC_WRITE,
122 FILE_SHARE_READ, NULL, OPEN_ALWAYS,
123 FILE_FLAG_OVERLAPPED, NULL);
124 if (
m_file == INVALID_HANDLE_VALUE) {
137 LLDB_LOGF(log,
"%p ConnectionGenericFile::Disconnect ()",
138 static_cast<void *
>(
this));
146 m_file = INVALID_HANDLE_VALUE;
155 ::CloseHandle(old_file);
167 ReturnInfo return_info;
169 DWORD bytes_read = 0;
182 if (result || ::GetLastError() == ERROR_IO_PENDING) {
188 ? std::chrono::duration_cast<std::chrono::milliseconds>(*timeout)
191 DWORD wait_result = ::WaitForMultipleObjects(
195 switch (wait_result) {
211 DWORD result_error = ::GetLastError();
215 if (result_error == ERROR_HANDLE_EOF ||
216 result_error == ERROR_OPERATION_ABORTED ||
217 result_error == ERROR_BROKEN_PIPE)
221 }
else if (bytes_read == 0)
227 }
else if (::GetLastError() == ERROR_BROKEN_PIPE) {
237 status = return_info.GetStatus();
239 *error_ptr = return_info.GetError();
249 "%p ConnectionGenericFile::Read() handle = %p, dst = %p, "
250 "dst_len = %zu) => %zu, error = %s",
251 static_cast<void *
>(
this),
m_file, dst, dst_len,
252 return_info.GetBytes(), return_info.GetError().AsCString());
254 return return_info.GetBytes();
260 ReturnInfo return_info;
261 DWORD bytes_written = 0;
277 if (!result && ::GetLastError() != ERROR_IO_PENDING) {
291 status = return_info.GetStatus();
293 *error_ptr = return_info.
GetError();
298 "%p ConnectionGenericFile::Write() handle = %p, src = %p, "
299 "src_len = %zu) => %zu, error = %s",
300 static_cast<void *
>(
this),
m_file, src, src_len,
301 return_info.GetBytes(), return_info.GetError().AsCString());
302 return return_info.GetBytes();
312 LARGE_INTEGER old_pos;
315 old_pos.QuadPart += amount;
#define LLDB_LOGF(log,...)
static uint32_t GetBytes(uint32_t bits)
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.
ValueType GetError() const
Access the error value.
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
int void SetError(ValueType err, lldb::ErrorType type)
Set accessor with an error value and type.
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.