Report lli remote IO errors consistently

This enables IO error reports in both the child and server processes.

The scheme still isn't entirely satisfactory and output is jumbled but it beats
having no output at all. This will hopefully unblock ARM support (PR18057).

llvm-svn: 200017
diff --git a/llvm/tools/lli/Unix/RPCChannel.inc b/llvm/tools/lli/Unix/RPCChannel.inc
index b7dec37..2a5d476 100644
--- a/llvm/tools/lli/Unix/RPCChannel.inc
+++ b/llvm/tools/lli/Unix/RPCChannel.inc
@@ -12,6 +12,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/raw_ostream.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/wait.h>
@@ -82,15 +85,14 @@
   return true;
 }
 
-void RPCChannel::ReportError(int rc, size_t Size, std::string &ErrorMsg) {
-  if (rc == -1) {
-    if (errno == EPIPE)
-      ErrorMsg += "pipe closed";
-    else if (errno == EINTR)
-      ErrorMsg += "interrupted";
-    else
-      ErrorMsg += "file descriptor error";
-  } else {
+void RPCChannel::Wait() { wait(NULL); }
+
+static bool CheckError(int rc, size_t Size, const char *Desc) {
+  if (rc < 0) {
+    llvm::errs() << "IO Error: " << Desc << ": " << sys::StrError() << '\n';
+    return false;
+  } else if ((size_t)rc != Size) {
+    std::string ErrorMsg;
     char Number[10] = { 0 };
     ErrorMsg += "Expecting ";
     sprintf(Number, "%d", (uint32_t)Size);
@@ -98,19 +100,22 @@
     ErrorMsg += " bytes, Got ";
     sprintf(Number, "%d", rc);
     ErrorMsg += Number;
+    llvm::errs() << "RPC Error: " << Desc << ": " << ErrorMsg << '\n';
+    return false;
   }
+  return true;
 }
 
-int RPCChannel::WriteBytes(const void *Data, size_t Size) {
-  return write(((ConnectionData_t *)ConnectionData)->OutputPipe, Data, Size);
+bool RPCChannel::WriteBytes(const void *Data, size_t Size) {
+  int rc = write(((ConnectionData_t *)ConnectionData)->OutputPipe, Data, Size);
+  return CheckError(rc, Size, "WriteBytes");
 }
 
-int RPCChannel::ReadBytes(void *Data, size_t Size) {
-  return read(((ConnectionData_t *)ConnectionData)->InputPipe, Data, Size);
+bool RPCChannel::ReadBytes(void *Data, size_t Size) {
+  int rc = read(((ConnectionData_t *)ConnectionData)->InputPipe, Data, Size);
+  return CheckError(rc, Size, "ReadBytes");
 }
 
-void RPCChannel::Wait() { wait(NULL); }
-
 RPCChannel::~RPCChannel() {
   delete static_cast<ConnectionData_t *>(ConnectionData);
 }