Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate channel status messages on close #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/TurboLinkGrpc/Private/TurboLinkGrpcContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ void GrpcContext::UpdateState(EGrpcContextState NewState)
InitialTag = Service->TurboLinkManager->GetNextTag(AsShared());
WriteTag = Service->TurboLinkManager->GetNextTag(AsShared());
ReadTag = Service->TurboLinkManager->GetNextTag(AsShared());
FinishTag = Service->TurboLinkManager->GetNextTag(AsShared());
}
else if (ContextState == EGrpcContextState::Done)
{
Service->TurboLinkManager->RemoveTag(InitialTag);
Service->TurboLinkManager->RemoveTag(WriteTag);
Service->TurboLinkManager->RemoveTag(ReadTag);
Service->TurboLinkManager->RemoveTag(FinishTag);
}

if (Client->OnContextStateChange.IsBound())
Expand Down
24 changes: 21 additions & 3 deletions Source/TurboLinkGrpc/Private/TurboLinkGrpcContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class GrpcContext : public TSharedFromThis<GrpcContext>
void* InitialTag = nullptr;
void* WriteTag = nullptr;
void* ReadTag = nullptr;
void* FinishTag = nullptr;

protected:
void UpdateState(EGrpcContextState NewState);
Expand Down Expand Up @@ -139,14 +140,22 @@ class GrpcContext_Ping_Stream : public TGrpcContext<T, R>
protected:
void OnRpcEventInternal(bool Ok, const void* EventTag, typename Super::FRpcCallbackFunc RpcCallbackFunc)
{

if (!Ok)
{
Super::RpcReaderWriter->Finish(&(Super::RpcStatus), Super::ReadTag);
Super::UpdateState(EGrpcContextState::Done);
Super::RpcReaderWriter->Finish(&(Super::RpcStatus), Super::FinishTag);
return;
}

FGrpcResult result = GrpcContext::MakeGrpcResult(Super::RpcStatus);
if (EventTag == Super::FinishTag) {
if (RpcCallbackFunc)
{
RpcCallbackFunc(result, nullptr);
}
Super::UpdateState(EGrpcContextState::Done);
return;
}
if (Super::RpcStatus.ok())
{
if (Super::GetState() == EGrpcContextState::Initialing)
Expand Down Expand Up @@ -293,11 +302,20 @@ class GrpcContext_Stream_Stream : public TGrpcContext<T, R>
{
if (!Ok)
{
Super::RpcReaderWriter->Finish(&(Super::RpcStatus), Super::ReadTag);
Super::RpcReaderWriter->Finish(&(Super::RpcStatus), Super::FinishTag);
return;
}

FGrpcResult result = GrpcContext::MakeGrpcResult(Super::RpcStatus);
if (EventTag == Super::FinishTag)
{
if (RpcCallbackFunc)
{
RpcCallbackFunc(result, &(Super::RpcResponse));
}
Super::UpdateState(EGrpcContextState::Done);
return;
}
if (Super::RpcStatus.ok())
{
if (Super::GetState() == EGrpcContextState::Initialing)
Expand Down