Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
705 views
in Technique[技术] by (71.8m points)

c++ - Alternative to missing method in last version of Boost asio library

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

There are a abstract class ICON with four subclasses.

POP3conN to flat POP3 communications

POP3conS to secure POP3 communications

SMTPconN to flat SMTP communications

SMTPconS to secure SMTP communications

ICON has a member

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

and two virtual procedures, defined in each subclass:

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

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:

[...]

Use get_executor().context() to obtain the associated 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: 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 */ } );

Becomes

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...