本文整理汇总了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();
}
}
示例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;
}