Boost asio async_read (async_write) wrapper

倾然丶 夕夏残阳落幕 提交于 2019-12-24 07:35:37

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/6560208/boost-asio-async-read-async-write-wrapper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!