Thursday, 15 January 2015

c++ - async_connect hangs - Ubuntu -



c++ - async_connect hangs - Ubuntu -

i sending https messages on port 443 on tcp socket using boost::asio graph.facebook.com. when on home linux box async_connect goes through instantly , fine. when run same code on rackspace linux server (which ubuntu) async_connect hangs 20-30 seconds each time before connection goes through. here code

boost::asio::io_service server::m_ioservice; boost::asio::ssl::context server::m_ctx(boost::asio::ssl::context::sslv23); boost::shared_ptr<boost::asio::io_service::work> m_work(new boost::asio::io_service::work(m_ioservice); boost::thread_group m_threads; m_ctx.set_default_verify_paths(); for(int z=0; z < 4; ++z) { m_threads.create_thread(boost::bind(&boost::asio::io_service::run, &m_ioservice)); } boost::asio::ip::tcp::resolver m_resolver; boost::asio::ssl::stream<boost::asio::ip::tcp::socket> m_sslsocket; boost::asio::streambuf m_request; m_sslsocket.set_verify_mode(boost::asio::ssl::verify_peer); m_sslsocket.set_verify_callback(boost::asio::ssl::rfc2818_verification("graph.facebook.com")); std::ostream request_stream(&m_request); request_stream << "get " << a_path << " http/1.0\r\n"; request_stream << "host: " << "graph.facebook.com" << "\r\n"; request_stream << "accept: */*\r\n"; request_stream << "connection: close\r\n\r\n"; boost::asio::ip::tcp::resolver::query query("graph.facebook.com", "https"); m_resolver.async_resolve(query, boost::bind(&handleresolve, this, boost::asio::placeholders::error, boost::asio::placeholders::iterator)); void handleresolve(const boost::system::error_code& a_err, boost::asio::ip::tcp::resolver::iterator a_endpointiterator) { if(!a_err) { // effort connection each endpoint in list until // found connection. std::cout << "before connect" << std::endl; boost::asio::async_connect(m_sslsocket.lowest_layer(), a_endpointiterator, boost::bind(&handleconnect, this, boost::asio::placeholders::error)); } else { std::cout << "error: " << a_err.message() << "\n"; } }

i don't error , connection works, 20-30 sec delay makes application unusable. help appreciated.

c++ boost boost-asio

No comments:

Post a Comment