Skip to content
Snippets Groups Projects
Commit d2bb95cc authored by Michael Davis's avatar Michael Davis
Browse files

[ssi_af_ls] Adds promise/future for stream responses

parent f3c38aba
No related branches found
No related tags found
No related merge requests found
......@@ -144,7 +144,9 @@ void CtaAdminCmd::send() const
// Send the Request to the Service and get a Response
cta::xrd::Response response = cta_service.Send(m_request);
cta::xrd::Response response;
auto stream_future = cta_service.Send(m_request, response);
// Handle responses
......@@ -159,10 +161,8 @@ void CtaAdminCmd::send() const
default: throw XrdSsiPb::PbException("Invalid response type.");
}
// If there is a Data/Stream payload to follow, wait until it has been processed before exiting
if(response.has_data()) {
while(true) ;
}
// If there is a Data/Stream payload, wait until it has been processed before exiting
stream_future.wait();
}
......
......@@ -297,7 +297,9 @@ int exceptionThrowingMain(int argc, const char *const *const argv)
// Send the Request to the Service and get a Response
cta::xrd::Response response = cta_service.Send(request);
cta::xrd::Response response;
cta_service.Send(request, response);
if(isJson)
{
......
......@@ -82,14 +82,12 @@ public:
/*!
* Return the future associated with this object's Metadata promise
*/
auto GetMetadataFuture() { return m_metadata_promise.get_future(); }
std::future<MetadataType> GetMetadataFuture() { return m_metadata_promise.get_future(); }
/*!
* Return the future associated with this object's Metadata promise
* Return the future associated with this object's Data/Stream promise
*/
#if 0
auto GetDataFuture() { return m_data_promise.get_future(); }
#endif
std::future<void> GetDataFuture() { return m_data_promise.get_future(); }
private:
void ProcessResponseMetadata();
......@@ -200,7 +198,9 @@ bool Request<RequestType, MetadataType, AlertType>::ProcessResponse(const XrdSsi
// For Stream responses, the framework allocates the buffer to receive the data
// Process Stream Response: set m_response_bufptr to point to the next chunk of stream data,
// then call ProcessResponseData()
std::cerr << "Calling GetResponseData with m_response_bufptr = " << ", m_response_bufsize = " << m_response_bufsize << std::endl;
GetResponseData(m_response_bufptr, m_response_bufsize);
std::cerr << "Returned from GetResponseData with m_response_bufptr = " << ", m_response_bufsize = " << m_response_bufsize << std::endl;
break;
......
......@@ -61,7 +61,7 @@ public:
virtual ~ServiceClientSide();
MetadataType Send(const RequestType &request);
std::future<void> Send(const RequestType &request, MetadataType &response);
private:
XrdSsiResource m_resource; //!< Requests are bound to this resource. As the resource is
......@@ -145,13 +145,19 @@ ServiceClientSide<RequestType, MetadataType, AlertType>::~ServiceClientSide()
/*!
* Send a Request to the Service
*
* @param[in] request
* @param[out] response
*
* @returns future for Data/Stream requests. This return value can be ignored for Metadata-only Responses.
*/
template <typename RequestType, typename MetadataType, typename AlertType>
MetadataType ServiceClientSide<RequestType, MetadataType, AlertType>::Send(const RequestType &request)
std::future<void> ServiceClientSide<RequestType, MetadataType, AlertType>::Send(const RequestType &request, MetadataType &response)
{
// Instantiate the Request object
auto request_ptr = new Request<RequestType, MetadataType, AlertType>(request, m_response_bufsize, m_request_tmo);
auto future_response = request_ptr->GetMetadataFuture();
auto metadata_future = request_ptr->GetMetadataFuture();
auto data_future = request_ptr->GetDataFuture();
// Transfer ownership of the Request to the Service object.
m_server_ptr->ProcessRequest(*request_ptr, m_resource);
......@@ -161,9 +167,10 @@ MetadataType ServiceClientSide<RequestType, MetadataType, AlertType>::Send(const
// we do not need to as we created a reusable Resource.
// Wait synchronously for the framework to return its Response (or an exception)
auto response = future_response.get();
response = metadata_future.get();
return response;
// Return the future for Data/Stream requests
return data_future;
}
} // namespace XrdSsiPb
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment