Example #1
0
void torrent_handle::async_call(Fun f, Args&&... a) const
{
    boost::shared_ptr<torrent> t = m_torrent.lock();
    TORRENT_ASSERT_PRECOND(t);
    if (!t) return;
    session_impl& ses = static_cast<session_impl&>(t->session());
    ses.get_io_service().dispatch([=] () {
        (t.get()->*f)(a...);
    } );
}
Example #2
0
	std::string generate_fingerprint(std::string name, int const major
		, int const minor
		, int const revision
		, int const tag)
	{
		TORRENT_ASSERT_PRECOND(major >= 0);
		TORRENT_ASSERT_PRECOND(minor >= 0);
		TORRENT_ASSERT_PRECOND(revision >= 0);
		TORRENT_ASSERT_PRECOND(tag >= 0);
		TORRENT_ASSERT_PRECOND(name.size() == 2);
		if (name.size() < 2) name = "--";

		std::string ret;
		ret.resize(8);
		ret[0] = '-';
		ret[1] = name[0];
		ret[2] = name[1];
		ret[3] = version_to_char(major);
		ret[4] = version_to_char(minor);
		ret[5] = version_to_char(revision);
		ret[6] = version_to_char(tag);
		ret[7] = '-';
		return ret;
	}
Example #3
0
void torrent_handle::sync_call(Fun f, Args&&... a) const
{
    boost::shared_ptr<torrent> t = m_torrent.lock();
    TORRENT_ASSERT_PRECOND(t);
    if (!t) return;
    session_impl& ses = static_cast<session_impl&>(t->session());

    // this is the flag to indicate the call has completed
    bool done = false;

    ses.get_io_service().dispatch([=,&done,&ses] ()
    {
        (t.get()->*f)(a...);
        std::unique_lock<std::mutex> l(ses.mut);
        done = true;
        ses.cond.notify_all();
    } );

    aux::torrent_wait(done, ses);
}
Example #4
0
void torrent_handle::set_download_limit(int limit) const
{
    TORRENT_ASSERT_PRECOND(limit >= -1);
    async_call(&torrent::set_download_limit, limit);
}
Example #5
0
void torrent_handle::set_max_connections(int max_connections) const
{
    TORRENT_ASSERT_PRECOND(max_connections >= 2 || max_connections == -1);
    async_call(&torrent::set_max_connections, max_connections, true);
}
Example #6
0
void torrent_handle::set_max_uploads(int max_uploads) const
{
    TORRENT_ASSERT_PRECOND(max_uploads >= 2 || max_uploads == -1);
    async_call(&torrent::set_max_uploads, max_uploads, true);
}
void apply_pack(settings_pack const* pack, aux::session_settings& sett
                , aux::session_impl* ses)
{
    typedef void (aux::session_impl::*fun_t)();
    std::vector<fun_t> callbacks;

    for (auto const& p : pack->m_strings)
    {
        // disregard setting indices that are not string types
        if ((p.first & settings_pack::type_mask) != settings_pack::string_type_base)
            continue;

        // ignore settings that are out of bounds
        int const index = p.first & settings_pack::index_mask;
        TORRENT_ASSERT_PRECOND(index >= 0 && index < settings_pack::num_string_settings);
        if (index < 0 || index >= settings_pack::num_string_settings)
            continue;

        // if the value did not change, don't call the update callback
        if (sett.get_str(p.first) == p.second) continue;

        sett.set_str(p.first, p.second);
        str_setting_entry_t const& sa = str_settings[index];

        if (sa.fun && ses
                && std::find(callbacks.begin(), callbacks.end(), sa.fun) == callbacks.end())
            callbacks.push_back(sa.fun);
    }

    for (auto const& p : pack->m_ints)
    {
        // disregard setting indices that are not int types
        if ((p.first & settings_pack::type_mask) != settings_pack::int_type_base)
            continue;

        // ignore settings that are out of bounds
        int const index = p.first & settings_pack::index_mask;
        TORRENT_ASSERT_PRECOND(index >= 0 && index < settings_pack::num_int_settings);
        if (index < 0 || index >= settings_pack::num_int_settings)
            continue;

        // if the value did not change, don't call the update callback
        if (sett.get_int(p.first) == p.second) continue;

        sett.set_int(p.first, p.second);
        int_setting_entry_t const& sa = int_settings[index];
        if (sa.fun && ses
                && std::find(callbacks.begin(), callbacks.end(), sa.fun) == callbacks.end())
            callbacks.push_back(sa.fun);
    }

    for (auto const& p : pack->m_bools)
    {
        // disregard setting indices that are not bool types
        if ((p.first & settings_pack::type_mask) != settings_pack::bool_type_base)
            continue;

        // ignore settings that are out of bounds
        int const index = p.first & settings_pack::index_mask;
        TORRENT_ASSERT_PRECOND(index >= 0 && index < settings_pack::num_bool_settings);
        if (index < 0 || index >= settings_pack::num_bool_settings)
            continue;

        // if the value did not change, don't call the update callback
        if (sett.get_bool(p.first) == p.second) continue;

        sett.set_bool(p.first, p.second);
        bool_setting_entry_t const& sa = bool_settings[index];
        if (sa.fun && ses
                && std::find(callbacks.begin(), callbacks.end(), sa.fun) == callbacks.end())
            callbacks.push_back(sa.fun);
    }

    // call the callbacks once all the settings have been applied, and
    // only once per callback
    for (auto const& f : callbacks)
    {
        (ses->*f)();
    }
}
Example #8
0
	void apply_pack(settings_pack const* pack, aux::session_settings& sett
		, aux::session_impl* ses)
	{
		typedef void (aux::session_impl::*fun_t)();
		std::vector<fun_t> callbacks;

		for (std::vector<std::pair<std::uint16_t, std::string> >::const_iterator i = pack->m_strings.begin()
			, end(pack->m_strings.end()); i != end; ++i)
		{
			// disregard setting indices that are not string types
			if ((i->first & settings_pack::type_mask) != settings_pack::string_type_base)
				continue;

			// ignore settings that are out of bounds
			int const index = i->first & settings_pack::index_mask;
			TORRENT_ASSERT_PRECOND(index >= 0 && index < settings_pack::num_string_settings);
			if (index < 0 || index >= settings_pack::num_string_settings)
				continue;

			sett.set_str(i->first, i->second);
			str_setting_entry_t const& sa = str_settings[index];
			if (sa.fun && ses
				&& std::find(callbacks.begin(), callbacks.end(), sa.fun) == callbacks.end())
				callbacks.push_back(sa.fun);
		}

		for (std::vector<std::pair<std::uint16_t, int> >::const_iterator i = pack->m_ints.begin()
			, end(pack->m_ints.end()); i != end; ++i)
		{
			// disregard setting indices that are not int types
			if ((i->first & settings_pack::type_mask) != settings_pack::int_type_base)
				continue;

			// ignore settings that are out of bounds
			int const index = i->first & settings_pack::index_mask;
			TORRENT_ASSERT_PRECOND(index >= 0 && index < settings_pack::num_int_settings);
			if (index < 0 || index >= settings_pack::num_int_settings)
				continue;

			sett.set_int(i->first, i->second);
			int_setting_entry_t const& sa = int_settings[index];
			if (sa.fun && ses
				&& std::find(callbacks.begin(), callbacks.end(), sa.fun) == callbacks.end())
				callbacks.push_back(sa.fun);
		}

		for (std::vector<std::pair<std::uint16_t, bool> >::const_iterator i = pack->m_bools.begin()
			, end(pack->m_bools.end()); i != end; ++i)
		{
			// disregard setting indices that are not bool types
			if ((i->first & settings_pack::type_mask) != settings_pack::bool_type_base)
				continue;

			// ignore settings that are out of bounds
			int const index = i->first & settings_pack::index_mask;
			TORRENT_ASSERT_PRECOND(index >= 0 && index < settings_pack::num_bool_settings);
			if (index < 0 || index >= settings_pack::num_bool_settings)
				continue;

			sett.set_bool(i->first, i->second);
			bool_setting_entry_t const& sa = bool_settings[index];
			if (sa.fun && ses
				&& std::find(callbacks.begin(), callbacks.end(), sa.fun) == callbacks.end())
				callbacks.push_back(sa.fun);
		}

		// call the callbacks once all the settings have been applied, and
		// only once per callback
		for (std::vector<fun_t>::iterator i = callbacks.begin(), end(callbacks.end());
			i != end; ++i)
		{
			fun_t const& f = *i;
			(ses->*f)();
		}
	}