简体   繁体   English

提升 asio async_read (async_write) 包装器

[英]Boost asio async_read (async_write) wrapper

I'm trying to code a wrapper over a boost::asio::ip::tcp::socket我正在尝试在 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...)所以我可以无缝地使用 ssl 和非 SSL stream ......唯一的事情是,我似乎没有找到每个参数的定义来将它们传递给 boost::asio::async_read (命名空间等) ..)

Any help would be appreciated !任何帮助,将不胜感激 ! Thanks谢谢

Your main requirements seems to be "use SSL and non-SSL streams seamlessly."您的主要要求似乎是“无缝使用 SSL 和非 SSL 流”。 To do that, you can wrap a the various stream types in a way that exposes the functions you need to use.为此,您可以包装各种 stream 类型,以公开您需要使用的功能。

Part of how you do that is deciding how you're going to do memory management.您如何做到这一点的一部分是决定您将如何进行 memory 管理。 MutableBufferSequence is not a type, it defines a set of requirements for a type to be used on that context. MutableBufferSequence 不是一种类型,它为要在该上下文中使用的类型定义了一组要求。

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).如果您打算使用少数几种方法中的一种,您可以在接口中使用它们(只要它满足 MutableBufferSequence/ConstBufferSequence 要求,就可以了)。 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如果您想保持 asio 缓冲区管理的灵活性,那么您可以

  • Template your code on stream type in order to achieve the seamless SSL/non-SSL requirement.在 stream 类型上模板化您的代码,以实现无缝的 SSL/非 SSL 要求。

  • Create a wrapper for the various stream types with templated methods on buffer type.使用缓冲区类型的模板化方法为各种 stream 类型创建一个包装器。

(Updated response; I shouldn't try to respond to a question like this when I have less than two minutes!) (更新的回复;当我不到两分钟的时间,我不应该尝试回答这样的问题!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM