【发布时间】:2022-10-14 00:03:17
【问题描述】:
我正在尝试更新一个使用 libtorrent 1.1.12 的旧项目(所以 libtorrent 1.1.12 到 libtorrent 当前版本)。
当我编译它时,我有这些警告:
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
所以我的问题是:
- 以这种方式初始化“ses”有什么问题?为什么会这样 报告警告?
- session_handle 方法警告怎么办?我没有找到任何 v2 中类似的枚举/函数。例如在 settings_pack 枚举 i 没有找到任何关于“half_open_connections”、“max_uploads”的信息 或“最大连接数”。
- 关于listen_on,我在文档中看到我可以使用 settings_pack::listen_interfaces。但是,我不再将“ec”传递为 一个参数。那么我该如何检查error_code 是在后面吗?
- 在这种情况下,禁用所有警告是否是个好习惯?
和 “#pragma 警告(禁用:4996)”?
最后,这是报告警告的项目代码的一部分。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; }
【问题讨论】:
-
你必须问图书馆的作者为什么他们选择弃用这些功能。如果我是你,我也会查看他们的文档和变更日志和提交历史,甚至可能是邮件列表档案,以了解原因并找出推荐的替代品。禁用警告肯定是我的最后的采取。
标签: c++ deprecated libtorrent