How to create a boost ssl iostream?

前端 未结 3 1594
无人共我
无人共我 2020-12-08 00:47

I\'m adding HTTPS support to code that does input and output using boost tcp::iostream (acting as an HTTP server).

I\'ve found examples (and have a working toy HTTPS

3条回答
  •  臣服心动
    2020-12-08 01:24

    I think what you want to do is use stream buffers (asio::streambuf)

    Then you can do something like (untested code written on the fly follows):

    boost::asio::streambuf msg;
    std::ostream msg_stream(&msg);
    msg_stream << "hello world";
    msg_stream.flush();
    boost::asio::write(stream, msg);
    

    Similarly your read/receive side can read into a stream buffer in conjunction with std::istream so you can process your input using various stream functions/operators.

    Asio reference for streambuf

    Another note is I think you should check out the asio tutorials/examples. Once you do you'll probably want to change your code to work asynchronously rather than the synchronous example you're showing above.

提交回复
热议问题