[asio]: Having trouble getting started with ssl
Hi, I tried to follow the documentation for ssl in boost::asio (Overview/SSL), coming up with a few lines of code which fail to compile with boost-1.36 (gcc-4.2.4, Ubuntu8.04, 64bit) with the following message: sslTest.cpp:13: error: invalid initialization of reference of type ‘boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >&’ from expression of type ‘boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >’ The message is pretty clear, but I have no idea yet how to fix the problem. Here is the code: // ----------------------------------------- #include <boost/asio.hpp> #include <boost/asio/ssl.hpp> using namespace std; using namespace boost::asio; int main() { io_service ioService; ssl::context ctx(ioService, ssl::context::sslv23); ssl::stream<ip::tcp::socket> sslSock(ioService, ctx); ip::tcp::socket& sock = sslSock.lowest_layer(); } // ----------------------------------------- Regards, Roland
sslTest.cpp:13: error: invalid initialization of reference of type 'boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >&' from expression of type 'boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >'
The message is pretty clear, but I have no idea yet how to fix the problem.
<...>
ip::tcp::socket& sock = sslSock.lowest_layer();
lowest_layer() returns a reference to the base type of ip::tcp::socket. So you can either declare such a reference: ssl::stream::lowest_layer_type &sock = ....; ...or (if need some members specific to tcp::socket) static_cast to the desired type.
Igor, thanks for the information. I guess I should file a bug report about the documentation then since I did pretty much exactly what is written here: http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/overview/ssl.html Regards, Roland Igor R wrote:
sslTest.cpp:13: error: invalid initialization of reference of type 'boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >&' from expression of type 'boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >'
The message is pretty clear, but I have no idea yet how to fix the problem.
<...>
ip::tcp::socket& sock = sslSock.lowest_layer();
lowest_layer() returns a reference to the base type of ip::tcp::socket. So you can either declare such a reference: ssl::stream::lowest_layer_type &sock = ....; ...or (if need some members specific to tcp::socket) static_cast to the desired type. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Igor,
thanks for the information. I guess I should file a bug report about the documentation then since I did pretty much exactly what is written here:
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/overview/ssl.html
Well, it seems that you're right: there's a bug either in the documentation or in the actual design.
participants (2)
-
Igor R
-
Roland Bock