简体   繁体   中英

Boost asio async_read (async_write) wrapper

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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