Commit e61b995d authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Use timeout for future-promise

parent 06578217
......@@ -41,6 +41,12 @@
#include "smf_config.hpp"
#include "3gpp_conversions.hpp"
#include "mime_parser.hpp"
#include <boost/thread.hpp>
#include <boost/thread/future.hpp>
#include <boost/chrono.hpp>
#include <boost/chrono/chrono.hpp>
#include <boost/chrono/duration.hpp>
#include <boost/chrono/system_clocks.hpp>
extern smf::smf_config smf_cfg;
......@@ -98,6 +104,13 @@ void SMContextsCollectionApiImpl::post_sm_contexts(
itti_msg->http_version = 1;
m_smf_app->handle_pdu_session_create_sm_context_request(itti_msg);
boost::future_status status;
// wait for timeout or ready
status = f.wait_for(boost::chrono::milliseconds(100));
if (status == boost::future_status::ready) {
assert(f.is_ready());
assert(f.has_value());
assert(!f.has_exception());
// Wait for the result from APP and send reply to AMF
smf::pdu_session_create_sm_context_response sm_context_response = f.get();
Logger::smf_api_server().debug("Got result for promise ID %d", promise_id);
......@@ -117,7 +130,8 @@ void SMContextsCollectionApiImpl::post_sm_contexts(
multipart_related_content_part_e::NAS, json_format);
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(
"multipart/related; boundary=" + std::string(CURL_MIME_BOUNDARY)));
"multipart/related; boundary=" +
std::string(CURL_MIME_BOUNDARY)));
} else if (!json_data.empty()) { // if not, include json data if available
response.headers().add<Pistache::Http::Header::Location>(
sm_context_response.get_smf_context_uri()); // Location header
......@@ -129,8 +143,12 @@ void SMContextsCollectionApiImpl::post_sm_contexts(
response.send(Pistache::Http::Code(sm_context_response.get_http_code()));
return;
}
response.send(
Pistache::Http::Code(sm_context_response.get_http_code()), body);
} else {
response.send(Pistache::Http::Code::Request_Timeout);
}
}
} // namespace api
} // namespace smf_server
......
......@@ -320,5 +320,5 @@ IF(STATIC_LINKING)
ENDIF(STATIC_LINKING)
target_link_libraries (smf ${ASAN}
-Wl,--start-group CN_UTILS SMF UDP PFCP 3GPP_COMMON_TYPES SMF_API -lnettle ${NETTLE_LIBRARIES} ${CRYPTO_LIBRARIES} -lnghttp2_asio -lboost_system -lboost_thread -lssl -lcrypto NAS gflags glog dl double-conversion folly -Wl,--end-group pthread m rt config++ event boost_system pistache curl)
-Wl,--start-group CN_UTILS SMF UDP PFCP 3GPP_COMMON_TYPES SMF_API -lnettle ${NETTLE_LIBRARIES} ${CRYPTO_LIBRARIES} -lnghttp2_asio -lboost_system -lboost_thread -lssl -lcrypto NAS gflags glog dl double-conversion folly -Wl,--end-group pthread m rt config++ event boost_system boost_chrono pistache curl)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment