[+] AuIRPCRequest::EmptyRequest()

[*] De boog numero 2
> Constrain dispatch bytebuffer views to the exact frame length
This commit is contained in:
Reece Wilson 2022-07-07 05:16:27 +01:00
parent c4df7fc4c2
commit 14ebab9d22
6 changed files with 40 additions and 4 deletions

View File

@ -100,6 +100,7 @@ struct AuIRPCRequest
{
virtual bool SetData(const AuByteBuffer &toRead) = 0;
virtual bool SetData(const AuMemoryViewRead &view) = 0;
virtual bool EmptyRequest() = 0;
virtual void SetCallback(AuSPtr<AuRPCRequestCallback> callback) = 0;
};

View File

@ -70,13 +70,22 @@ bool AuRPCClientChannel::OnDataAvailable(AuByteBuffer &view)
}
auto oldRead = view.readPtr;
auto frameLength = view.Read<AuUInt32>();
if (view.Read<AuUInt32>() > bytesAvailable)
if (!frameLength)
{
Disconnect();
return false;
}
if (frameLength > bytesAvailable)
{
view.readPtr = oldRead;
return true;
}
auto endPtr = oldRead + frameLength;
auto packetType = view.Read<AuUInt8>();
if (packetType == kResponseConnectOK)
@ -100,10 +109,16 @@ bool AuRPCClientChannel::OnDataAvailable(AuByteBuffer &view)
return true;
}
auto oldLength = view.length;
view.length = (oldRead - view.base) + frameLength;
response->message = &view;
response->Deserialize();
this->ProcessResponse(response);
view.readPtr = endPtr;
view.length = oldLength;
}
} while (true);

View File

@ -35,6 +35,11 @@ void AuRPCRequest::SetCallback(AuSPtr<AuRPCRequestCallback> callback)
this->callback = callback;
}
bool AuRPCRequest::EmptyRequest()
{
return SetData(AuMemoryViewRead {});
}
AuMemoryViewRead AuRPCRequest::GetData()
{
return this->data;

View File

@ -20,6 +20,8 @@ struct AuRPCRequest : AuIRPCRequest
void SetCallback(AuSPtr<AuRPCRequestCallback> callback) override;
bool EmptyRequest() override;
ERPCRequestState GetState();
AuMemoryViewRead GetData();

View File

@ -92,8 +92,8 @@ void AuRPCServer::Dispatch(AuRPCServerChannel *channel,
itr->second->Dispatch(*response, request->methodId, *buffer);
channel->SendResponse(response);
response->FinalizeWrite();
channel->SendResponse(response);
}
catch (...)
{

View File

@ -66,7 +66,14 @@ bool AuRPCServerChannel::OnDataAvailable(AuByteBuffer& view)
auto oldRead = view.readPtr;
if (view.Read<AuUInt32>() > bytesAvailable)
auto frameLength = view.Read<AuUInt32>();
if (!frameLength)
{
FatalError();
return false;
}
if (frameLength > bytesAvailable)
{
view.readPtr = oldRead;
return true;
@ -99,7 +106,13 @@ bool AuRPCServerChannel::OnDataAvailable(AuByteBuffer& view)
request->methodId = view.Read<AuUInt32>();
request->cookie = view.Read<AuUInt64>();
auto oldLength = view.length;
view.length = (oldRead - view.base) + frameLength;
this->server_->Dispatch(this, request, &view);
view.readPtr = frameLength + oldRead;
view.length = oldLength;
}
}