mirror of
https://git.suyu.dev/suyu/discord-rpc.git
synced 2026-01-01 12:15:46 +01:00
track open/close state in connection, disconnect on read error, clarify error codes a little
This commit is contained in:
parent
c3c27c730d
commit
d5e6c4c11a
5 changed files with 47 additions and 5 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue