[英]Io_context error in Boost Library
I'm trying to build a chat room using by Boost Libraries. 我正在尝试使用Boost Libraries建立一个聊天室。 But when I'm trying to use
asio::io_context
, the compiler says: 但是当我尝试使用
asio::io_context
,编译器说:
io_context is not an member of asio.
io_context不是asio的成员。
I built Boost 4 times and I thought maybe the problem was due to an installation failure on my part, but it doesn't seem to be. 我建了4次Boost,我想可能问题是由于我的安装失败,但似乎不是。
#include <ctime>
#include <iostream>
#include <string>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
std::string make_daytime_string()
{
using namespace std; // For time_t, time and ctime;
time_t now = time(0);
return ctime(&now);
}
class tcp_connection
: public boost::enable_shared_from_this<tcp_connection>
{
public:
typedef boost::shared_ptr<tcp_connection> pointer;
static pointer create(boost::asio::io_context& io_context)
{
return pointer(new tcp_connection(io_context));
}
tcp::socket& socket()
{
return socket_;
}
void start()
{
message_ = make_daytime_string();
boost::asio::async_write(socket_, boost::asio::buffer(message_),
boost::bind(&tcp_connection::handle_write, shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}
private:
tcp_connection(boost::asio::io_context& io_context)
: socket_(io_context)
{
}
void handle_write(const boost::system::error_code& /*error*/,
size_t /*bytes_transferred*/)
{
}
tcp::socket socket_;
std::string message_;
};
class tcp_server
{
public:
tcp_server(boost::asio::io_context& io_context) //error
: acceptor_(io_context, tcp::endpoint(tcp::v4(), 13)) //error
{
start_accept();
}
Things changed in Boost 1.66: Boost 1.66改变了一些事情:
The release notes show the renamed/changed interfaces: 发行说明显示重命名/更改的界面:
Boost.Asio now provides the interfaces and functionality specified by the "C++ Extensions for Networking" Technical Specification.
Boost.Asio现在提供“C ++网络扩展”技术规范指定的接口和功能。 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.
除了通过通常的Boost.Asio头文件进行访问之外,还可以通过与TS中定义的头文件相对应的特殊头来访问此功能。 These are listed in the table below:
这些列在下表中:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.