diff --git a/.gitignore b/.gitignore index 163832df8..413af3a6f 100644 --- a/.gitignore +++ b/.gitignore @@ -78,3 +78,9 @@ examples/wsperf/wsperf_client *.out *.log +*.opensdf +*.sdf +*.vcxproj +*.vcxproj.filters +*.user +install diff --git a/.travis.yml b/.travis.yml index bf60651cb..027ac560e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ branches: - permessage-deflate - experimental - 0.3.x-cmake + - develop notifications: recipients: - travis@zaphoyd.com diff --git a/CMakeLists.txt b/CMakeLists.txt index 78a8beef1..4efcb389d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ project (websocketpp) cmake_minimum_required (VERSION 2.6) set (WEBSOCKETPP_MAJOR_VERSION 0) -set (WEBSOCKETPP_MINOR_VERSION 3) +set (WEBSOCKETPP_MINOR_VERSION 4) set (WEBSOCKETPP_PATCH_VERSION 0) set (WEBSOCKETPP_VERSION ${WEBSOCKETPP_MAJOR_VERSION}.${WEBSOCKETPP_MINOR_VERSION}.${WEBSOCKETPP_PATCH_VERSION}) @@ -87,7 +87,14 @@ if (BUILD_TESTS OR BUILD_EXAMPLES) # C++11 defines if (ENABLE_CPP11) - add_definitions (-D_WEBSOCKETPP_CPP11_STL_) + if (MSVC) + add_definitions (-D_WEBSOCKETPP_CPP11_FUNCTIONAL_) + add_definitions (-D_WEBSOCKETPP_CPP11_SYSTEM_ERROR_) + add_definitions (-D_WEBSOCKETPP_CPP11_RANDOM_DEVICE_) + add_definitions (-D_WEBSOCKETPP_CPP11_MEMORY_) + else() + add_definitions (-D_WEBSOCKETPP_CPP11_STL_) + endif() endif () # Visual studio @@ -106,7 +113,7 @@ if (BUILD_TESTS OR BUILD_EXAMPLES) set (WEBSOCKETPP_PLATFORM_LIBS pthread rt) set (WEBSOCKETPP_PLATFORM_TSL_LIBS ssl crypto) set (WEBSOCKETPP_BOOST_LIBS system thread) - set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++0x") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") if (NOT APPLE) add_definitions (-DNDEBUG -Wall -Wcast-align) # todo: should we use CMAKE_C_FLAGS for these? endif () diff --git a/COPYING b/COPYING index 7eeeb8f39..f8cc5ba1b 100644 --- a/COPYING +++ b/COPYING @@ -1,6 +1,6 @@ Main Library: -Copyright (c) 2013, Peter Thorson. All rights reserved. +Copyright (c) 2014, Peter Thorson. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/Doxyfile b/Doxyfile index 353a1fbd6..b37846173 100644 --- a/Doxyfile +++ b/Doxyfile @@ -33,7 +33,7 @@ PROJECT_NAME = "websocketpp" # if some version control system is used. -PROJECT_NUMBER = "0.3.0" +PROJECT_NUMBER = "0.4.0" # Using the PROJECT_BRIEF tag one can provide an optional one line description diff --git a/SConstruct b/SConstruct index cdb5c2273..2f35a055c 100644 --- a/SConstruct +++ b/SConstruct @@ -101,12 +101,14 @@ if env['CXX'].startswith('g++'): #env.Append(CCFLAGS = ['-Wconversion']) env.Append(CCFLAGS = ['-Wcast-align']) env.Append(CCFLAGS = ['-Wshadow']) + env.Append(CCFLAGS = ['-Wunused-parameter']) elif env['CXX'].startswith('clang++'): #env.Append(CCFLAGS = ['-Wcast-align']) #env.Append(CCFLAGS = ['-Wglobal-constructors']) #env.Append(CCFLAGS = ['-Wconversion']) env.Append(CCFLAGS = ['-Wno-padded']) env.Append(CCFLAGS = ['-Wshadow']) + env.Append(CCFLAGS = ['-Wunused-parameter']) # Wpadded # Wsign-conversion @@ -132,7 +134,7 @@ env.Append(CPPPATH = ['#']) ##### Set up C++11 environment polyfill_libs = [] # boost libraries used as drop in replacements for incomplete - # C++11 STL implementations + # C++11 STL implementations env_cpp11 = env.Clone () if env_cpp11['CXX'].startswith('g++'): @@ -165,18 +167,18 @@ else: # values then use it for the boost libraries. Otherwise just add them to the # regular CPPPATH values. if env['CXX'].startswith('g++') or env['CXX'].startswith('clang'): - env.Append(CPPFLAGS = '-isystem ' + env['BOOST_INCLUDES']) + env.Append(CPPFLAGS = '-isystem ' + env['BOOST_INCLUDES']) else: - env.Append(CPPPATH = [env['BOOST_INCLUDES']]) + env.Append(CPPPATH = [env['BOOST_INCLUDES']]) env.Append(LIBPATH = [env['BOOST_LIBS']]) # if the build system is known to allow the isystem modifier for library include # values then use it for the boost libraries. Otherwise just add them to the # regular CPPPATH values. if env_cpp11['CXX'].startswith('g++') or env_cpp11['CXX'].startswith('clang'): - env_cpp11.Append(CPPFLAGS = '-isystem ' + env_cpp11['BOOST_INCLUDES']) + env_cpp11.Append(CPPFLAGS = '-isystem ' + env_cpp11['BOOST_INCLUDES']) else: - env_cpp11.Append(CPPPATH = [env_cpp11['BOOST_INCLUDES']]) + env_cpp11.Append(CPPPATH = [env_cpp11['BOOST_INCLUDES']]) env_cpp11.Append(LIBPATH = [env_cpp11['BOOST_LIBS']]) releasedir = 'build/release/' diff --git a/changelog.md b/changelog.md index 78802d758..4ab768077 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,48 @@ -HEAD +0.4.0 - 2014-11-04 +- BREAKING API CHANGE: All WebSocket++ methods now throw an exception of type + `websocketpp::exception` which derives from `std::exception`. This normalizes + all exception types under the standard exception hierarchy and allows + WebSocket++ exceptions to be caught in the same statement as others. The error + code that was previously thrown is wrapped in the exception object and can be + accessed via the `websocketpp::exception::code()` method. +- BREAKING API CHANGE: Custom logging policies have some new required + constructors that take generic config settings rather than pointers to + std::ostreams. This allows writing logging policies that do not involve the + use of std::ostream. This does not affect anyone using the built in logging + policies. +- BREAKING UTILITY CHANGE: `websocketpp::lib::net::htonll` and + `websocketpp::lib::net::ntohll` have been prefixed with an underscore to avoid + conflicts with similarly named macros in some operating systems. If you are + using the WebSocket++ provided 64 bit host/network byte order functions you + will need to switch to the prefixed versions. +- BREAKING UTILITY CHANGE: The signature of `base64_encode` has changed from + `websocketpp::base64_encode(unsigned char const *, unsigned int)` to + `websocketpp::base64_encode(unsigned char const *, size_t)`. +- BREAKING UTILITY CHANGE: The signature of `sha1::calc` has changed from + `websocketpp::sha1::calc(void const *, int, unsigned char *)` to + `websocketpp::sha1::calc(void const *, size_t, unsigned char *)` +- Feature: Adds incomplete `minimal_server` and `minimal_client` configs that + can be used to build custom configs without pulling in the dependencies of + `core` or `core_client`. These configs will offer a stable base config to + future-proof custom configs. +- Improvement: Core library no longer has std::iostream as a dependency. + std::iostream is still required for the optional iostream logging policy and + iostream transport. +- Bug: C++11 Chrono support was being incorrectly detected by the `boost_config` + header. Thank you Max Dmitrichenko for reporting and a patch. +- Bug: use of `std::put_time` is now guarded by a unique flag rather than a + chrono library flag. Thank you Max Dmitrichenko for reporting. +- Bug: Fixes non-thread safe use of std::localtime. #347 #383 +- Compatibility: Adjust usage of std::min to be more compatible with systems + that define a min(...) macro. +- Compatibility: Removes unused parameters from all library, test, and example + code. This assists with those developing with -Werror and -Wunused-parameter + #376 +- Compatibility: Renames ntohll and htonll methods to avoid conflicts with + platform specific macros. #358 #381, #382 Thank you logotype, unphased, + svendjo +- Cleanup: Removes unused functions, fixes variable shadow warnings, normalizes + all whitespace in library, examples, and tests to 4 spaces. #376 0.3.0 - 2014-08-10 - Feature: Adds `start_perpetual` and `stop_perpetual` methods to asio transport diff --git a/docs/simple_broadcast_server.cpp b/docs/simple_broadcast_server.cpp index 504a8c94c..955d71115 100644 --- a/docs/simple_broadcast_server.cpp +++ b/docs/simple_broadcast_server.cpp @@ -36,7 +36,7 @@ class broadcast_server { void run(uint16_t port) { m_server.listen(port); - m_server.start_accept(); + m_server.start_accept(); m_server.run(); } private: diff --git a/docs/simple_count_server_thread.cpp b/docs/simple_count_server_thread.cpp index 9d2fed227..a30af9948 100644 --- a/docs/simple_count_server_thread.cpp +++ b/docs/simple_count_server_thread.cpp @@ -46,7 +46,7 @@ class count_server { void run(uint16_t port) { m_server.listen(port); - m_server.start_accept(); + m_server.start_accept(); m_server.run(); } private: diff --git a/examples/broadcast_server/broadcast_server.cpp b/examples/broadcast_server/broadcast_server.cpp index bdb01fe44..dc17250d6 100644 --- a/examples/broadcast_server/broadcast_server.cpp +++ b/examples/broadcast_server/broadcast_server.cpp @@ -59,9 +59,9 @@ class broadcast_server { m_server.listen(port); // Start the server accept loop - m_server.start_accept(); + m_server.start_accept(); - // Start the ASIO io_service run loop + // Start the ASIO io_service run loop try { m_server.run(); } catch (const std::exception & e) { @@ -142,18 +142,18 @@ class broadcast_server { }; int main() { - try { - broadcast_server server_instance; + try { + broadcast_server server_instance; - // Start a thread to run the processing loop - thread t(bind(&broadcast_server::process_messages,&server_instance)); + // Start a thread to run the processing loop + thread t(bind(&broadcast_server::process_messages,&server_instance)); - // Run the asio loop with the main thread - server_instance.run(9002); + // Run the asio loop with the main thread + server_instance.run(9002); - t.join(); + t.join(); - } catch (std::exception & e) { - std::cout << e.what() << std::endl; - } + } catch (std::exception & e) { + std::cout << e.what() << std::endl; + } } diff --git a/examples/debug_client/debug_client.cpp b/examples/debug_client/debug_client.cpp index f68559673..d8d84b185 100644 --- a/examples/debug_client/debug_client.cpp +++ b/examples/debug_client/debug_client.cpp @@ -74,25 +74,25 @@ class perftest { client::connection_ptr con = m_endpoint.get_connection(uri, ec); if (ec) { - m_endpoint.get_alog().write(websocketpp::log::alevel::app,ec.message()); + m_endpoint.get_alog().write(websocketpp::log::alevel::app,ec.message()); } //con->set_proxy("http://humupdates.uchicago.edu:8443"); m_endpoint.connect(con); - // Start the ASIO io_service run loop - m_start = std::chrono::high_resolution_clock::now(); + // Start the ASIO io_service run loop + m_start = std::chrono::high_resolution_clock::now(); m_endpoint.run(); } - void on_socket_init(websocketpp::connection_hdl hdl) { + void on_socket_init(websocketpp::connection_hdl) { m_socket_init = std::chrono::high_resolution_clock::now(); } - context_ptr on_tls_init(websocketpp::connection_hdl hdl) { + context_ptr on_tls_init(websocketpp::connection_hdl) { m_tls_init = std::chrono::high_resolution_clock::now(); - context_ptr ctx(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1)); + context_ptr ctx = websocketpp::lib::make_shared(boost::asio::ssl::context::tlsv1); try { ctx->set_options(boost::asio::ssl::context::default_workarounds | @@ -108,11 +108,11 @@ class perftest { m_open = std::chrono::high_resolution_clock::now(); m_endpoint.send(hdl, "", websocketpp::frame::opcode::text); } - void on_message(websocketpp::connection_hdl hdl, message_ptr msg) { + void on_message(websocketpp::connection_hdl hdl, message_ptr) { m_message = std::chrono::high_resolution_clock::now(); m_endpoint.close(hdl,websocketpp::close::status::going_away,""); } - void on_close(websocketpp::connection_hdl hdl) { + void on_close(websocketpp::connection_hdl) { m_close = std::chrono::high_resolution_clock::now(); std::cout << "Socket Init: " << std::chrono::duration_cast(m_socket_init-m_start).count() << std::endl; @@ -133,13 +133,13 @@ class perftest { }; int main(int argc, char* argv[]) { - std::string uri = "wss://echo.websocket.org"; + std::string uri = "wss://echo.websocket.org"; - if (argc == 2) { - uri = argv[1]; - } + if (argc == 2) { + uri = argv[1]; + } - try { + try { perftest endpoint; endpoint.start(uri); } catch (const std::exception & e) { diff --git a/examples/debug_server/debug_server.cpp b/examples/debug_server/debug_server.cpp index 724ec3c40..68b320e58 100644 --- a/examples/debug_server/debug_server.cpp +++ b/examples/debug_server/debug_server.cpp @@ -59,10 +59,10 @@ void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { } int main() { - // Create a server endpoint + // Create a server endpoint server echo_server; - try { + try { // Set logging settings echo_server.set_access_channels(websocketpp::log::alevel::all); echo_server.clear_access_channels(websocketpp::log::alevel::frame_payload); @@ -80,7 +80,7 @@ int main() { // Start the server accept loop echo_server.start_accept(); - // Start the ASIO io_service run loop + // Start the ASIO io_service run loop echo_server.run(); } catch (const std::exception & e) { std::cout << e.what() << std::endl; diff --git a/examples/dev/main.cpp b/examples/dev/main.cpp index 9e93f6842..3b7bdfbb0 100644 --- a/examples/dev/main.cpp +++ b/examples/dev/main.cpp @@ -1,5 +1,5 @@ //#ifndef _WEBSOCKETPP_CPP11_STL_ -// #define _WEBSOCKETPP_CPP11_STL_ +// #define _WEBSOCKETPP_CPP11_STL_ //#endif #include @@ -24,177 +24,177 @@ typedef websocketpp::server server; /*class handler : public server::handler { - bool validate(connection_ptr con) { - std::cout << "handler validate" << std::endl; - if (con->get_origin() != "http://www.example.com") { - con->set_status(websocketpp::http::status_code::FORBIDDEN); - return false; - } - return true; - } - - void http(connection_ptr con) { - std::cout << "handler http" << std::endl; - } - - void on_load(connection_ptr con, ptr old_handler) { - std::cout << "handler on_load" << std::endl; - } - void on_unload(connection_ptr con, ptr new_handler) { - std::cout << "handler on_unload" << std::endl; - } - - void on_open(connection_ptr con) { - std::cout << "handler on_open" << std::endl; - } - void on_fail(connection_ptr con) { - std::cout << "handler on_fail" << std::endl; - } - - void on_message(connection_ptr con, message_ptr msg) { - std::cout << "handler on_message" << std::endl; - - - } - - void on_close(connection_ptr con) { - std::cout << "handler on_close" << std::endl; - } + bool validate(connection_ptr con) { + std::cout << "handler validate" << std::endl; + if (con->get_origin() != "http://www.example.com") { + con->set_status(websocketpp::http::status_code::FORBIDDEN); + return false; + } + return true; + } + + void http(connection_ptr con) { + std::cout << "handler http" << std::endl; + } + + void on_load(connection_ptr con, ptr old_handler) { + std::cout << "handler on_load" << std::endl; + } + void on_unload(connection_ptr con, ptr new_handler) { + std::cout << "handler on_unload" << std::endl; + } + + void on_open(connection_ptr con) { + std::cout << "handler on_open" << std::endl; + } + void on_fail(connection_ptr con) { + std::cout << "handler on_fail" << std::endl; + } + + void on_message(connection_ptr con, message_ptr msg) { + std::cout << "handler on_message" << std::endl; + + + } + + void on_close(connection_ptr con) { + std::cout << "handler on_close" << std::endl; + } };*/ int main() { - typedef websocketpp::message_buffer::message - message_type; - typedef websocketpp::message_buffer::alloc::con_msg_manager - con_msg_man_type; + typedef websocketpp::message_buffer::message + message_type; + typedef websocketpp::message_buffer::alloc::con_msg_manager + con_msg_man_type; - con_msg_man_type::ptr manager(new con_msg_man_type()); + con_msg_man_type::ptr manager = websocketpp::lib::make_shared(); - size_t foo = 1024; + size_t foo = 1024; - message_type::ptr input = manager->get_message(websocketpp::frame::opcode::TEXT,foo); - message_type::ptr output = manager->get_message(websocketpp::frame::opcode::TEXT,foo); - websocketpp::frame::masking_key_type key; + message_type::ptr input = manager->get_message(websocketpp::frame::opcode::TEXT,foo); + message_type::ptr output = manager->get_message(websocketpp::frame::opcode::TEXT,foo); + websocketpp::frame::masking_key_type key; - std::random_device dev; + std::random_device dev; - key.i = 0x12345678; + key.i = 0x12345678; - double m = 18094238402394.0824923; + double m = 18094238402394.0824923; - /*std::cout << "Some Math" << std::endl; - { - boost::timer::auto_cpu_timer t; + /*std::cout << "Some Math" << std::endl; + { + boost::timer::auto_cpu_timer t; - for (int i = 0; i < foo; i++) { - m /= 1.001; - } + for (int i = 0; i < foo; i++) { + m /= 1.001; + } - }*/ + }*/ - std::cout << m << std::endl; + std::cout << m << std::endl; - std::cout << "Random Gen" << std::endl; - { - boost::timer::auto_cpu_timer t; + std::cout << "Random Gen" << std::endl; + { + boost::timer::auto_cpu_timer t; - input->get_raw_payload().replace(0,foo,foo,'\0'); - output->get_raw_payload().replace(0,foo,foo,'\0'); - } + input->get_raw_payload().replace(0,foo,foo,'\0'); + output->get_raw_payload().replace(0,foo,foo,'\0'); + } - std::cout << "Out of place accelerated" << std::endl; - { - boost::timer::auto_cpu_timer t; + std::cout << "Out of place accelerated" << std::endl; + { + boost::timer::auto_cpu_timer t; - websocketpp::frame::word_mask_exact(reinterpret_cast(const_cast(input->get_raw_payload().data())), reinterpret_cast(const_cast(output->get_raw_payload().data())), foo, key); - } + websocketpp::frame::word_mask_exact(reinterpret_cast(const_cast(input->get_raw_payload().data())), reinterpret_cast(const_cast(output->get_raw_payload().data())), foo, key); + } - std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; - std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; + std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; + std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; - input->get_raw_payload().replace(0,foo,foo,'\0'); - output->get_raw_payload().replace(0,foo,foo,'\0'); + input->get_raw_payload().replace(0,foo,foo,'\0'); + output->get_raw_payload().replace(0,foo,foo,'\0'); - std::cout << "In place accelerated" << std::endl; - { - boost::timer::auto_cpu_timer t; + std::cout << "In place accelerated" << std::endl; + { + boost::timer::auto_cpu_timer t; - websocketpp::frame::word_mask_exact(reinterpret_cast(const_cast(input->get_raw_payload().data())), reinterpret_cast(const_cast(input->get_raw_payload().data())), foo, key); - } + websocketpp::frame::word_mask_exact(reinterpret_cast(const_cast(input->get_raw_payload().data())), reinterpret_cast(const_cast(input->get_raw_payload().data())), foo, key); + } - std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; - std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; + std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; + std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; - input->get_raw_payload().replace(0,foo,foo,'\0'); - output->get_raw_payload().replace(0,foo,foo,'\0'); - std::cout << "Out of place byte by byte" << std::endl; - { - boost::timer::auto_cpu_timer t; + input->get_raw_payload().replace(0,foo,foo,'\0'); + output->get_raw_payload().replace(0,foo,foo,'\0'); + std::cout << "Out of place byte by byte" << std::endl; + { + boost::timer::auto_cpu_timer t; - websocketpp::frame::byte_mask(input->get_raw_payload().begin(), input->get_raw_payload().end(), output->get_raw_payload().begin(), key); - } + websocketpp::frame::byte_mask(input->get_raw_payload().begin(), input->get_raw_payload().end(), output->get_raw_payload().begin(), key); + } - std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; - std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; + std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; + std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; - input->get_raw_payload().replace(0,foo,foo,'\0'); - output->get_raw_payload().replace(0,foo,foo,'\0'); - std::cout << "In place byte by byte" << std::endl; - { - boost::timer::auto_cpu_timer t; + input->get_raw_payload().replace(0,foo,foo,'\0'); + output->get_raw_payload().replace(0,foo,foo,'\0'); + std::cout << "In place byte by byte" << std::endl; + { + boost::timer::auto_cpu_timer t; - websocketpp::frame::byte_mask(input->get_raw_payload().begin(), input->get_raw_payload().end(), input->get_raw_payload().begin(), key); - } + websocketpp::frame::byte_mask(input->get_raw_payload().begin(), input->get_raw_payload().end(), input->get_raw_payload().begin(), key); + } - std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; - std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; + std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; + std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; - input->get_raw_payload().replace(0,foo,foo,'a'); - output->get_raw_payload().replace(0,foo,foo,'b'); - std::cout << "Copy" << std::endl; - { - boost::timer::auto_cpu_timer t; + input->get_raw_payload().replace(0,foo,foo,'a'); + output->get_raw_payload().replace(0,foo,foo,'b'); + std::cout << "Copy" << std::endl; + { + boost::timer::auto_cpu_timer t; - std::copy(input->get_raw_payload().begin(), input->get_raw_payload().end(), output->get_raw_payload().begin()); - } + std::copy(input->get_raw_payload().begin(), input->get_raw_payload().end(), output->get_raw_payload().begin()); + } - std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; - std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; + std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; + std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; - /*server::handler::ptr h(new handler()); + /*server::handler::ptr h(new handler()); - server test_server(h); - server::connection_ptr con; + server test_server(h); + server::connection_ptr con; - std::stringstream output; + std::stringstream output; - test_server.register_ostream(&output); + test_server.register_ostream(&output); - con = test_server.get_connection(); + con = test_server.get_connection(); - con->start(); + con->start(); - //foo.handle_accept(con,true); + //foo.handle_accept(con,true); - std::stringstream input; - input << "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n"; - //input << "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; - input >> *con; + std::stringstream input; + input << "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n"; + //input << "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; + input >> *con; - std::stringstream input2; - input2 << "messageabc2"; - input2 >> *con; + std::stringstream input2; + input2 << "messageabc2"; + input2 >> *con; - std::stringstream input3; - input3 << "messageabc3"; - input3 >> *con; + std::stringstream input3; + input3 << "messageabc3"; + input3 >> *con; - std::stringstream input4; - input4 << "close"; - input4 >> *con; + std::stringstream input4; + input4 << "close"; + input4 >> *con; - std::cout << "connection output:" << std::endl; - std::cout << output.str() << std::endl;*/ + std::cout << "connection output:" << std::endl; + std::cout << output.str() << std::endl;*/ } diff --git a/examples/echo_server/echo_handler.hpp b/examples/echo_server/echo_handler.hpp index f90634212..f55b867a2 100644 --- a/examples/echo_server/echo_handler.hpp +++ b/examples/echo_server/echo_handler.hpp @@ -29,9 +29,9 @@ #define WEBSOCKETPP_ECHO_SERVER_HANDLER_HPP class echo_handler : public server::handler { - void on_message(connection_ptr con, std::string msg) { - con->write(msg); - } + void on_message(connection_ptr con, std::string msg) { + con->write(msg); + } }; #endif // WEBSOCKETPP_ECHO_SERVER_HANDLER_HPP diff --git a/examples/echo_server/echo_server.cpp b/examples/echo_server/echo_server.cpp index f1f60e2d2..59fc1fcb1 100644 --- a/examples/echo_server/echo_server.cpp +++ b/examples/echo_server/echo_server.cpp @@ -28,10 +28,10 @@ void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { } int main() { - // Create a server endpoint + // Create a server endpoint server echo_server; - try { + try { // Set logging settings echo_server.set_access_channels(websocketpp::log::alevel::all); echo_server.clear_access_channels(websocketpp::log::alevel::frame_payload); @@ -48,7 +48,7 @@ int main() { // Start the server accept loop echo_server.start_accept(); - // Start the ASIO io_service run loop + // Start the ASIO io_service run loop echo_server.run(); } catch (const std::exception & e) { std::cout << e.what() << std::endl; diff --git a/examples/echo_server_tls/echo_server_tls.cpp b/examples/echo_server_tls/echo_server_tls.cpp index feeb05b87..6523a77cc 100644 --- a/examples/echo_server_tls/echo_server_tls.cpp +++ b/examples/echo_server_tls/echo_server_tls.cpp @@ -33,7 +33,7 @@ std::string get_password() { context_ptr on_tls_init(websocketpp::connection_hdl hdl) { std::cout << "on_tls_init called with hdl: " << hdl.lock().get() << std::endl; - context_ptr ctx(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1)); + context_ptr ctx = websocketpp::lib::make_shared(boost::asio::ssl::context::tlsv1); try { ctx->set_options(boost::asio::ssl::context::default_workarounds | @@ -50,23 +50,23 @@ context_ptr on_tls_init(websocketpp::connection_hdl hdl) { int main() { // Create a server endpoint - server echo_server; + server echo_server; // Initialize ASIO - echo_server.init_asio(); + echo_server.init_asio(); // Register our message handler echo_server.set_message_handler(bind(&on_message,&echo_server,::_1,::_2)); echo_server.set_tls_init_handler(bind(&on_tls_init,::_1)); - // Listen on port 9002 - echo_server.listen(9002); + // Listen on port 9002 + echo_server.listen(9002); - // Start the server accept loop - echo_server.start_accept(); + // Start the server accept loop + echo_server.start_accept(); - // Start the ASIO io_service run loop - echo_server.run(); + // Start the ASIO io_service run loop + echo_server.run(); } diff --git a/examples/iostream_server/iostream_server.cpp b/examples/iostream_server/iostream_server.cpp index 5ade71a34..0114fbf0c 100644 --- a/examples/iostream_server/iostream_server.cpp +++ b/examples/iostream_server/iostream_server.cpp @@ -18,17 +18,17 @@ typedef server::message_ptr message_ptr; void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { if (msg->get_opcode() == websocketpp::frame::opcode::text) { s->get_alog().write(websocketpp::log::alevel::app, - "Text Message Received: "+msg->get_payload()); + "Text Message Received: "+msg->get_payload()); } else { s->get_alog().write(websocketpp::log::alevel::app, - "Binary Message Received: "+websocketpp::utility::to_hex(msg->get_payload())); + "Binary Message Received: "+websocketpp::utility::to_hex(msg->get_payload())); } try { s->send(hdl, msg->get_payload(), msg->get_opcode()); } catch (const websocketpp::lib::error_code& e) { s->get_alog().write(websocketpp::log::alevel::app, - "Echo Failed: "+e.message()); + "Echo Failed: "+e.message()); } } @@ -36,7 +36,7 @@ int main() { server s; std::ofstream log; - try { + try { // set up access channels to only log interesting things s.clear_access_channels(websocketpp::log::alevel::all); s.set_access_channels(websocketpp::log::alevel::connect); diff --git a/examples/print_server/print_server.cpp b/examples/print_server/print_server.cpp index 962ec45ae..78fb0e8f9 100644 --- a/examples/print_server/print_server.cpp +++ b/examples/print_server/print_server.cpp @@ -5,7 +5,7 @@ typedef websocketpp::server server; -void on_message(websocketpp::connection_hdl hdl, server::message_ptr msg) { +void on_message(websocketpp::connection_hdl, server::message_ptr msg) { std::cout << msg->get_payload() << std::endl; } diff --git a/examples/sip_client/sip_client.cpp b/examples/sip_client/sip_client.cpp index 990d76fc3..0854955ee 100644 --- a/examples/sip_client/sip_client.cpp +++ b/examples/sip_client/sip_client.cpp @@ -43,13 +43,13 @@ void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) { int main(int argc, char* argv[]) { - std::string uri = "ws://localhost:9001"; + std::string uri = "ws://localhost:9001"; - if (argc == 2) { - uri = argv[1]; - } + if (argc == 2) { + uri = argv[1]; + } - try { + try { // We expect there to be a lot of errors, so suppress them sip_client.clear_access_channels(websocketpp::log::alevel::all); sip_client.clear_error_channels(websocketpp::log::elevel::all); @@ -69,7 +69,7 @@ int main(int argc, char* argv[]) { sip_client.connect(con); - // Start the ASIO io_service run loop + // Start the ASIO io_service run loop sip_client.run(); while(!received) { diff --git a/examples/telemetry_client/telemetry_client.cpp b/examples/telemetry_client/telemetry_client.cpp index f3db649aa..658fb3d46 100644 --- a/examples/telemetry_client/telemetry_client.cpp +++ b/examples/telemetry_client/telemetry_client.cpp @@ -37,13 +37,13 @@ class telemetry_client { // This method will block until the connection is complete void run(const std::string & uri) { - // Create a new connection to the given URI + // Create a new connection to the given URI websocketpp::lib::error_code ec; client::connection_ptr con = m_client.get_connection(uri, ec); if (ec) { - m_client.get_alog().write(websocketpp::log::alevel::app, - "Get Connection Error: "+ec.message()); - return; + m_client.get_alog().write(websocketpp::log::alevel::app, + "Get Connection Error: "+ec.message()); + return; } // Grab a handle for this connection so we can talk to it in a thread @@ -65,7 +65,7 @@ class telemetry_client { } // The open handler will signal that we are ready to start sending telemetry - void on_open(websocketpp::connection_hdl hdl) { + void on_open(websocketpp::connection_hdl) { m_client.get_alog().write(websocketpp::log::alevel::app, "Connection opened, starting telemetry!"); @@ -74,7 +74,7 @@ class telemetry_client { } // The close handler will signal that we should stop sending telemetry - void on_close(websocketpp::connection_hdl hdl) { + void on_close(websocketpp::connection_hdl) { m_client.get_alog().write(websocketpp::log::alevel::app, "Connection closed, stopping telemetry!"); @@ -83,7 +83,7 @@ class telemetry_client { } // The fail handler will signal that we should stop sending telemetry - void on_fail(websocketpp::connection_hdl hdl) { + void on_fail(websocketpp::connection_hdl) { m_client.get_alog().write(websocketpp::log::alevel::app, "Connection failed, stopping telemetry!"); @@ -128,7 +128,7 @@ class telemetry_client { // in this simple example, we'll stop the telemetry loop. if (ec) { m_client.get_alog().write(websocketpp::log::alevel::app, - "Send Error: "+ec.message()); + "Send Error: "+ec.message()); break; } diff --git a/examples/testee_client/testee_client.cpp b/examples/testee_client/testee_client.cpp index d2e0545b1..57f50436a 100644 --- a/examples/testee_client/testee_client.cpp +++ b/examples/testee_client/testee_client.cpp @@ -28,16 +28,16 @@ void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) { } int main(int argc, char* argv[]) { - // Create a server endpoint + // Create a server endpoint client c; - std::string uri = "ws://localhost:9001"; + std::string uri = "ws://localhost:9001"; - if (argc == 2) { - uri = argv[1]; - } + if (argc == 2) { + uri = argv[1]; + } - try { + try { // We expect there to be a lot of errors, so suppress them c.clear_access_channels(websocketpp::log::alevel::all); c.clear_error_channels(websocketpp::log::elevel::all); @@ -52,7 +52,7 @@ int main(int argc, char* argv[]) { client::connection_ptr con = c.get_connection(uri+"/getCaseCount", ec); c.connect(con); - // Start the ASIO io_service run loop + // Start the ASIO io_service run loop c.run(); std::cout << "case count: " << case_count << std::endl; diff --git a/examples/testee_server/testee_server.cpp b/examples/testee_server/testee_server.cpp index a21ff3366..1c9910e8c 100644 --- a/examples/testee_server/testee_server.cpp +++ b/examples/testee_server/testee_server.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Peter Thorson. All rights reserved. + * Copyright (c) 2014, Peter Thorson. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -80,7 +80,7 @@ void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { s->send(hdl, msg->get_payload(), msg->get_opcode()); } -void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket & s) { +void on_socket_init(websocketpp::connection_hdl, boost::asio::ip::tcp::socket & s) { boost::asio::ip::tcp::no_delay option(true); s.set_option(option); } @@ -124,7 +124,7 @@ int main(int argc, char * argv[]) { typedef websocketpp::lib::shared_ptr thread_ptr; std::vector ts; for (size_t i = 0; i < num_threads; i++) { - ts.push_back(thread_ptr(new websocketpp::lib::thread(&server::run, &testee_server))); + ts.push_back(websocketpp::lib::make_shared(&server::run, &testee_server)); } for (size_t i = 0; i < num_threads; i++) { diff --git a/examples/utility_client/utility_client.cpp b/examples/utility_client/utility_client.cpp index 9b5a25c0d..4f0b8900e 100644 --- a/examples/utility_client/utility_client.cpp +++ b/examples/utility_client/utility_client.cpp @@ -119,7 +119,7 @@ class websocket_endpoint { m_endpoint.init_asio(); m_endpoint.start_perpetual(); - m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint)); + m_thread = websocketpp::lib::make_shared(&client::run, &m_endpoint); } ~websocket_endpoint() { @@ -155,7 +155,7 @@ class websocket_endpoint { } int new_id = m_next_id++; - connection_metadata::ptr metadata_ptr(new connection_metadata(new_id, con->get_handle(), uri)); + connection_metadata::ptr metadata_ptr = websocketpp::lib::make_shared(new_id, con->get_handle(), uri); m_connection_list[new_id] = metadata_ptr; con->set_open_handler(websocketpp::lib::bind( diff --git a/readme.md b/readme.md index 685562319..2afd14e94 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -WebSocket++ (0.3.0) +WebSocket++ (0.4.0) ========================== WebSocket++ is a header only C++ library that implements RFC6455 The WebSocket diff --git a/roadmap.md b/roadmap.md index ee74655e6..b35c54ad0 100644 --- a/roadmap.md +++ b/roadmap.md @@ -16,24 +16,23 @@ Complete & Tested: - open_handler - close_handler - echo_server & echo_server_tls - -Implemented, needs more testing -- TLS support - External io_service support -- socket_init_handler -- tls_init_handler -- tcp_init_handler +- TLS support - exception/error handling +- Timeouts - Subprotocol negotiation +- validate_handler - Hybi 00/Hixie 76 legacy protocol support -- Performance tuning - Outgoing Proxy Support +- socket_init_handler +- tls_init_handler +- tcp_init_handler + +Ongoing work +- Performance tuning - PowerPC support - Visual Studio / Windows support -- Timeouts - CMake build/install support - -- validate_handler - http_handler Future feature roadmap diff --git a/test/connection/connection.cpp b/test/connection/connection.cpp index 401ea0ff2..3f107b348 100644 --- a/test/connection/connection.cpp +++ b/test/connection/connection.cpp @@ -37,9 +37,9 @@ BOOST_AUTO_TEST_CASE( basic_http_request ) { std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; std::string output = "HTTP/1.1 426 Upgrade Required\r\nServer: " + - std::string(websocketpp::user_agent)+"\r\n\r\n"; + std::string(websocketpp::user_agent)+"\r\n\r\n"; - std::string o2 = run_server_test(input); + std::string o2 = run_server_test(input); BOOST_CHECK(o2 == output); } @@ -83,10 +83,10 @@ struct connection_setup { connection_setup(bool p_is_server) : c(p_is_server, "", alog, elog, rng) {} websocketpp::lib::error_code ec; - stub_config::alog_type alog; + stub_config::alog_type alog; stub_config::elog_type elog; - stub_config::rng_type rng; - websocketpp::connection c; + stub_config::rng_type rng; + websocketpp::connection c; }; /*void echo_func(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { @@ -127,8 +127,8 @@ BOOST_AUTO_TEST_CASE( basic_websocket_request ) { output+=websocketpp::user_agent; output+="\r\nUpgrade: websocket\r\n\r\n"; - server s; - s.set_message_handler(bind(&echo_func,&s,::_1,::_2)); + server s; + s.set_message_handler(bind(&echo_func,&s,::_1,::_2)); BOOST_CHECK(run_server_test(s,input) == output); } @@ -139,8 +139,8 @@ BOOST_AUTO_TEST_CASE( http_request ) { output+=websocketpp::user_agent; output+="\r\n\r\n/foo/bar"; - server s; - s.set_http_handler(bind(&http_func,&s,::_1)); + server s; + s.set_http_handler(bind(&http_func,&s,::_1)); BOOST_CHECK_EQUAL(run_server_test(s,input), output); } @@ -149,9 +149,9 @@ BOOST_AUTO_TEST_CASE( request_no_server_header ) { std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n"; std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nUpgrade: websocket\r\n\r\n"; - server s; - s.set_user_agent(""); - s.set_message_handler(bind(&echo_func,&s,::_1,::_2)); + server s; + s.set_user_agent(""); + s.set_message_handler(bind(&echo_func,&s,::_1,::_2)); BOOST_CHECK_EQUAL(run_server_test(s,input), output); } @@ -160,10 +160,10 @@ BOOST_AUTO_TEST_CASE( request_no_server_header_override ) { std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n"; std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: foo\r\nUpgrade: websocket\r\n\r\n"; - server s; - s.set_user_agent(""); - s.set_message_handler(bind(&echo_func,&s,::_1,::_2)); - s.set_validate_handler(bind(&validate_set_ua,&s,::_1)); + server s; + s.set_user_agent(""); + s.set_message_handler(bind(&echo_func,&s,::_1,::_2)); + s.set_validate_handler(bind(&validate_set_ua,&s,::_1)); BOOST_CHECK_EQUAL(run_server_test(s,input), output); } @@ -173,21 +173,21 @@ BOOST_AUTO_TEST_CASE( basic_client_websocket ) { //std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: foo\r\nUpgrade: websocket\r\n\r\n"; - std::string ref = "GET / HTTP/1.1\r\nConnection: Upgrade\r\nFoo: Bar\r\nHost: localhost\r\nSec-WebSocket-Key: AAAAAAAAAAAAAAAAAAAAAA==\r\nSec-WebSocket-Version: 13\r\nUpgrade: websocket\r\nUser-Agent: foo\r\n\r\n"; + std::string ref = "GET / HTTP/1.1\r\nConnection: Upgrade\r\nFoo: Bar\r\nHost: localhost\r\nSec-WebSocket-Key: AAAAAAAAAAAAAAAAAAAAAA==\r\nSec-WebSocket-Version: 13\r\nUpgrade: websocket\r\nUser-Agent: foo\r\n\r\n"; - std::stringstream output; + std::stringstream output; - client e; - e.set_access_channels(websocketpp::log::alevel::none); + client e; + e.set_access_channels(websocketpp::log::alevel::none); e.set_error_channels(websocketpp::log::elevel::none); - e.set_user_agent("foo"); - e.register_ostream(&output); + e.set_user_agent("foo"); + e.register_ostream(&output); - client::connection_ptr con; - websocketpp::lib::error_code ec; - con = e.get_connection(uri, ec); - con->append_header("Foo","Bar"); - e.connect(con); + client::connection_ptr con; + websocketpp::lib::error_code ec; + con = e.get_connection(uri, ec); + con->append_header("Foo","Bar"); + e.connect(con); BOOST_CHECK_EQUAL(ref, output.str()); } @@ -207,9 +207,9 @@ BOOST_AUTO_TEST_CASE( set_max_message_size ) { output.append(frame1, 4); output.append("A message was too large"); - server s; - s.set_user_agent(""); - s.set_validate_handler(bind(&validate_set_ua,&s,::_1)); + server s; + s.set_user_agent(""); + s.set_validate_handler(bind(&validate_set_ua,&s,::_1)); s.set_max_message_size(2); BOOST_CHECK_EQUAL(run_server_test(s,input), output); @@ -231,10 +231,10 @@ BOOST_AUTO_TEST_CASE( user_reject_origin ) { BOOST_AUTO_TEST_CASE( basic_text_message ) { std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n"; - unsigned char frames[8] = {0x82,0x82,0xFF,0xFF,0xFF,0xFF,0xD5,0xD5}; - input.append(reinterpret_cast(frames),8); + unsigned char frames[8] = {0x82,0x82,0xFF,0xFF,0xFF,0xFF,0xD5,0xD5}; + input.append(reinterpret_cast(frames),8); - std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: "+websocketpp::USER_AGENT+"\r\nUpgrade: websocket\r\n\r\n**"; + std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: "+websocketpp::USER_AGENT+"\r\nUpgrade: websocket\r\n\r\n**"; BOOST_CHECK( run_server_test(input) == output); } diff --git a/test/connection/connection_tu2.cpp b/test/connection/connection_tu2.cpp index ee0d6a980..2a1c0163e 100644 --- a/test/connection/connection_tu2.cpp +++ b/test/connection/connection_tu2.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Peter Thorson. All rights reserved. + * Copyright (c) 2014, Peter Thorson. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -40,18 +40,18 @@ std::string run_server_test(server & s, std::string input) { server::connection_ptr con; std::stringstream output; - s.clear_access_channels(websocketpp::log::alevel::all); + s.clear_access_channels(websocketpp::log::alevel::all); s.clear_error_channels(websocketpp::log::elevel::all); - s.register_ostream(&output); + s.register_ostream(&output); - con = s.get_connection(); - con->start(); + con = s.get_connection(); + con->start(); - std::stringstream channel; + std::stringstream channel; - channel << input; - channel >> *con; + channel << input; + channel >> *con; - return output.str(); + return output.str(); } diff --git a/test/connection/connection_tu2.hpp b/test/connection/connection_tu2.hpp index b4e95216d..b54afa1ff 100644 --- a/test/connection/connection_tu2.hpp +++ b/test/connection/connection_tu2.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Peter Thorson. All rights reserved. + * Copyright (c) 2014, Peter Thorson. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/test/endpoint/endpoint.cpp b/test/endpoint/endpoint.cpp index da3c839ca..79cbe6290 100644 --- a/test/endpoint/endpoint.cpp +++ b/test/endpoint/endpoint.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Peter Thorson. All rights reserved. + * Copyright (c) 2014, Peter Thorson. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/test/http/parser.cpp b/test/http/parser.cpp index beaa8fb71..d8a551a5e 100644 --- a/test/http/parser.cpp +++ b/test/http/parser.cpp @@ -54,24 +54,24 @@ BOOST_AUTO_TEST_CASE( is_token_char ) { // numbers for (int i = 0x30; i < 0x3a; i++) { - BOOST_CHECK( websocketpp::http::is_token_char((unsigned char)(i)) ); + BOOST_CHECK( websocketpp::http::is_token_char((unsigned char)(i)) ); } // upper for (int i = 0x41; i < 0x5b; i++) { - BOOST_CHECK( websocketpp::http::is_token_char((unsigned char)(i)) ); + BOOST_CHECK( websocketpp::http::is_token_char((unsigned char)(i)) ); } // lower for (int i = 0x61; i < 0x7b; i++) { - BOOST_CHECK( websocketpp::http::is_token_char((unsigned char)(i)) ); + BOOST_CHECK( websocketpp::http::is_token_char((unsigned char)(i)) ); } // invalid characters // lower unprintable for (int i = 0; i < 33; i++) { - BOOST_CHECK( !websocketpp::http::is_token_char((unsigned char)(i)) ); + BOOST_CHECK( !websocketpp::http::is_token_char((unsigned char)(i)) ); } // misc @@ -95,7 +95,7 @@ BOOST_AUTO_TEST_CASE( is_token_char ) { // upper unprintable and out of ascii range for (int i = 127; i < 256; i++) { - BOOST_CHECK( !websocketpp::http::is_token_char((unsigned char)(i)) ); + BOOST_CHECK( !websocketpp::http::is_token_char((unsigned char)(i)) ); } // is not @@ -412,9 +412,9 @@ BOOST_AUTO_TEST_CASE( blank_consume ) { bool exception = false; try { - r.consume(raw.c_str(),raw.size()); + r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == false ); @@ -429,9 +429,9 @@ BOOST_AUTO_TEST_CASE( blank_request ) { bool exception = false; try { - r.consume(raw.c_str(),raw.size()); + r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == true ); @@ -446,9 +446,9 @@ BOOST_AUTO_TEST_CASE( bad_request_no_host ) { bool exception = false; try { - r.consume(raw.c_str(),raw.size()); + r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == true ); @@ -464,10 +464,10 @@ BOOST_AUTO_TEST_CASE( basic_request ) { size_t pos = 0; try { - pos = r.consume(raw.c_str(),raw.size()); + pos = r.consume(raw.c_str(),raw.size()); } catch (std::exception &e) { - exception = true; - std::cout << e.what() << std::endl; + exception = true; + std::cout << e.what() << std::endl; } BOOST_CHECK( exception == false ); @@ -488,9 +488,9 @@ BOOST_AUTO_TEST_CASE( trailing_body_characters ) { size_t pos = 0; try { - pos = r.consume(raw.c_str(),raw.size()); + pos = r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == false ); @@ -512,11 +512,11 @@ BOOST_AUTO_TEST_CASE( basic_split1 ) { size_t pos = 0; try { - pos += r.consume(raw.c_str(),raw.size()); - pos += r.consume(raw2.c_str(),raw2.size()); + pos += r.consume(raw.c_str(),raw.size()); + pos += r.consume(raw2.c_str(),raw2.size()); } catch (std::exception &e) { - exception = true; - std::cout << e.what() << std::endl; + exception = true; + std::cout << e.what() << std::endl; } BOOST_CHECK( exception == false ); @@ -538,11 +538,11 @@ BOOST_AUTO_TEST_CASE( basic_split2 ) { size_t pos = 0; try { - pos += r.consume(raw.c_str(),raw.size()); - pos += r.consume(raw2.c_str(),raw2.size()); + pos += r.consume(raw.c_str(),raw.size()); + pos += r.consume(raw2.c_str(),raw2.size()); } catch (std::exception &e) { - exception = true; - std::cout << e.what() << std::endl; + exception = true; + std::cout << e.what() << std::endl; } BOOST_CHECK( exception == false ); @@ -563,11 +563,11 @@ BOOST_AUTO_TEST_CASE( max_header_len ) { size_t pos = 0; try { - pos += r.consume(raw.c_str(),raw.size()); + pos += r.consume(raw.c_str(),raw.size()); } catch (const websocketpp::http::exception& e) { - if (e.m_error_code == websocketpp::http::status_code::request_header_fields_too_large) { - exception = true; - } + if (e.m_error_code == websocketpp::http::status_code::request_header_fields_too_large) { + exception = true; + } } BOOST_CHECK( exception == true ); @@ -583,12 +583,12 @@ BOOST_AUTO_TEST_CASE( max_header_len_split ) { size_t pos = 0; try { - pos += r.consume(raw.c_str(),raw.size()); - pos += r.consume(raw2.c_str(),raw2.size()); + pos += r.consume(raw.c_str(),raw.size()); + pos += r.consume(raw2.c_str(),raw2.size()); } catch (const websocketpp::http::exception& e) { - if (e.m_error_code == websocketpp::http::status_code::request_header_fields_too_large) { - exception = true; - } + if (e.m_error_code == websocketpp::http::status_code::request_header_fields_too_large) { + exception = true; + } } BOOST_CHECK( exception == true ); @@ -603,9 +603,9 @@ BOOST_AUTO_TEST_CASE( firefox_full_request ) { size_t pos = 0; try { - pos += r.consume(raw.c_str(),raw.size()); + pos += r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == false ); @@ -636,9 +636,9 @@ BOOST_AUTO_TEST_CASE( bad_method ) { bool exception = false; try { - r.consume(raw.c_str(),raw.size()); + r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == true ); @@ -652,9 +652,9 @@ BOOST_AUTO_TEST_CASE( bad_header_name ) { bool exception = false; try { - r.consume(raw.c_str(),raw.size()); + r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == true ); @@ -669,9 +669,9 @@ BOOST_AUTO_TEST_CASE( old_http_version ) { size_t pos = 0; try { - pos = r.consume(raw.c_str(),raw.size()); + pos = r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == false ); @@ -692,9 +692,9 @@ BOOST_AUTO_TEST_CASE( new_http_version1 ) { size_t pos = 0; try { - pos = r.consume(raw.c_str(),raw.size()); + pos = r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == false ); @@ -715,9 +715,9 @@ BOOST_AUTO_TEST_CASE( new_http_version2 ) { size_t pos = 0; try { - pos = r.consume(raw.c_str(),raw.size()); + pos = r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == false ); @@ -740,9 +740,9 @@ BOOST_AUTO_TEST_CASE( new_http_version3 ) { size_t pos = 0; try { - pos = r.consume(raw.c_str(),raw.size()); + pos = r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == true ); @@ -757,9 +757,9 @@ BOOST_AUTO_TEST_CASE( header_whitespace1 ) { size_t pos = 0; try { - pos = r.consume(raw.c_str(),raw.size()); + pos = r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == false ); @@ -780,9 +780,9 @@ BOOST_AUTO_TEST_CASE( header_whitespace2 ) { size_t pos = 0; try { - pos = r.consume(raw.c_str(),raw.size()); + pos = r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == false ); @@ -803,9 +803,9 @@ BOOST_AUTO_TEST_CASE( header_aggregation ) { size_t pos = 0; try { - pos = r.consume(raw.c_str(),raw.size()); + pos = r.consume(raw.c_str(),raw.size()); } catch (...) { - exception = true; + exception = true; } BOOST_CHECK( exception == false ); @@ -826,10 +826,10 @@ BOOST_AUTO_TEST_CASE( wikipedia_example_response ) { size_t pos = 0; try { - pos += r.consume(raw.c_str(),raw.size()); + pos += r.consume(raw.c_str(),raw.size()); } catch (std::exception &e) { - exception = true; - std::cout << e.what() << std::endl; + exception = true; + std::cout << e.what() << std::endl; } BOOST_CHECK( exception == false ); @@ -853,10 +853,10 @@ BOOST_AUTO_TEST_CASE( response_with_non_standard_lws ) { size_t pos = 0; try { - pos += r.consume(raw.c_str(),raw.size()); + pos += r.consume(raw.c_str(),raw.size()); } catch (std::exception &e) { - exception = true; - std::cout << e.what() << std::endl; + exception = true; + std::cout << e.what() << std::endl; } BOOST_CHECK( exception == false ); @@ -880,10 +880,10 @@ BOOST_AUTO_TEST_CASE( plain_http_response ) { size_t pos = 0; try { - pos += r.consume(raw.c_str(),raw.size()); + pos += r.consume(raw.c_str(),raw.size()); } catch (std::exception &e) { - exception = true; - std::cout << e.what() << std::endl; + exception = true; + std::cout << e.what() << std::endl; } BOOST_CHECK( exception == false ); @@ -915,10 +915,10 @@ BOOST_AUTO_TEST_CASE( parse_istream ) { size_t pos = 0; try { - pos += r.consume(s); + pos += r.consume(s); } catch (std::exception &e) { - exception = true; - std::cout << e.what() << std::endl; + exception = true; + std::cout << e.what() << std::endl; } BOOST_CHECK_EQUAL( exception, false ); diff --git a/test/http/parser_perf.cpp b/test/http/parser_perf.cpp index 9e3d2b5c8..0c76bc77a 100644 --- a/test/http/parser_perf.cpp +++ b/test/http/parser_perf.cpp @@ -31,111 +31,111 @@ class scoped_timer { public: - scoped_timer(std::string i) : m_id(i),m_start(std::chrono::steady_clock::now()) { - std::cout << "Clock " << i << ": "; - } - ~scoped_timer() { - std::chrono::nanoseconds time_taken = std::chrono::steady_clock::now()-m_start; + scoped_timer(std::string i) : m_id(i),m_start(std::chrono::steady_clock::now()) { + std::cout << "Clock " << i << ": "; + } + ~scoped_timer() { + std::chrono::nanoseconds time_taken = std::chrono::steady_clock::now()-m_start; - //nanoseconds_per_test + //nanoseconds_per_test - //tests_per_second + //tests_per_second - //1000000000.0/(double(time_taken.count())/1000.0) + //1000000000.0/(double(time_taken.count())/1000.0) - std::cout << 1000000000.0/(double(time_taken.count())/1000.0) << std::endl; + std::cout << 1000000000.0/(double(time_taken.count())/1000.0) << std::endl; - //std::cout << (1.0/double(time_taken.count())) * double(1000000000*1000) << std::endl; - } + //std::cout << (1.0/double(time_taken.count())) * double(1000000000*1000) << std::endl; + } private: - std::string m_id; - std::chrono::steady_clock::time_point m_start; + std::string m_id; + std::chrono::steady_clock::time_point m_start; }; int main() { - std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; - - std::string firefox = "GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n"; - - std::string firefox1 = "GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\n"; - - std::string firefox2 = "Accept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n"; - - { - scoped_timer timer("Simplest 1 chop"); - for (int i = 0; i < 1000; i++) { - websocketpp::http::parser::request r; - - try { - r.consume(raw.c_str(),raw.size()); - } catch (...) { - std::cout << "exception" << std::endl; - } - - if (!r.ready()) { - std::cout << "error" << std::endl; - break; - } - } - } - - { - scoped_timer timer("FireFox, 1 chop, consume old"); - for (int i = 0; i < 1000; i++) { - websocketpp::http::parser::request r; - - try { - r.consume2(firefox.c_str(),firefox.size()); - } catch (...) { - std::cout << "exception" << std::endl; - } - - if (!r.ready()) { - std::cout << "error" << std::endl; - break; - } - } - } - - { - scoped_timer timer("FireFox, 1 chop"); - for (int i = 0; i < 1000; i++) { - websocketpp::http::parser::request r; - - try { - r.consume(firefox.c_str(),firefox.size()); - } catch (...) { - std::cout << "exception" << std::endl; - } - - if (!r.ready()) { - std::cout << "error" << std::endl; - break; - } - } - } - - - - { - scoped_timer timer("FireFox, 2 chop"); - for (int i = 0; i < 1000; i++) { - websocketpp::http::parser::request r; - - try { - r.consume(firefox1.c_str(),firefox1.size()); - r.consume(firefox2.c_str(),firefox2.size()); - } catch (...) { - std::cout << "exception" << std::endl; - } - - if (!r.ready()) { - std::cout << "error" << std::endl; - break; - } - } - } - - return 0; + std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; + + std::string firefox = "GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n"; + + std::string firefox1 = "GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\n"; + + std::string firefox2 = "Accept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n"; + + { + scoped_timer timer("Simplest 1 chop"); + for (int i = 0; i < 1000; i++) { + websocketpp::http::parser::request r; + + try { + r.consume(raw.c_str(),raw.size()); + } catch (...) { + std::cout << "exception" << std::endl; + } + + if (!r.ready()) { + std::cout << "error" << std::endl; + break; + } + } + } + + { + scoped_timer timer("FireFox, 1 chop, consume old"); + for (int i = 0; i < 1000; i++) { + websocketpp::http::parser::request r; + + try { + r.consume2(firefox.c_str(),firefox.size()); + } catch (...) { + std::cout << "exception" << std::endl; + } + + if (!r.ready()) { + std::cout << "error" << std::endl; + break; + } + } + } + + { + scoped_timer timer("FireFox, 1 chop"); + for (int i = 0; i < 1000; i++) { + websocketpp::http::parser::request r; + + try { + r.consume(firefox.c_str(),firefox.size()); + } catch (...) { + std::cout << "exception" << std::endl; + } + + if (!r.ready()) { + std::cout << "error" << std::endl; + break; + } + } + } + + + + { + scoped_timer timer("FireFox, 2 chop"); + for (int i = 0; i < 1000; i++) { + websocketpp::http::parser::request r; + + try { + r.consume(firefox1.c_str(),firefox1.size()); + r.consume(firefox2.c_str(),firefox2.size()); + } catch (...) { + std::cout << "exception" << std::endl; + } + + if (!r.ready()) { + std::cout << "error" << std::endl; + break; + } + } + } + + return 0; } diff --git a/test/logger/basic.cpp b/test/logger/basic.cpp index f955967a2..de51e5ad2 100644 --- a/test/logger/basic.cpp +++ b/test/logger/basic.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Peter Thorson. All rights reserved. + * Copyright (c) 2014, Peter Thorson. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/test/message_buffer/alloc.cpp b/test/message_buffer/alloc.cpp index 2a0dc3203..9f6ba2ab7 100644 --- a/test/message_buffer/alloc.cpp +++ b/test/message_buffer/alloc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Peter Thorson. All rights reserved. + * Copyright (c) 2014, Peter Thorson. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -35,62 +35,62 @@ template