diff --git a/Doxyfile b/Doxyfile index 6366a0849d..e378c1cc9c 100644 --- a/Doxyfile +++ b/Doxyfile @@ -32,7 +32,9 @@ PROJECT_NAME = "websocketpp" # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = + +PROJECT_NUMBER = "0.3.0-dev" + # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer diff --git a/test/transport/asio/SConscript b/test/transport/asio/SConscript index bd49b0d681..e3097cdbb1 100644 --- a/test/transport/asio/SConscript +++ b/test/transport/asio/SConscript @@ -14,15 +14,15 @@ env_cpp11 = env_cpp11.Clone () BOOST_LIBS = boostlibs(['unit_test_framework','system','thread','regex'],env) + [platform_libs] + [tls_libs] objs = env.Object('base_boost.o', ["base.cpp"], LIBS = BOOST_LIBS) -#objs += env.Object('timers_boost.o', ["timers.cpp"], LIBS = BOOST_LIBS) +objs += env.Object('timers_boost.o', ["timers.cpp"], LIBS = BOOST_LIBS) prgs = env.Program('test_base_boost', ["base_boost.o"], LIBS = BOOST_LIBS) -#prgs += env.Program('test_timers_boost', ["timers_boost.o"], LIBS = BOOST_LIBS) +prgs += env.Program('test_timers_boost', ["timers_boost.o"], LIBS = BOOST_LIBS) if env_cpp11.has_key('WSPP_CPP11_ENABLED'): BOOST_LIBS_CPP11 = boostlibs(['unit_test_framework','system'],env_cpp11) + [platform_libs] + [polyfill_libs] + [tls_libs] objs += env_cpp11.Object('base_stl.o', ["base.cpp"], LIBS = BOOST_LIBS_CPP11) - #objs += env_cpp11.Object('timers_stl.o', ["timers.cpp"], LIBS = BOOST_LIBS_CPP11) + objs += env_cpp11.Object('timers_stl.o', ["timers.cpp"], LIBS = BOOST_LIBS_CPP11) prgs += env_cpp11.Program('test_base_stl', ["base_stl.o"], LIBS = BOOST_LIBS_CPP11) - #prgs += env_cpp11.Program('test_timers_stl', ["timers_stl.o"], LIBS = BOOST_LIBS_CPP11) + prgs += env_cpp11.Program('test_timers_stl', ["timers_stl.o"], LIBS = BOOST_LIBS_CPP11) Return('prgs') diff --git a/test/transport/asio/timers.cpp b/test/transport/asio/timers.cpp index e310a5143c..71255d5b7f 100644 --- a/test/transport/asio/timers.cpp +++ b/test/transport/asio/timers.cpp @@ -44,17 +44,18 @@ #include // Loggers -#include +#include +//#include #include // Accept a connection, read data, and discard until EOF -void run_dummy_server() { +void run_dummy_server(int port) { using boost::asio::ip::tcp; try { boost::asio::io_service io_service; - tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v6(), 9005)); + tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v6(), port)); tcp::socket socket(io_service); acceptor.accept(socket); @@ -76,10 +77,20 @@ void run_dummy_server() { } } +// Wait for the specified time period then fail the test +void run_test_timer(long value) { + boost::asio::io_service ios; + boost::asio::deadline_timer t(ios,boost::posix_time::milliseconds(value)); + boost::system::error_code ec; + t.wait(ec); + BOOST_FAIL( "Test timed out" ); +} + struct config { typedef websocketpp::concurrency::none concurrency_type; - typedef websocketpp::log::mock alog_type; - typedef websocketpp::log::mock elog_type; + //typedef websocketpp::log::basic alog_type; + typedef websocketpp::log::stub alog_type; + typedef websocketpp::log::stub elog_type; typedef websocketpp::http::parser::request request_type; typedef websocketpp::http::parser::response response_type; typedef websocketpp::transport::asio::tls_socket::endpoint socket_type; @@ -92,34 +103,20 @@ struct config { static const long timeout_socket_shutdown = 1000; }; -void run_test_timer() { - boost::asio::io_service ios; - boost::asio::deadline_timer t(ios,boost::posix_time::milliseconds(1000)); - t.wait(); - BOOST_FAIL( "Test timed out" ); -} - +// Mock context that does no validation typedef websocketpp::lib::shared_ptr context_ptr; context_ptr on_tls_init(websocketpp::connection_hdl hdl) { - context_ptr ctx(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1)); - - try { - ctx->set_options(boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::no_sslv2 | - boost::asio::ssl::context::single_dh_use); - } catch (std::exception& e) { - std::cout << e.what() << std::endl; - } - return ctx; + return context_ptr(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1)); } -struct stub_con: public websocketpp::transport::asio::connection { +// Mock connection +struct mock_con: public websocketpp::transport::asio::connection { typedef websocketpp::transport::asio::connection base; - stub_con(bool a, config::alog_type& b, config::elog_type& c) : base(a,b,c) {} + mock_con(bool a, config::alog_type& b, config::elog_type& c) : base(a,b,c) {} void start() { - base::init(websocketpp::lib::bind(&stub_con::handle_start,this, + base::init(websocketpp::lib::bind(&mock_con::handle_start,this, websocketpp::lib::placeholders::_1)); } @@ -128,41 +125,40 @@ struct stub_con: public websocketpp::transport::asio::connection { using websocketpp::transport::asio::socket::error::tls_handshake_timeout; BOOST_CHECK_EQUAL( ec, make_error_code(tls_handshake_timeout) ); + + base::cancel_socket(); } }; typedef websocketpp::transport::asio::connection con_type; -typedef websocketpp::lib::shared_ptr connection_ptr; +typedef websocketpp::lib::shared_ptr connection_ptr; -struct stub_endpoint : public websocketpp::transport::asio::endpoint { +struct mock_endpoint : public websocketpp::transport::asio::endpoint { typedef websocketpp::transport::asio::endpoint base; - stub_endpoint() { - base::init_logging(&mock_logger,&mock_logger); + mock_endpoint() { + alog.set_channels(websocketpp::log::alevel::all); + base::init_logging(&alog,&elog); init_asio(); } - connection_ptr connect(std::string u) { - connection_ptr con(new stub_con(true,mock_logger,mock_logger)); + void connect(std::string u) { + m_con.reset(new mock_con(false,alog,elog)); websocketpp::uri_ptr uri(new websocketpp::uri(u)); - - - BOOST_CHECK_EQUAL( base::init(con), websocketpp::lib::error_code() ); + BOOST_CHECK_EQUAL( base::init(m_con), websocketpp::lib::error_code() ); base::async_connect( - con, + m_con, uri, websocketpp::lib::bind( - &stub_endpoint::handle_connect, + &mock_endpoint::handle_connect, this, - con, + m_con, websocketpp::lib::placeholders::_1, websocketpp::lib::placeholders::_2 ) ); - - return con; } void handle_connect(connection_ptr con, websocketpp::connection_hdl, @@ -171,23 +167,20 @@ struct stub_endpoint : public websocketpp::transport::asio::endpoint { BOOST_CHECK( !ec ); con->start(); } - - void run() { - base::run(); - } - connection_ptr con; - config::alog_type mock_logger; + connection_ptr m_con; + config::alog_type alog; + config::elog_type elog; }; BOOST_AUTO_TEST_CASE( tls_handshake_timeout ) { - websocketpp::lib::thread dummy_server(&run_dummy_server); - //websocketpp::lib::thread timer(&run_test_timer); - - stub_endpoint endpoint; + websocketpp::lib::thread dummy_server(websocketpp::lib::bind(&run_dummy_server,9005)); + websocketpp::lib::thread timer(websocketpp::lib::bind(&run_test_timer,5000)); + dummy_server.detach(); + timer.detach(); + + mock_endpoint endpoint; endpoint.set_tls_init_handler(&on_tls_init); endpoint.connect("wss://localhost:9005"); endpoint.run(); - - BOOST_CHECK( true ); } \ No newline at end of file diff --git a/websocketpp/endpoint.hpp b/websocketpp/endpoint.hpp index 7c38557774..63b7579c6c 100644 --- a/websocketpp/endpoint.hpp +++ b/websocketpp/endpoint.hpp @@ -99,7 +99,7 @@ public: m_alog.write(log::alevel::devel,"endpoint constructor"); - transport_type::init_logging(&m_elog,&m_alog); + transport_type::init_logging(&m_alog,&m_elog); } /// Returns the user agent string that this endpoint will use diff --git a/websocketpp/impl/connection_impl.hpp b/websocketpp/impl/connection_impl.hpp index 9919afccdb..06b0b809d4 100644 --- a/websocketpp/impl/connection_impl.hpp +++ b/websocketpp/impl/connection_impl.hpp @@ -807,7 +807,11 @@ void connection::handle_read_frame(const lib::error_code& ec, } if (m_processor->ready()) { - //m_alog.write(log::alevel::devel,"consume ended in ready"); + if (m_alog.static_test(log::alevel::devel)) { + std::stringstream s; + s << "Complete frame received. Dispatching"; + m_alog.write(log::alevel::devel,s.str()); + } message_ptr msg = m_processor->get_message(); diff --git a/websocketpp/logger/mock.hpp b/websocketpp/logger/stub.hpp similarity index 88% rename from websocketpp/logger/mock.hpp rename to websocketpp/logger/stub.hpp index e4bd42b149..41cd30b5b6 100644 --- a/websocketpp/logger/mock.hpp +++ b/websocketpp/logger/stub.hpp @@ -25,8 +25,8 @@ * */ -#ifndef WEBSOCKETPP_LOGGER_MOCK_HPP -#define WEBSOCKETPP_LOGGER_MOCK_HPP +#ifndef WEBSOCKETPP_LOGGER_STUB_HPP +#define WEBSOCKETPP_LOGGER_STUB_HPP #include @@ -35,11 +35,11 @@ namespace websocketpp { namespace log { -/// Mock logger that does nothing! -class mock { +/// Stub logger that ignores all input! +class stub { public: - mock(std::ostream* out = &std::cout) {} - mock(level c, std::ostream* out = &std::cout) {} + stub(std::ostream* out = &std::cout) {} + stub(level c, std::ostream* out = &std::cout) {} void set_channels(level channels) {} void clear_channels(level channels) {} @@ -54,4 +54,4 @@ public: } // log } // websocketpp -#endif // WEBSOCKETPP_LOGGER_MOCK_HPP +#endif // WEBSOCKETPP_LOGGER_STUB_HPP diff --git a/websocketpp/transport/asio/endpoint.hpp b/websocketpp/transport/asio/endpoint.hpp index bd40b6a169..d95d88398a 100644 --- a/websocketpp/transport/asio/endpoint.hpp +++ b/websocketpp/transport/asio/endpoint.hpp @@ -377,9 +377,9 @@ protected: * haven't been constructed yet, and cannot be used in the transport * destructor as they will have been destroyed by then. */ - void init_logging(elog_type* e, alog_type* a) { - m_elog = e; + void init_logging(alog_type* a, elog_type* e) { m_alog = a; + m_elog = e; } void handle_accept(connection_hdl hdl, accept_handler callback, diff --git a/websocketpp/transport/asio/security/base.hpp b/websocketpp/transport/asio/security/base.hpp index ed419f701b..5760e958da 100644 --- a/websocketpp/transport/asio/security/base.hpp +++ b/websocketpp/transport/asio/security/base.hpp @@ -70,6 +70,7 @@ namespace socket { * policies and support code for the ASIO transport types. */ +/// Errors related to asio transport sockets namespace error { enum value { /// Catch-all error for security policy errors that don't fit in other @@ -98,6 +99,7 @@ namespace error { }; } // namespace error +/// Error category related to asio transport socket policies class socket_category : public lib::error_category { public: const char *name() const _WEBSOCKETPP_NOEXCEPT_TOKEN_ { @@ -135,6 +137,7 @@ inline lib::error_code make_error_code(error::value e) { return lib::error_code(static_cast(e), get_socket_category()); } +/// Type of asio transport socket policy initialization handlers typedef lib::function init_handler; } // namespace socket diff --git a/websocketpp/transport/iostream/endpoint.hpp b/websocketpp/transport/iostream/endpoint.hpp index fd80aae671..da9e6153e7 100644 --- a/websocketpp/transport/iostream/endpoint.hpp +++ b/websocketpp/transport/iostream/endpoint.hpp @@ -97,7 +97,7 @@ protected: * haven't been constructed yet, and cannot be used in the transport * destructor as they will have been destroyed by then. */ - void init_logging(elog_type* e, alog_type* a) { + void init_logging(alog_type* a, elog_type* e) { m_elog = e; m_alog = a; }