From c005a8792d8864788d2ea30e01ff944389c992fa Mon Sep 17 00:00:00 2001 From: melode11 Date: Tue, 19 May 2015 14:45:56 +0800 Subject: [PATCH] add tls branch --- src/internal/sio_client_impl.cpp | 31 +++++++++++++++++++++++++++---- src/internal/sio_client_impl.h | 18 +++++++++++++++++- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/internal/sio_client_impl.cpp b/src/internal/sio_client_impl.cpp index 92ce0af..12d4c78 100644 --- a/src/internal/sio_client_impl.cpp +++ b/src/internal/sio_client_impl.cpp @@ -49,7 +49,9 @@ namespace sio m_client.set_close_handler(lib::bind(&client_impl::on_close,this,_1)); m_client.set_fail_handler(lib::bind(&client_impl::on_fail,this,_1)); m_client.set_message_handler(lib::bind(&client_impl::on_message,this,_1,_2)); - +#if SIO_TLS + m_client.set_tls_init_handler(lib::bind(&client_impl::on_tls_init,this,_1)); +#endif m_packet_mgr.set_decode_callback(lib::bind(&client_impl::on_decode,this,_1)); m_packet_mgr.set_encode_callback(lib::bind(&client_impl::on_encode,this,_1,_2)); @@ -198,13 +200,17 @@ namespace sio do{ websocketpp::uri uo(uri); ostringstream ss; - +#if SIO_TLS + ss<<"wss://"; +#else + ss<<"ws://"; +#endif if (m_sid.size()==0) { - ss<<"ws://"<set_options(boost::asio::ssl::context::default_workarounds | + boost::asio::ssl::context::no_sslv2 | + boost::asio::ssl::context::single_dh_use,ec); + if(ec) + { + cerr<<"Init tls failed,reason:"<< ec.message()< #if _DEBUG || DEBUG +#if SIO_TLS +#include +typedef websocketpp::config::debug_asio_tls client_config; +#else #include typedef websocketpp::config::debug_asio client_config; +#endif //SIO_TLS +#else +#if SIO_TLS +#include +typedef websocketpp::config::asio_tls_client client_config; #else #include typedef websocketpp::config::asio_client client_config; -#endif +#endif //SIO_TLS +#endif //DEBUG #include #include @@ -159,6 +169,12 @@ namespace sio void clear_timers(); + #if SIO_TLS + typedef websocketpp::lib::shared_ptr context_ptr; + + context_ptr on_tls_init(connection_hdl con); + #endif + // Connection pointer for client functions. connection_hdl m_con; client_type m_client;