我正在尝试编写一个服务器,该服务器将调用另一个服务器,然后等待其响应,然后将其发送回响应。因此,我创建了一个libnghttp2_asio客户端会话,并使用该会话将请求发送到处理程序函数中的其他服务器。它适用于一些请求。不幸的是,每当我对第一台服务器进行负载测试时,我都会得到一个错误服务器:asio_client_session_impl.cc:611: void nghttp2::asio_http2::client::session_impl::enter_callback(): Assertion !inside_callback_ failed.
经过一些要求..
我该如何解决?
int main(int argc, char *argv[]) {
boost::system::error_code ec;
boost::asio::ssl::context tls(boost::asio::ssl::context::sslv23);
tls.use_private_key_file("localhost-privkey.pem", boost::asio::ssl::context::pem);
tls.use_certificate_chain_file("localhost-cert.pem");
configure_tls_context_easy(ec, tls);
boost::system::error_code ec2;
boost::asio::io_service io_service;
// second server address
session sess(io_service,"second_server_address ", "3000");
sess.on_connect([](tcp::resolver::iterator endpoint_it) {
// get the thread id for printing
std::thread::id this_id = std::this_thread::get_id();
std:cerr << "Session connected tID : "<< this_id << std::endl;
});
sess.on_error([](const boost::system::error_code &ec) {
std::cerr << "C:error: " << ec.message() << std::endl;
});
// http2 server
http2 server;
// pass the number of threads
server.num_threads(1);
server.handle("/test",[&sess, &ec2 ](const nghttp2::asio_http2::server::request &req, const nghttp2::asio_http2::server::response &res) {
auto req2 = sess.submit(ec2, "POST","http://second_server_address:3000/test");
req2->on_response([&res](const nghttp2::asio_http2::client::response &res2) {
std::cerr << "response was received" << std::endl;
res.write_head(200);
res.end("random data");
});
req2->on_close([](uint32_t error_code) {
std::cerr << "request done closed" << error_code << std::endl;
});
});
if (server.listen_and_serve(ec,tls, "0.0.0.0", "3000",true)) {
std::cerr << "S:error " << ec.message() << std::endl;
}
io_service.run();
}