I'm trying to update an old project that used libtorrent 1.1.12 (so libtorrent 1.1.12 to libtorrent current version).
When i compile it, i've these warnings:
warning C4996: 'libtorrent::session::session': was declared deprecated
warning C4996: 'libtorrent::session_handle::set_max_half_open_connections': was declared deprecated
warning C4996: 'libtorrent::session_handle::set_max_uploads': was declared deprecated
warning C4996: 'libtorrent::session_handle::set_max_connections': was declared deprecated
warning C4996: 'libtorrent::session_handle::listen_on': was declared deprecated
So my questions are:
- What is wrong with initializing "ses" in this way? Why does it report the warning?
- What about session_handle methods warnings? I haven't found any similar enums/functions in v2. For example in settings_pack enum i haven't found anything about "half_open_connections", "max_uploads" or "max_connections".
- As for listen_on, i saw in the documentation that i can use settings_pack::listen_interfaces. However, i no longer pass "ec" as a parameter. So how can i perform the check on the error_code that is right after?
- In this case, is it a good practice to disable all warnings?
With "#pragma warning(disable: 4996)"?
Finally, this is a part of the project code that reports the warnings.
bool Patcher::Begin()
{
ses = new session( // warning C4996: 'libtorrent::session::session': was declared deprecated
fingerprint("LT", LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0),
session::add_default_plugins
);
settings_pack settings;
settings.set_int(settings_pack::alert_mask, alert_category::status | alert_category::error);
// ... other settings
ses->set_max_half_open_connections(stConfig.maxHalfOpenConnections); // warning C4996: 'libtorrent::session_handle::set_max_half_open_connections': was declared deprecated
ses->set_max_uploads(stConfig.maxUploadsPerSession); // warning C4996: 'libtorrent::session_handle::set_max_uploads': was declared deprecated
ses->set_max_connections(stConfig.maxConnectionsPerSession); // warning C4996: 'libtorrent::session_handle::set_max_connections': was declared deprecated
std::pair<int, int> portRange(stConfig.minPort, stConfig.maxPort);
error_code ec;
ses->listen_on(portRange, ec, nullptr, 0); // warning C4996: 'libtorrent::session_handle::listen_on': was declared deprecated
if (ec.value() != 0)
// ...
return false;
ses->apply_settings(settings);
return true;
}
Ask the authors, or see whether they explained it already in documentation, or in the commit that introduced the deprecation.
Because the authors marked it deprecated, for reasons you should ask them about.
If something is marked deprecated, that means some other conscious entity chose to mark it deprecated because it should no longer be used in new code. See whether they explained their reasoning or just ask them.
It's never good practice to disable all warnings.
A deprecation warning is a deliberate notice that an interface or interfaces are likely to be removed in a future update. It is an opportunity to comply with the new, preferred interface, in advance.
It's up to you to read the documentation and find out what that new, preferred interface is.
For example, if some of the interfaces you're using were deprecated in this commit, it explains which overloads were deprecated and which should be preferred instead, in the commit message itself: