lli: Factor portable messaging into a new RPCChannel facility

The client and server now use a single unified low-level RPC core built around
LLVM's existing cross-platform abstractions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199947 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alp Toker
2014-01-23 22:19:45 +00:00
parent 2f49a7b24b
commit 2a02d4bee3
9 changed files with 151 additions and 168 deletions

View File

@@ -15,6 +15,7 @@
#ifndef LLI_REMOTETARGETEXTERNAL_H
#define LLI_REMOTETARGETEXTERNAL_H
#include "RPCChannel.h"
#include "RemoteTarget.h"
#include "RemoteTargetMessage.h"
#include "llvm/ADT/SmallVector.h"
@@ -28,6 +29,28 @@
namespace llvm {
class RemoteTargetExternal : public RemoteTarget {
RPCChannel RPC;
bool WriteBytes(const void *Data, size_t Size) {
int rc = RPC.WriteBytes(Data, Size);
if (rc != -1 && (size_t)rc == Size)
return true;
ErrorMsg = "WriteBytes: ";
RPC.ReportError(rc, Size, ErrorMsg);
return false;
}
bool ReadBytes(void *Data, size_t Size) {
int rc = RPC.ReadBytes(Data, Size);
if (rc != -1 && (size_t)rc == Size)
return true;
ErrorMsg = "ReadBytes: ";
RPC.ReportError(rc, Size, ErrorMsg);
return false;
}
public:
/// Allocate space in the remote target address space.
///
@@ -79,17 +102,26 @@ public:
/// @returns Page alignment return value. Default of 4k.
virtual unsigned getPageAlignment() { return 4096; }
/// Start the remote process.
///
/// @returns True on success. On failure, ErrorMsg is updated with
/// descriptive text of the encountered error.
virtual bool create();
virtual bool create() {
RPC.ChildName = ChildName;
if (!RPC.createServer())
return true;
// We must get Ack from the client (blocking read)
if (!Receive(LLI_ChildActive)) {
ErrorMsg += ", (RPCChannel::create) - Stopping process!";
stop();
return false;
}
return true;
}
/// Terminate the remote process.
virtual void stop();
RemoteTargetExternal(std::string &Name) : RemoteTarget(), ChildName(Name) {}
virtual ~RemoteTargetExternal();
virtual ~RemoteTargetExternal() {}
private:
std::string ChildName;
@@ -119,13 +151,6 @@ private:
SmallVector<int, 2> Sizes;
void AppendWrite(const void *Data, uint32_t Size);
void AppendRead(void *Data, uint32_t Size);
// This will get filled in as a point to an OS-specific structure.
void *ConnectionData;
bool WriteBytes(const void *Data, size_t Size);
bool ReadBytes(void *Data, size_t Size);
void Wait();
};
} // end namespace llvm