当前位置: 首页>>代码示例>>C++>>正文


C++ socket::get_io_service方法代码示例

本文整理汇总了C++中tcp::socket::get_io_service方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::get_io_service方法的具体用法?C++ socket::get_io_service怎么用?C++ socket::get_io_service使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tcp::socket的用法示例。


在下文中一共展示了socket::get_io_service方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: transmit_file

void transmit_file(tcp::socket& socket,
    random_access_handle& file, Handler handler)
{
  // Construct an OVERLAPPED-derived object to contain the handler.
  overlapped_ptr overlapped(socket.get_io_service(), handler);

  // Initiate the TransmitFile operation.
  BOOL ok = ::TransmitFile(socket.native(),
      file.native(), 0, 0, overlapped.get(), 0, 0);
  DWORD last_error = ::GetLastError();

  // Check if the operation completed immediately.
  if (!ok && last_error != ERROR_IO_PENDING)
  {
    // The operation completed immediately, so a completion notification needs
    // to be posted. When complete() is called, ownership of the OVERLAPPED-
    // derived object passes to the io_service.
    asio::error_code ec(last_error,
        asio::error::get_system_category());
    overlapped.complete(ec, 0);
  }
  else
  {
    // The operation was successfully initiated, so ownership of the
    // OVERLAPPED-derived object has passed to the io_service.
    overlapped.release();
  }
}
开发者ID:barrbrain,项目名称:asio,代码行数:28,代码来源:transmit_file.cpp

示例2: l

boost::shared_ptr<torrent_info> setup_peer(tcp::socket& s, sha1_hash& ih
	, boost::shared_ptr<lt::session>& ses, bool incoming = true
	, int flags = 0, torrent_handle* th = nullptr)
{
	boost::shared_ptr<torrent_info> t = ::create_torrent();
	ih = t->info_hash();
	settings_pack sett;
	sett.set_str(settings_pack::listen_interfaces, "0.0.0.0:48900");
	sett.set_int(settings_pack::alert_mask, alert::all_categories);
	sett.set_bool(settings_pack::enable_upnp, false);
	sett.set_bool(settings_pack::enable_natpmp, false);
	sett.set_bool(settings_pack::enable_lsd, false);
	sett.set_bool(settings_pack::enable_dht, false);
	sett.set_int(settings_pack::in_enc_policy, settings_pack::pe_disabled);
	sett.set_int(settings_pack::out_enc_policy, settings_pack::pe_disabled);
	sett.set_bool(settings_pack::enable_outgoing_utp, false);
	sett.set_bool(settings_pack::enable_incoming_utp, false);
	ses.reset(new lt::session(sett, lt::session::add_default_plugins));

	error_code ec;
	add_torrent_params p;
	p.flags &= ~add_torrent_params::flag_paused;
	p.flags &= ~add_torrent_params::flag_auto_managed;
	p.flags |= flags;
	p.ti = t;
	p.save_path = "./tmp1_fast";

	remove("./tmp1_fast/temporary", ec);
	if (ec) log("remove(): %s", ec.message().c_str());
	ec.clear();
	torrent_handle ret = ses->add_torrent(p, ec);
	if (th) *th = ret;

	// wait for the torrent to be ready
	if ((flags & add_torrent_params::flag_seed_mode) == 0)
	{
		wait_for_downloading(*ses, "ses");
	}

	if (incoming)
	{
		s.connect(tcp::endpoint(address::from_string("127.0.0.1", ec), ses->listen_port()), ec);
		if (ec) TEST_ERROR(ec.message());
	}
	else
	{
		tcp::acceptor l(s.get_io_service());
		l.open(tcp::v4());
		l.bind(tcp::endpoint(address_v4::from_string("127.0.0.1"), 0));
		l.listen();
		tcp::endpoint addr = l.local_endpoint();

		ret.connect_peer(addr);
		print_session_log(*ses);
		l.accept(s);
	}

	print_session_log(*ses);

	return t;
}
开发者ID:RealImage,项目名称:libtorrent,代码行数:61,代码来源:test_fast_extension.cpp


注:本文中的tcp::socket::get_io_service方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。