I have these typedefs the problem is I need pass a secure socket as TSocket will a direct cast from TSecureSocket to TSocket work ? or is there another solution? depending on the port I will make the socket secure and in others I will not. I just need the return type to be TSocket.
typedef boost::asio::ip::tcp::socket TBoostSocket;
typedef boost::asio::ssl::stream<TBoostSocket> TSLLSocket;
typedef boost::shared_ptr<TBoostSocket> TSocket;
typedef boost::shared_ptr<TSLLSocket> TSecureSocket;
I have looked at this
boost::asio convert socket to secure
Short Answer No. Because
boost::asio::ssl::stream<TBoostSocket>wraps the socket.However
TSLLSocket(or boost::asio::ssl::stream rather) provides a method for retrieving the socket from an instance:http://www.boost.org/doc/libs/1_52_0/doc/html/boost_asio/reference/ssl__stream/next_layer/overload1.html
Where
next_layer_typeis defined by the following typedef:http://www.boost.org/doc/libs/1_52_0/doc/html/boost_asio/reference/ssl__stream/next_layer_type.html
Since you define your template with
TBoostSocketthat is what you should get when you callnext_layer()orlowest_layer()Of course this returns a reference not a pointer, and that reference is to an instance not owned by you. So you will now need to somehow wrap this in a shared_ptr, and that may not be that easy since you can’t allow it to be deleted.