最新版本的Boost asio库中缺少方法的替代方法 [英] Alternative to missing method in last version of Boost asio library

查看:407
本文介绍了最新版本的Boost asio库中缺少方法的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几年前,我使用Boost asio库编写了一个电子邮件客户端.

Some years ago, I wrote a email client using Boost asio library.

有一个抽象类 ICON ,其中包含四个子类.

There are a abstract class ICON with four subclasses.

POP3conN 到平面POP3通信

POP3conS 以保护POP3通信

SMTPconN 到平面SMTP通信

SMTPconS 以保护SMTP通信

图标有一个成员

boost::asio::ip::tcp::socket socket_

和在echa子类中定义的两个虚拟过程:

and two virtual procedures, defined in echa subclass:

void SMTPconN::run() { socket_.get_io_service().run(); }
void SMTPconN::reset() { socket_.get_io_service().reset(); }

该应用程序在boost_1_63_0上运行良好.但是,当我尝试更新为boost_1_70_0时,编译器(MS V Studio 2015)在两个定义中都抱怨:

The application worked fine with boost_1_63_0. But when I try update to boost_1_70_0, the compiler (MS V Studio 2015) complains in both definitions:

class "boost::asio::ssl::stream<boost::asio::ip::tcp::socket>" has no member "get_io_service".

因为我想对大量的代码和复杂的逻辑进行最小的更改:这种遗漏的方法是否有解决方法?

Because I want do the minimal change in what is a huge amount of code and complex logic: do is there some workaround to this missed method?

推荐答案

文档位于

The docs state under Networking TS compatibility that you can use get_context().context(), which will get you a io_context instance (which replaced io_service somewhere around boost 1.64/1.65 IIRC).

网络TS兼容性

Boost.Asio现在提供网络的C ++扩展"技术规范指定的接口和功能.除了通过普通的Boost.Asio头文件进行访问之外,还可以通过与TS中定义的头文件相对应的特殊头来访问此功能.这些在下表中列出:

Networking TS compatibility

Boost.Asio now provides the interfaces and functionality specified by the "C++ Extensions for Networking" Technical Specification. In addition to access via the usual Boost.Asio header files, this functionality may be accessed through special headers that correspond to the header files defined in the TS. These are listed in the table below:

[...]

使用get_executor().context()获得关联的io_context.

Use get_executor().context() to obtain the associated io_context.

get_io_service()get_io_context()以前都是为了方便移植而设计的,但与此同时,它们也已被弃用和废弃.

Both get_io_service() and get_io_context() were previously in place to facilitate porting, but they have in the mean time also been deprecated and obsoleted.

PS:另请参见获得增强效果:: asio通过boost :: asio :: ip :: tcp :: socket中的:: io_context执行自定义功能,它与您的问题极为相似,但指定了特定的用例.

PS: Also see Get boost::asio::io_context from a boost::asio::ip::tcp::socket to exec a custom function which is eerily similar to your question but specifies a specific use-case.

针对该用例,其中的注释具有 确定更好的解决方案 :

The comments there have the decidedly better solution for that use-case:

socket.get_io_service().post([](){ /* my custom code */ } );

成为

post(socket.executor(), [](){ /* my custom code */ } );

这篇关于最新版本的Boost asio库中缺少方法的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆