diff --git a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp index 6c43e93c6..00118e199 100644 --- a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp +++ b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp @@ -1,55 +1,60 @@ #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); } + +void ClientGetReadReactor::OnDone(const grpc::Status &status) { + std::lock_guard guard{this->setReadyStateMutex}; + this->setReadyState(SocketStatus::CLOSED); +} diff --git a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.h b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.h index a8640e827..b70124248 100644 --- a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.h +++ b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.h @@ -1,38 +1,39 @@ #pragma once #include "../NativeModules/InternalModules/SocketStatus.h" #include #include "_generated/tunnelbroker.grpc.pb.h" #include "_generated/tunnelbroker.pb.h" class ClientGetReadReactor : public grpc::ClientReadReactor { std::string sessionID; grpc::ClientContext context; tunnelbroker::GetRequest request; tunnelbroker::GetResponse response; std::mutex onReadDoneCallbackMutex; std::mutex onOpenCallbackMutex; std::mutex onCloseCallbackMutex; std::mutex setReadyStateMutex; std::function onReadDoneCallback; std::function onOpenCallback; std::function onCloseCallback; std::function setReadyState; public: ClientGetReadReactor( tunnelbroker::TunnelbrokerService::Stub *stub, std::string sessionID); void OnReadInitialMetadataDone(bool ok) override; void OnReadDone(bool ok) override; + void OnDone(const grpc::Status &status) override; void close(); void setOnOpenCallback(std::function onOpenCallback); void setOnReadDoneCallback(std::function onReadDoneCallback); void setOnCloseCallback(std::function onCloseCallback); void assignSetReadyStateCallback(std::function callback); };