diff --git a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp index 00118e199..e11a940db 100644 --- a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp +++ b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp @@ -1,60 +1,68 @@ #include "ClientGetReadReactor.h" ClientGetReadReactor::ClientGetReadReactor( tunnelbroker::TunnelbrokerService::Stub *stub, std::string sessionID) : sessionID{sessionID}, request{} { request.set_sessionid(sessionID); stub->async()->Get(&(this->context), &(this->request), this); StartRead(&(this->response)); StartCall(); } void ClientGetReadReactor::OnReadDone(bool ok) { if (!ok) { return; } std::lock_guard guard{this->onReadDoneCallbackMutex}; if (this->onReadDoneCallback) { this->onReadDoneCallback(this->response.payload()); } StartRead(&(this->response)); } void ClientGetReadReactor::close() { this->context.TryCancel(); } void ClientGetReadReactor::setOnOpenCallback( std::function onOpenCallback) { std::lock_guard guard{this->onOpenCallbackMutex}; this->onOpenCallback = onOpenCallback; } void ClientGetReadReactor::setOnReadDoneCallback( std::function onReadDoneCallback) { std::lock_guard guard{this->onReadDoneCallbackMutex}; this->onReadDoneCallback = onReadDoneCallback; } void ClientGetReadReactor::setOnCloseCallback( std::function onCloseCallback) { std::lock_guard guard{this->onCloseCallbackMutex}; this->onCloseCallback = onCloseCallback; } void ClientGetReadReactor::assignSetReadyStateCallback( std::function callback) { std::lock_guard guard{this->setReadyStateMutex}; this->setReadyState = callback; } void ClientGetReadReactor::OnReadInitialMetadataDone(bool ok) { std::lock_guard guard{this->setReadyStateMutex}; this->setReadyState(SocketStatus::OPEN); + if (this->onOpenCallback) { + std::lock_guard onOpenGuard{this->onOpenCallbackMutex}; + this->onOpenCallback(); + } } void ClientGetReadReactor::OnDone(const grpc::Status &status) { std::lock_guard guard{this->setReadyStateMutex}; this->setReadyState(SocketStatus::CLOSED); + if (this->onCloseCallback) { + std::lock_guard onCloseGuard{this->onCloseCallbackMutex}; + this->onCloseCallback(); + } }