SSL [SOLVED]: How to accept boost::asio::ssl::stream<boost::asio::ip::tcp::socket> as an argument of type boost::asio::ip::tcp::socket

SSL [SOLVED]: How to accept boost::asio::ssl::stream<boost::asio::ip::tcp::socket> as an argument of type boost::asio::ip::tcp::socket

Home Forums SSL SSL [SOLVED]: How to accept boost::asio::ssl::stream<boost::asio::ip::tcp::socket> as an argument of type boost::asio::ip::tcp::socket

Tagged: , , , ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36782

    Anonymous

    QuestionQuestion

    I was trying to adapt the SSL server example in the Boost docs here but I would like to make an application where you can use normal boost::asio::ip::tcp::socket or an SSL socket but I haven’t found a good way to pass either to a function like void do_something_with_socket(boost::asio::ip::tcp::socket& sock) because the SSL socket doesn’t inherit from the raw TCP socket. The only thing I can think of is to use templates everywhere but I was wondering if there is any better way to do this? Thanks.

    Edit: I’ve looked through the members of boost::asio::ssl::stream<boost::asio::ip::tcp::socket> and I’ve found next_layer() is a boost::asio::ip::tcp::socket but I’ve tried it and it doesn’t encrypt the data because I guess this is the raw socket the SSL stream uses?

    #36783

    Anonymous

    Accepted AnswerAnswer

    Try using lowest_layer() instead of next layer.

    For example, this asio HTTP library uses”templates everywhere” and connects an SSL socket with the following code:

    void connect_socket(ConnectHandler connect_handler,
                        ASIO::ip::tcp::resolver::iterator host_iterator)
    { ASIO::async_connect(socket_.lowest_layer(), host_iterator, connect_handler); }
    

    Where socket_ is a boost::asio::ssl::stream<boost::asio::ip::tcp::socket>.

    Source: https://stackoverflow.com/questions/47999884/how-to-accept-boostasiosslstreamboostasioiptcpsocket-as-an-argum
    Author: kenba
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.