예제 #1
0
inline boost::system::error_code connect(
    boost::asio::ip::tcp::socket::lowest_layer_type& socket,
    boost::asio::ip::tcp::resolver& resolver,
    const url& u, boost::system::error_code& ec)
{
  // Create a query that corresponds to the url.
  std::ostringstream port_string;
  port_string << u.port();

  // Get a list of endpoints corresponding to the query.
  boost::asio::ip::tcp::resolver::results_type endpoints = resolver.resolve(u.host(), port_string.str(), ec);
  if (ec)
    return ec;

  // Try each endpoint until we successfully establish a connection.
  ec = boost::asio::error::host_not_found;
  boost::asio::connect(socket, endpoints, ec);
  if (ec)
    return ec;

  // Disable the Nagle algorithm on all sockets.
  ec = boost::system::error_code();
  socket.set_option(boost::asio::ip::tcp::no_delay(true), ec);
  return ec;
}
예제 #2
0
void async_connect(boost::asio::ip::tcp::socket::lowest_layer_type& socket,
    boost::asio::ip::tcp::resolver& resolver, const url& u, Handler handler)
{
  std::ostringstream port_string;
  port_string << u.port();
  connect_coro<Handler>(handler, socket, resolver)(
      boost::system::error_code(), u.host(), port_string.str());
}
예제 #3
0
파일: websocket.cpp 프로젝트: aspectron/jsx
void websocket::connect(url const& target)
{
	state_ = CONNECTING;

	if ( target.scheme() != "ws" && target.scheme() != "wss" )
	{
		throw std::invalid_argument("Unsupported URL " + target.to_string());
	}

	tcp_conn_.reset(new pion::tcp::connection(rt_.io_service(), target.is_scheme_secured()));
//	tcp_conn_->getSocket().set_option(boost::asio::ip::tcp::no_delay(true)); // disable ngale

	// create resolver and start async resolve
	boost::shared_ptr<tcp::resolver> resolver = boost::make_shared<tcp::resolver>(rt_.io_service());
	tcp::resolver::query query(target.host(), std::to_string(static_cast<unsigned long long>(target.effective_port())),
		tcp::resolver::query::numeric_service);

	resolver->async_resolve(query, boost::bind(&websocket::handle_resolve, this,
		target, resolver, boost::asio::placeholders::error, boost::asio::placeholders::iterator));
}
예제 #4
0
acceptor reactor::listen(const url& url){
    return make_wrapper(pn_reactor_acceptor(pn_object(), url.host().c_str(), url.port().c_str(), 0));
}