Asynchronous asio不';我不能耽搁吗?

Asynchronous asio不';我不能耽搁吗?,asynchronous,boost,boost-asio,Asynchronous,Boost,Boost Asio,我对asio是新手 以下是我在编写我的日间tcp服务器时遵循的指南:。我试图重现一个合理的例子,说明非同步代码实际上是异步的。我没有修改任何其他内容,只是tcp\u服务器类中的一小段代码。我添加此延迟是为了确保在等待计时器过期后,我们可以正常处理其他客户端连接/请求。那么,我错过什么了吗?因为在我的情况下,延迟基本上不起作用;( void handle\u accept(const tcp\u connection::pointer和new\u connection, 常量asio::错误(代码

我对asio是新手

以下是我在编写我的日间tcp服务器时遵循的指南:。我试图重现一个合理的例子,说明非同步代码实际上是异步的。我没有修改任何其他内容,只是
tcp\u服务器
类中的一小段代码。我添加此延迟是为了确保在等待计时器过期后,我们可以正常处理其他客户端连接/请求。那么,我错过什么了吗?因为在我的情况下,延迟基本上不起作用;(

void handle\u accept(const tcp\u connection::pointer和new\u connection,
常量asio::错误(代码和错误){
asio::稳定计时器(io_上下文,asio::时钟::秒(5));
std::cout
void handle\u accept(常量tcp\u连接::指针和新连接,
常量asio::错误(代码和错误){
asio::稳定计时器(io_上下文,asio::时钟::秒(5));

std::我不能谢谢你。现在我理解出了什么问题。但是你说的“时间可能就在它旁边”是什么意思?我该怎么做?在你的示例中,将计时器声明移到“tcp::acceptor acceptor”后面的一行一定要在构造函数中初始化它,就像
接受器一样。这是另一个是,它有帮助。再次感谢;)
void handle_accept(const tcp_connection::pointer &new_connection,
                   const asio::error_code &error) {

    asio::steady_timer timer(io_context_,  asio::chrono::seconds(5));

    std::cout << "Before timer" << std::endl;

    timer.async_wait(std::bind(&tcp_server::handle_wait, this, error, new_connection));
}

void handle_wait(asio::error_code &ec, const tcp_connection::pointer &new_connection) {
    if (!ec) {
        new_connection->start();
    }

    std::cout << "Inside timer" << std::endl;

    start_accept();
}
void handle_accept(const tcp_connection::pointer &new_connection,
                       const asio::error_code &error) {

        asio::steady_timer timer(io_context_,  asio::chrono::seconds(5));

        std::cout << "Before timer" << std::endl;

        timer.async_wait(std::bind(&tcp_server::handle_wait, this, error, new_connection));
    }