开发者

Boost asio async_read (async_write) wrapper

开发者 https://www.devze.com 2023-03-17 02:48 出处:网络
I\'m trying to code a wrapper over a boost::asio::ip::tcp::socket Something like that : class Socket { public:

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


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!)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号