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

Dont signal occurrence if client call not active #223

Closed
wants to merge 2 commits into from
Closed
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
25 changes: 22 additions & 3 deletions src/grpc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ namespace grpc_labview
}

int32_t ClientCleanUpProc(grpc_labview::gRPCid* clientId);
void SignalOccurenceForClientCall(grpc_labview::ClientCall* clientCall);

//---------------------------------------------------------------------
//---------------------------------------------------------------------
Expand Down Expand Up @@ -192,6 +193,22 @@ int32_t CloseClient(grpc_labview::LabVIEWgRPCClient* client)
return 0;
}

// Signal a lv occurence for a client call from async c++ thread
void SignalOccurenceForClientCall(grpc_labview::ClientCall* clientCall)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we name this method CheckActiveAndSignalOccurence to signify that we will fire the occurrence only if the client call is active?

{
if (clientCall == nullptr)
{
return;
}
std::lock_guard<std::mutex> lock(clientCall->_client->clientLock);
std::list<grpc_labview::ClientCall*>::iterator it;
it = std::find(clientCall->_client->ActiveClientCalls.begin(), clientCall->_client->ActiveClientCalls.end(), clientCall);
if (it != clientCall->_client->ActiveClientCalls.end())
{
grpc_labview::SignalOccurrence(clientCall->_occurrence);
}
}

LIBRARY_EXPORT int32_t CloseClient(grpc_labview::gRPCid* clientId)
{
auto client = clientId->CastTo<grpc_labview::LabVIEWgRPCClient>();
Expand All @@ -218,6 +235,8 @@ int32_t ClientCleanUpProc(grpc_labview::gRPCid* clientId)
{
(*activeClientCall)->Cancel();
}

client->ActiveClientCalls.clear();
ni-sujain marked this conversation as resolved.
Show resolved Hide resolved
}
return CloseClient(client.get());
}
Expand Down Expand Up @@ -307,7 +326,7 @@ LIBRARY_EXPORT int32_t ClientUnaryCall(
{
grpc::internal::RpcMethod method(clientCall->_methodName.c_str(), grpc::internal::RpcMethod::NORMAL_RPC);
clientCall->_status = grpc::internal::BlockingUnaryCall(clientCall->_client->Channel.get(), method, &(clientCall->_context.get()->gRPCClientContext) , *clientCall->_request.get(), clientCall->_response.get());
grpc_labview::SignalOccurrence(clientCall->_occurrence);
SignalOccurenceForClientCall(clientCall);
return 0;
});

Expand Down Expand Up @@ -560,7 +579,7 @@ LIBRARY_EXPORT int32_t ClientBeginReadFromStream(grpc_labview::gRPCid* callId, g
{
call->_response->Clear();
auto result = reader->Read(call->_response.get());
grpc_labview::SignalOccurrence(occurrence);
SignalOccurenceForClientCall(call.get());
return result;
});

Expand Down Expand Up @@ -695,7 +714,7 @@ LIBRARY_EXPORT int32_t ClientCompleteClientStreamingCall(grpc_labview::gRPCid* c
[call, occurrence]()
{
call->Finish();
grpc_labview::SignalOccurrence(occurrence);
SignalOccurenceForClientCall(call.get());
return 0;
});
return 0;
Expand Down