track open/close state in connection, disconnect on read error, clarify error codes a little

This commit is contained in:
Chris Marsh
2017-07-31 14:42:36 -07:00
parent c3c27c730d
commit d5e6c4c11a
5 changed files with 47 additions and 5 deletions

View File

@@ -97,13 +97,18 @@ bool RpcConnection::Read(JsonDocument& message)
for (;;) {
bool didRead = connection->Read(&readFrame, sizeof(MessageFrameHeader));
if (!didRead) {
if (!connection->isOpen) {
lastErrorCode = (int)ErrorCode::PipeClosed;
StringCopy(lastErrorMessage, "Pipe closed");
Close();
}
return false;
}
if (readFrame.length > 0) {
didRead = connection->Read(readFrame.message, readFrame.length);
if (!didRead) {
lastErrorCode = -2;
lastErrorCode = (int)ErrorCode::ReadCorrupt;
StringCopy(lastErrorMessage, "Partial data in frame");
Close();
return false;
@@ -132,7 +137,7 @@ bool RpcConnection::Read(JsonDocument& message)
break;
default:
// something bad happened
lastErrorCode = -1;
lastErrorCode = (int)ErrorCode::ReadCorrupt;
StringCopy(lastErrorMessage, "Bad ipc frame");
Close();
return false;