I implemented a request queuing scheme that worked prior to v2.1. No longer works with v2.1. Is it a bug in C++ Rest SDK? What is the workaround?
The idea is to defer reply() processing by queuing incoming requests inside listener.support() lamda. Some brief time later the queued request is popped in the main() thread and a reply() is issued. The issue is that wait() after close() always hangs. This issue looks similar to Simple Listener Program Faulting on Linux.
What's the correct way of deferring/queuing incoming requests? Isn't there an issue if a request comes in a split second before close(), before listener.support reply is executed, thus causing wait() to hang forever?
The idea is to defer reply() processing by queuing incoming requests inside listener.support() lamda. Some brief time later the queued request is popped in the main() thread and a reply() is issued. The issue is that wait() after close() always hangs. This issue looks similar to Simple Listener Program Faulting on Linux.
What's the correct way of deferring/queuing incoming requests? Isn't there an issue if a request comes in a split second before close(), before listener.support reply is executed, thus causing wait() to hang forever?
#include "cpprest/http_client.h"
#include "cpprest/http_listener.h"
#include "concurrent_queue.h"
Concurrency::concurrent_queue<web::http::http_request> cq;
int main()
{
try
{
web::http::experimental::listener::http_listener listener(U("http://192.168.1.104:3901"));
listener.support([=](web::http::http_request request) { cq.push(request); /*request.reply(web::http::status_codes::OK, U("Hello, World!"));*/ });
listener.open().wait();
std::string line;
std::cout << "listening. hit enter to initiate shutdown." << std::endl;
std::getchar();
std::cout << "popping requests" << std::endl;
web::http::http_request request;
while (cq.try_pop(request))
request.reply(web::http::status_codes::ServiceUnavailable);
std::cout << "closing" << std::endl;
Concurrency::task<void> task = listener.close();
std::cout << "waiting" << std::endl;
task.wait();
std::cout << "ending" << std::endl;
}
catch (...)
{
std::cout << "caught error" << std::endl;
}
return(0);
}