diff options
author | Alp Toker <alp@nuanti.com> | 2014-01-23 22:19:45 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2014-01-23 22:19:45 +0000 |
commit | 2a02d4bee3f683180a40b65a2c3833ceb64236c3 (patch) | |
tree | 89a2e96aafd4f6e946fa8c0f812d07f64c21501f /tools/lli/Unix | |
parent | 2f49a7b24b4adfed31855edeb9d1b3f0386c188b (diff) | |
download | llvm-2a02d4bee3f683180a40b65a2c3833ceb64236c3.tar.gz llvm-2a02d4bee3f683180a40b65a2c3833ceb64236c3.tar.bz2 llvm-2a02d4bee3f683180a40b65a2c3833ceb64236c3.tar.xz |
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
Diffstat (limited to 'tools/lli/Unix')
-rw-r--r-- | tools/lli/Unix/RPCChannel.inc (renamed from tools/lli/Unix/RemoteTargetExternal.inc) | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/tools/lli/Unix/RemoteTargetExternal.inc b/tools/lli/Unix/RPCChannel.inc index ea8e4597d5..b7dec37d93 100644 --- a/tools/lli/Unix/RemoteTargetExternal.inc +++ b/tools/lli/Unix/RPCChannel.inc @@ -1,4 +1,4 @@ -//=- RemoteTargetExternal.inc - LLVM out-of-process JIT execution for Unix --=// +//=- RPCChannel.inc - LLVM out-of-process JIT execution for Unix --=// // // The LLVM Compiler Infrastructure // @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// Implementation of the Unix-specific parts of the RemoteTargetExternal class +// Implementation of the Unix-specific parts of the RPCChannel class // which executes JITed code in a separate process from where it was built. // //===----------------------------------------------------------------------===// @@ -30,7 +30,7 @@ struct ConnectionData_t { namespace llvm { -bool RemoteTargetExternal::create() { +bool RPCChannel::createServer() { int PipeFD[2][2]; pid_t ChildPID; @@ -62,8 +62,7 @@ bool RemoteTargetExternal::create() { int rc = execv(ChildName.c_str(), args); if (rc != 0) perror("Error executing child process: "); - } - else { + } else { // In the parent... // Close the child ends of the pipes @@ -71,19 +70,19 @@ bool RemoteTargetExternal::create() { close(PipeFD[1][1]); // Store the parent ends of the pipes - ConnectionData = (void*)new ConnectionData_t(PipeFD[1][0], PipeFD[0][1]); - - // We must get Ack from the client (blocking read) - if (!Receive(LLI_ChildActive)) { - ErrorMsg += ", (RemoteTargetExternal::create) - Stopping process!"; - stop(); - return false; - } + ConnectionData = (void *)new ConnectionData_t(PipeFD[1][0], PipeFD[0][1]); + return true; } + return false; +} + +bool RPCChannel::createClient() { + // Store the parent ends of the pipes + ConnectionData = (void *)new ConnectionData_t(STDIN_FILENO, STDOUT_FILENO); return true; } -static void ReportError(int rc, size_t Size, std::string &ErrorMsg) { +void RPCChannel::ReportError(int rc, size_t Size, std::string &ErrorMsg) { if (rc == -1) { if (errno == EPIPE) ErrorMsg += "pipe closed"; @@ -102,31 +101,17 @@ static void ReportError(int rc, size_t Size, std::string &ErrorMsg) { } } -bool RemoteTargetExternal::WriteBytes(const void *Data, size_t Size) { - int rc = write(((ConnectionData_t*)ConnectionData)->OutputPipe, Data, Size); - if (rc != -1 && (size_t)rc == Size) - return true; - - ErrorMsg = "WriteBytes: "; - ReportError(rc, Size, ErrorMsg); - return false; +int RPCChannel::WriteBytes(const void *Data, size_t Size) { + return write(((ConnectionData_t *)ConnectionData)->OutputPipe, Data, Size); } -bool RemoteTargetExternal::ReadBytes(void *Data, size_t Size) { - int rc = read(((ConnectionData_t*)ConnectionData)->InputPipe, Data, Size); - if (rc != -1 && (size_t)rc == Size) - return true; - - ErrorMsg = "ReadBytes: "; - ReportError(rc, Size, ErrorMsg); - return false; +int RPCChannel::ReadBytes(void *Data, size_t Size) { + return read(((ConnectionData_t *)ConnectionData)->InputPipe, Data, Size); } -void RemoteTargetExternal::Wait() { - wait(NULL); -} +void RPCChannel::Wait() { wait(NULL); } -RemoteTargetExternal::~RemoteTargetExternal() { +RPCChannel::~RPCChannel() { delete static_cast<ConnectionData_t *>(ConnectionData); } |