Skip to content

Commit

Permalink
fix creation of redundant wire_response (#72)
Browse files Browse the repository at this point in the history
Looks good!
  • Loading branch information
venediktov authored and abushev committed Sep 21, 2017
1 parent e309a35 commit 64a38f3
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions rtb/exchange/exchange_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,22 @@ namespace vanilla {
}
std::chrono::milliseconds timeout{bid_request.request().tmax ? bid_request.request().tmax : tmax.count()};
auto future = std::async(std::launch::async, [&]() {
auto auction_response = auction_handler(bid_request);
auto wire_response = parser.create_response(auction_response);
return wire_response;
boost::optional<auction_response_type> auction_response = auction_handler(bid_request);
return auction_response;
});
if (future.wait_for(timeout) == std::future_status::ready) {
r << future.get() << http::server::reply::flush("");
auto auction_response = future.get();
if(if_response_handler) {
auto custom_reply = if_response_handler(*auction_response);
if (custom_reply) {
custom_reply(r);
return true;
}
}
auto wire_response = parser.create_response(*auction_response);
r << wire_response << http::server::reply::flush("json");
} else {
r << http::server::reply::flush("");
r << http::server::reply::flush("json");
}
return true;
}
Expand All @@ -122,11 +130,9 @@ namespace vanilla {
return false;
}
std::chrono::milliseconds timeout{bid_request.request().tmax ? bid_request.request().tmax : tmax.count()};
boost::optional<wire_response_type> wire_response;
auction_response_type auction_response;
boost::optional<auction_response_type> auction_response;
auto submit_async = [&]() {
auction_response = auction_async_handler(bid_request);
wire_response = parser.create_response(auction_response);
io_service.stop();
};
io_service.post(submit_async);
Expand All @@ -138,17 +144,16 @@ namespace vanilla {
});
io_service.reset();
io_service.run();
if (wire_response && timer.expires_from_now().total_milliseconds() > 0) {
if (auction_response && timer.expires_from_now().total_milliseconds() > 0) {
if(if_response_handler) {
auto custom_reply = if_response_handler(auction_response);
if ( custom_reply ) {
custom_reply(r);
} else {
r << *wire_response << http::server::reply::flush("json");
}
} else {
r << *wire_response << http::server::reply::flush("json");
auto custom_reply = if_response_handler(*auction_response);
if (custom_reply) {
custom_reply(r);
return true;
}
}
auto wire_response = parser.create_response(*auction_response);
r << wire_response << http::server::reply::flush("json");
} else {
r << http::server::reply::flush("json");
}
Expand Down

0 comments on commit 64a38f3

Please sign in to comment.