2

我刚刚更新了 boost 库,1.68.01.70.0获取(beast) websocket ssl client async example中的超时操作。

在上面的链接中,您将看到:

void
    on_resolve(
        beast::error_code ec,
        tcp::resolver::results_type results)
    {
        if(ec)
            return fail(ec, "resolve");

        // Set a timeout on the operation
        beast::get_lowest_layer(ws_).expires_after(std::chrono::seconds(30));

        // Make the connection on the IP address we get from a lookup
        beast::get_lowest_layer(ws_).async_connect(
            results,
            beast::bind_front_handler(
                &session::on_connect,
                shared_from_this()));
    }

有不止一个函数使用这种结构来处理超时。对于我的代码(在 eclipse-cdt 中,我看到它是这样的

截图

错误说(当鼠标指针悬停在expires_afterasync_connect上):


无法解析方法“expires_after”或无法解析
方法“async_connect”

当鼠标指针被接管“get_lowest_layer”时,错误说

无效参数'
候选者是:
boost::beast::detail::lowest_layer_type_impl<#0,bool74 0 value 43 8 2 201 2
boost::beast::detail::has_next_layer_impl
boost::beast::detail::has_next_layer_impl 1 # 0 0 71 4417 0 0>::type & get_lowest_layer(#0 &) '

我想知道我需要为此链接一些库。我不知道是哪一个。 有什么建议么?

4

2 回答 2

1

这与so库无关。

  1. boost::beast 是一个模板库,所以没有共享库。

  2. 您的编辑器使用定义而不是链接来显示此 IDE 错误。基本上,您的编辑器未能找到您指向的标题。

如果我不得不猜测,您已经手动编译了 boost 以使用 boost::beast,因为它在大多数现代 Linux 发行版上不可用。或者你可能没有使用 Linux。该示例包含一些包含,并且您的 IDE 无法解析它们,因为它们不在您的系统包含 ( /usr/include) 中。所以,它不知道去哪里找。

因此,总而言之,您的构建系统没有与您的 IDE 正确耦合。

要解决此问题,请尝试了解您的 IDE 如何解决丢失的标头。添加包含 boost 标头的包含路径。

于 2019-04-16T15:44:19.263 回答
0

通过beast 1.70.0将超时设置为

void
    on_resolve(
        beast::error_code ec,
        tcp::resolver::results_type results)
    {
        if(ec)
            return fail(ec, "resolve");

        // Set a timeout on the operation
        ws_.next_layer().expires_after(std::chrono::seconds(30));

        // Make the connection on the IP address we get from a lookup
         ws_.next_layer().async_connect(
            results,
            beast::bind_front_handler(
                &session::on_connect,
                shared_from_this()));
    }

我还对我的代码(使用beast 1.68.0)进行了一些更改,如下所示

void Foo::closetimer_websocket(beast::error_code ec) {

    if (ec.message() == "Success") {
        ioc.stop();
    }
}

// closetimer_websocket is the member of class Foo. And FooObject is its instance
void session::SetAsyncOpTimeoutInSec(unsigned int time_inSeconds) {
    TcpTimer.expires_from_now((boost::posix_time::seconds(time_inSeconds)));
    TcpTimer.async_wait(bind(&Foo::closetimer_websocket, FooObject, placeholders::_1));
}

void session::on_resolve(beast::error_code ec,
        tcp::resolver::results_type results) {
     if(ec)
            return fail(ec, "resolve");

    //Set the timeout
    SetAsyncOpTimeoutInSec(5);

    // Make the connection on the IP address we get from a lookup
    net::async_connect(ws_.next_layer().next_layer(), results.begin(),
            results.end(),
            bind(&session::on_connect, shared_from_this(), placeholders::_1));
}

于 2019-04-19T04:19:38.667 回答