Boost asio async_read (async_write) 包装器

发布于 2024-11-18 05:53:15 字数 491 浏览 3 评论 0原文

我正在尝试在 boost::asio::ip::tcp::socket 上编写一个包装器

class Socket {
  public:
    void async_read(AsyncReadStream & s,                     
                    const boost::asio::MutableBufferSequence & buffers,   
                    CompletionCondition completion_condition,
                    ReadHandler handler) {};
};

这样我就可以无缝地使用 ssl 和非 ssl 流...... 唯一的事情是,我似乎没有找到每个参数的定义来将它们传递给 boost::asio::async_read (命名空间等...)

任何帮助将不胜感激!谢谢

I'm trying to code a wrapper over a boost::asio::ip::tcp::socket

Something like that :

class Socket {
  public:
    void async_read(AsyncReadStream & s,                     
                    const boost::asio::MutableBufferSequence & buffers,   
                    CompletionCondition completion_condition,
                    ReadHandler handler) {};
};

So I would be able to use ssl and non-ssl stream seamlessly...
The only thing is that, I do not seems to find the definition of each parameters to pass them to boost::asio::async_read (namespaces, etc...)

Any help would be appreciated ! Thanks

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

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

发布评论

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

评论(1

得不到的就毁灭 2024-11-25 05:53:15

您的主要要求似乎是“无缝使用 SSL 和非 SSL 流”。为此,您可以以公开需要使用的函数的方式包装各种流类型。

做到这一点的一部分是决定如何进行内存管理。 MutableBufferSequence 不是一种类型,它定义了在该上下文中使用的类型的一组要求。

如果您打算使用少数方法之一,则可以在接口中使用它们(只要它满足 MutableBufferSequence/ConstBufferSequence 要求,适当)。这样做的缺点是缓冲区管理成为接口的一部分。

如果您想保持 asio 缓冲区管理的灵活性,那么您可以

  • 在流类型上模板化您的代码,以实现无缝 SSL/非 SSL 要求。

  • 使用缓冲区类型的模板化方法为各种流类型创建包装器。

(更新回复;当我的时间少于两分钟时,我不应该尝试回答这样的问题!)

Your main requirements seems to be "use SSL and non-SSL streams seamlessly." To do that, you can wrap a the various stream types in a way that exposes the functions you need to use.

Part of how you do that is deciding how you're going to do memory management. MutableBufferSequence is not a type, it defines a set of requirements for a type to be used on that context.

If you are going to use one of a smallish number of approaches you can just use them in the interface (as long as it meets the MutableBufferSequence/ConstBufferSequence requirements, appropriate). The downside of this is that buffer management becomes part of the interface.

If you want to maintain the asio buffer management flexibility then you could

  • Template your code on stream type in order to achieve the seamless SSL/non-SSL requirement.

  • Create a wrapper for the various stream types with templated methods on buffer type.

(Updated response; I shouldn't try to respond to a question like this when I have less than two minutes!)

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