From e8e4962290748312b26856ab7f13ed3e36b17e73 Mon Sep 17 00:00:00 2001 From: kamchatka_volcano Date: Sat, 27 Aug 2022 15:10:17 +0300 Subject: [PATCH] -made ResponserHandler in requester get response data by copy; -updated the version to 1.4.0; -made ResponserHandler in requester get response data by copy; --- CMakeLists.txt | 2 +- include/fcgi_responder/requester.h | 2 +- src/requester.cpp | 4 ++-- src/requesterimpl.cpp | 12 ++++++------ src/requesterimpl.h | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index efdff32..0e1d413 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.18) -project(fcgi_responder VERSION 1.3.1 DESCRIPTION "FastCGI protocol responder role implementation library") +project(fcgi_responder VERSION 1.4.0 DESCRIPTION "FastCGI protocol responder role implementation library") if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(FCGI_RESPONDER_SUBPROJECT OFF) diff --git a/include/fcgi_responder/requester.h b/include/fcgi_responder/requester.h index 15556e2..4fc586d 100644 --- a/include/fcgi_responder/requester.h +++ b/include/fcgi_responder/requester.h @@ -41,7 +41,7 @@ class Requester{ /// std::optional sendRequest( std::map params, std::string data, - std::function&)> responseHandler, + const std::function)>& responseHandler, bool keepConnection = false); /// /// \brief setErrorInfoHandler diff --git a/src/requester.cpp b/src/requester.cpp index bcbb8d9..5de0dfb 100644 --- a/src/requester.cpp +++ b/src/requester.cpp @@ -40,10 +40,10 @@ const RequesterImpl& Requester::impl() const std::optional Requester::sendRequest( std::map params, std::string data, - std::function&)> responseHandler, + const std::function)>& responseHandler, bool keepConnection) { - return impl().sendRequest(std::move(params), std::move(data), std::move(responseHandler), keepConnection); + return impl().sendRequest(std::move(params), std::move(data), responseHandler, keepConnection); } int Requester::availableRequestsNumber() const diff --git a/src/requesterimpl.cpp b/src/requesterimpl.cpp index 0e02731..5f1abd5 100644 --- a/src/requesterimpl.cpp +++ b/src/requesterimpl.cpp @@ -40,7 +40,7 @@ RequesterImpl::RequesterImpl( std::optional RequesterImpl::sendRequest( std::map params, std::string data, - std::function&)> responseHandler, + const std::function)>& responseHandler, bool keepConnection) { if (connectionState_ == ConnectionState::NotConnected) { @@ -76,7 +76,7 @@ int RequesterImpl::availableRequestsNumber() const void RequesterImpl::initConnection( std::map params, std::string data, - std::function&)> responseHandler, + std::function)> responseHandler, bool keepConnection) { connectionState_ = ConnectionState::ConnectionInProgress; @@ -104,7 +104,7 @@ void RequesterImpl::initConnection( std::optional RequesterImpl::doSendRequest( const std::map& params, const std::string& data, - const std::function&)>& responseHandler, + std::function)> responseHandler, bool keepConnection) { if (requestIdPool_.empty()){ @@ -116,7 +116,7 @@ std::optional RequesterImpl::doSendRequest( auto requestId = *requestIdPool_.begin(); requestIdPool_.erase(requestId); responseMap_.emplace(requestId, - ResponseContext{responseHandler, ResponseData{}, keepConnection, + ResponseContext{std::move(responseHandler), ResponseData{}, keepConnection, std::make_shared>([=] { doEndRequest(requestId, ResponseStatus::Cancelled); }) @@ -140,9 +140,9 @@ std::optional RequesterImpl::doSendRequest( void RequesterImpl::doEndRequest(uint16_t requestId, ResponseStatus responseStatus) { - const auto& responseContext = responseMap_.at(requestId); + auto& responseContext = responseMap_.at(requestId); if (responseStatus == ResponseStatus::Successful) - responseContext.responseHandler(responseContext.responseData); + responseContext.responseHandler(std::move(responseContext.responseData)); else responseContext.responseHandler(std::nullopt); diff --git a/src/requesterimpl.h b/src/requesterimpl.h index 2d68c7b..74322b7 100644 --- a/src/requesterimpl.h +++ b/src/requesterimpl.h @@ -38,7 +38,7 @@ class RequesterImpl{ void receiveData(const char* data, std::size_t size); std::optional sendRequest( std::map params, std::string data, - std::function&)> responseHandler, + const std::function)>& responseHandler, bool keepConnection = false); void setErrorInfoHandler(const std::function& handler); @@ -52,12 +52,12 @@ class RequesterImpl{ void initConnection( std::map params, std::string data, - std::function&)> responseHandler, + std::function)> responseHandler, bool keepConnection); std::optional doSendRequest( const std::map& params, const std::string& data, - const std::function&)>& responseHandler, + std::function)> responseHandler, bool keepConnection); void doEndRequest(uint16_t requestId, ResponseStatus responseStatus); void onRecordRead(const Record& record); @@ -80,7 +80,7 @@ class RequesterImpl{ } cfg_; struct ResponseContext{ - std::function&)> responseHandler; + std::function)> responseHandler; ResponseData responseData; bool keepConnection = false; std::shared_ptr> cancelRequestHandler;