使用 boost::asio::async_read 读入缓冲区时出现问题

发布于 2024-08-31 10:06:29 字数 1470 浏览 4 评论 0原文

再会。

我的项目中有一个 Types.hpp 文件。在其中我有:

....    
namespace RC 
{
 .....
 .....

 struct ViewSettings
 {
  ....
 };

 .....
}

在 Server.cpp 文件中,我包含了这个 Types.hpp 文件,并且我在那里:

class Session
{
 .....

 RC::ViewSettings tmp;
 boost::asio::async_read(socket_, boost::asio::buffer(&tmp, sizeof(RC::ViewSettings)), 
                         boost::bind(&Session::Finish_Reading_Data, shared_from_this(), boost::asio::placeholders::error));

 .....
}

在编译过程中我遇到了错误:

 error C2825: 'F': must be a class or namespace when followed by '::'
 : see reference to class template instantiation 'boost::_bi::result_traits<R,F>' 

 being compiled with
 [
  R=boost::_bi::unspecified,
  F=void (__thiscall Session::* )(void)
 ]

 : see reference to class template instantiation 'boost::_bi::bind_t<R,F,L>' 
 being compiled with
 [
  R=boost::_bi::unspecified,
  F=void (__thiscall Session::* )(void),
  L=boost::_bi::list2<boost::_bi::value<boost::shared_ptr<Session>>,boost::arg<1>>
 ]

 error C2039: 'result_type' : is not a member of '`global namespace''

像这样的代码以正确的方式工作:

   int w; 
   boost::asio::async_read(socket_, boost::asio::buffer(&w, sizeof(int)), 
                        boost::bind(&Session::Handle_Read_Width, shared_from_this(), boost::asio::placeholders::error));

请帮忙。这里有什么问题? 提前致谢。

Good day.

I have a Types.hpp file in my project. And within it i have:

....    
namespace RC 
{
 .....
 .....

 struct ViewSettings
 {
  ....
 };

 .....
}

In the Server.cpp file I'm including this Types.hpp file, and i have there:

class Session
{
 .....

 RC::ViewSettings tmp;
 boost::asio::async_read(socket_, boost::asio::buffer(&tmp, sizeof(RC::ViewSettings)), 
                         boost::bind(&Session::Finish_Reading_Data, shared_from_this(), boost::asio::placeholders::error));

 .....
}

And during the compilation i have an errors:

 error C2825: 'F': must be a class or namespace when followed by '::'
 : see reference to class template instantiation 'boost::_bi::result_traits<R,F>' 

 being compiled with
 [
  R=boost::_bi::unspecified,
  F=void (__thiscall Session::* )(void)
 ]

 : see reference to class template instantiation 'boost::_bi::bind_t<R,F,L>' 
 being compiled with
 [
  R=boost::_bi::unspecified,
  F=void (__thiscall Session::* )(void),
  L=boost::_bi::list2<boost::_bi::value<boost::shared_ptr<Session>>,boost::arg<1>>
 ]

 error C2039: 'result_type' : is not a member of '`global namespace''

And the code like this works in proper way:

   int w; 
   boost::asio::async_read(socket_, boost::asio::buffer(&w, sizeof(int)), 
                        boost::bind(&Session::Handle_Read_Width, shared_from_this(), boost::asio::placeholders::error));

Please, help. What's the problem here?
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

格子衫的從容 2024-09-07 10:06:30

您需要从 boost::enable_shared_from_this继承 Session。

You need to inherit Session from boost::enable_shared_from_this<Session>.

情丝乱 2024-09-07 10:06:29

您正在尝试传输一个结构,而不仅仅是一个简单的类型。这就是为什么它适用于 int,而不适用于 struct。

我认为这是序列化领域,所以我认为你需要 boost.serialization。

http://www.boost.org/doc/ libs/1_43_0/doc/html/boost_asio/examples.html
检查这个序列化示例,也许会对您有所帮助。

You are trying to transfer a struct, not just a simple type. That's why it works with int, and won't work with the struct.

I think this is in the area of serialization, so i think you will need boost.serialization.

http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/examples.html
Check this serialization example, maybe that will help you out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文