Compare commits

..

1 Commits

Author SHA1 Message Date
Peter Thorson bded14b635 Merge branch 'master' into tutorials 2014-03-25 07:24:28 -05:00
146 changed files with 1753 additions and 3339 deletions
-6
View File
@@ -78,9 +78,3 @@ examples/wsperf/wsperf_client
*.out
*.log
*.opensdf
*.sdf
*.vcxproj
*.vcxproj.filters
*.user
install
-1
View File
@@ -14,7 +14,6 @@ branches:
- permessage-deflate
- experimental
- 0.3.x-cmake
- develop
notifications:
recipients:
- travis@zaphoyd.com
+3 -10
View File
@@ -9,7 +9,7 @@ project (websocketpp)
cmake_minimum_required (VERSION 2.6)
set (WEBSOCKETPP_MAJOR_VERSION 0)
set (WEBSOCKETPP_MINOR_VERSION 4)
set (WEBSOCKETPP_MINOR_VERSION 3)
set (WEBSOCKETPP_PATCH_VERSION 0)
set (WEBSOCKETPP_VERSION ${WEBSOCKETPP_MAJOR_VERSION}.${WEBSOCKETPP_MINOR_VERSION}.${WEBSOCKETPP_PATCH_VERSION})
@@ -87,14 +87,7 @@ if (BUILD_TESTS OR BUILD_EXAMPLES)
# C++11 defines
if (ENABLE_CPP11)
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()
add_definitions (-D_WEBSOCKETPP_CPP11_STL_)
endif ()
# Visual studio
@@ -113,7 +106,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 ()
+1 -1
View File
@@ -1,6 +1,6 @@
Main Library:
Copyright (c) 2014, Peter Thorson. All rights reserved.
Copyright (c) 2013, 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:
+1 -1
View File
@@ -33,7 +33,7 @@ PROJECT_NAME = "websocketpp"
# if some version control system is used.
PROJECT_NUMBER = "0.4.0"
PROJECT_NUMBER = "0.3.0-alpha4"
# Using the PROJECT_BRIEF tag one can provide an optional one line description
+5 -8
View File
@@ -101,14 +101,12 @@ 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
@@ -134,7 +132,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++'):
@@ -167,18 +165,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/'
@@ -216,7 +214,6 @@ echo_server = SConscript('#/examples/echo_server/SConscript',variant_dir = build
# echo_server_tls
if tls_build:
echo_server_tls = SConscript('#/examples/echo_server_tls/SConscript',variant_dir = builddir + 'echo_server_tls',duplicate = 0)
echo_server_both = SConscript('#/examples/echo_server_both/SConscript',variant_dir = builddir + 'echo_server_both',duplicate = 0)
# broadcast_server
broadcast_server = SConscript('#/examples/broadcast_server/SConscript',variant_dir = builddir + 'broadcast_server',duplicate = 0)
+1 -50
View File
@@ -1,50 +1,4 @@
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
HEAD
- Feature: Adds `start_perpetual` and `stop_perpetual` methods to asio transport
These may be used to replace manually managed `asio::io_service::work` objects
- Feature: Allow setting pong and handshake timeouts at runtime.
@@ -63,9 +17,6 @@
- Feature: Adds the ability to specify a maximum message size.
- Feature: Adds `close::status::get_string(...)` method to look up a human
readable string given a close code value.
- Feature: Adds `connection::read_all(...)` method to iostream transport as a
convenience method for reading all data into the connection buffer without the
end user needing to manually loop on `read_some`.
- Improvement: Open, close, and pong timeouts can be disabled entirely by
setting their duration to 0.
- Improvement: Numerous performance improvements. Including: tuned default
+1 -1
View File
@@ -36,7 +36,7 @@ public:
void run(uint16_t port) {
m_server.listen(port);
m_server.start_accept();
m_server.start_accept();
m_server.run();
}
private:
+1 -1
View File
@@ -46,7 +46,7 @@ public:
void run(uint16_t port) {
m_server.listen(port);
m_server.start_accept();
m_server.start_accept();
m_server.run();
}
private:
+12 -12
View File
@@ -59,9 +59,9 @@ public:
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 @@ private:
};
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;
}
}
+13 -13
View File
@@ -74,25 +74,25 @@ public:
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) {
void on_socket_init(websocketpp::connection_hdl hdl) {
m_socket_init = std::chrono::high_resolution_clock::now();
}
context_ptr on_tls_init(websocketpp::connection_hdl) {
context_ptr on_tls_init(websocketpp::connection_hdl hdl) {
m_tls_init = std::chrono::high_resolution_clock::now();
context_ptr ctx = websocketpp::lib::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::tlsv1);
context_ptr ctx(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1));
try {
ctx->set_options(boost::asio::ssl::context::default_workarounds |
@@ -108,11 +108,11 @@ public:
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) {
void on_message(websocketpp::connection_hdl hdl, message_ptr msg) {
m_message = std::chrono::high_resolution_clock::now();
m_endpoint.close(hdl,websocketpp::close::status::going_away,"");
}
void on_close(websocketpp::connection_hdl) {
void on_close(websocketpp::connection_hdl hdl) {
m_close = std::chrono::high_resolution_clock::now();
std::cout << "Socket Init: " << std::chrono::duration_cast<dur_type>(m_socket_init-m_start).count() << std::endl;
@@ -133,13 +133,13 @@ private:
};
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) {
+3 -3
View File
@@ -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;
+122 -122
View File
@@ -1,5 +1,5 @@
//#ifndef _WEBSOCKETPP_CPP11_STL_
// #define _WEBSOCKETPP_CPP11_STL_
// #define _WEBSOCKETPP_CPP11_STL_
//#endif
#include <random>
@@ -24,177 +24,177 @@
typedef websocketpp::server<websocketpp::config::core> 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;
}
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 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_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_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_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;
}
void on_close(connection_ptr con) {
std::cout << "handler on_close" << std::endl;
}
};*/
int main() {
typedef websocketpp::message_buffer::message<websocketpp::message_buffer::alloc::con_msg_manager>
message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_man_type;
typedef websocketpp::message_buffer::message<websocketpp::message_buffer::alloc::con_msg_manager>
message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_man_type;
con_msg_man_type::ptr manager = websocketpp::lib::make_shared<con_msg_man_type>();
con_msg_man_type::ptr manager(new con_msg_man_type());
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<uint8_t*>(const_cast<char*>(input->get_raw_payload().data())), reinterpret_cast<uint8_t*>(const_cast<char*>(output->get_raw_payload().data())), foo, key);
}
websocketpp::frame::word_mask_exact(reinterpret_cast<uint8_t*>(const_cast<char*>(input->get_raw_payload().data())), reinterpret_cast<uint8_t*>(const_cast<char*>(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<uint8_t*>(const_cast<char*>(input->get_raw_payload().data())), reinterpret_cast<uint8_t*>(const_cast<char*>(input->get_raw_payload().data())), foo, key);
}
websocketpp::frame::word_mask_exact(reinterpret_cast<uint8_t*>(const_cast<char*>(input->get_raw_payload().data())), reinterpret_cast<uint8_t*>(const_cast<char*>(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;*/
}
+3 -3
View File
@@ -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
+3 -3
View File
@@ -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;
-15
View File
@@ -1,15 +0,0 @@
file (GLOB SOURCE_FILES *.cpp)
file (GLOB HEADER_FILES *.hpp)
if (OPENSSL_FOUND)
init_target (echo_server_both)
build_executable (${TARGET_NAME} ${SOURCE_FILES} ${HEADER_FILES})
link_boost ()
link_openssl()
final_target ()
endif()
-24
View File
@@ -1,24 +0,0 @@
## Combo plain+tls echo server
##
Import('env')
Import('env_cpp11')
Import('boostlibs')
Import('platform_libs')
Import('polyfill_libs')
Import('tls_libs')
env = env.Clone ()
env_cpp11 = env_cpp11.Clone ()
prgs = []
# if a C++11 environment is available build using that, otherwise use boost
if env_cpp11.has_key('WSPP_CPP11_ENABLED'):
ALL_LIBS = boostlibs(['system'],env_cpp11) + [platform_libs] + [polyfill_libs] + [tls_libs]
prgs += env_cpp11.Program('echo_server_both', ["echo_server_both.cpp"], LIBS = ALL_LIBS)
else:
ALL_LIBS = boostlibs(['system'],env) + [platform_libs] + [polyfill_libs] + [tls_libs]
prgs += env.Program('echo_server_both', ["echo_server_both.cpp"], LIBS = ALL_LIBS)
Return('prgs')
@@ -1,86 +0,0 @@
#include <websocketpp/config/asio.hpp>
#include <websocketpp/server.hpp>
#include <iostream>
// define types for two different server endpoints, one for each config we are
// using
typedef websocketpp::server<websocketpp::config::asio> server_plain;
typedef websocketpp::server<websocketpp::config::asio_tls> server_tls;
// alias some of the bind related functions as they are a bit long
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
// type of the ssl context pointer is long so alias it
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
// The shared on_message handler takes a template parameter so the function can
// resolve any endpoint dependent types like message_ptr or connection_ptr
template <typename EndpointType>
void on_message(EndpointType* s, websocketpp::connection_hdl hdl,
typename EndpointType::message_ptr msg)
{
std::cout << "on_message called with hdl: " << hdl.lock().get()
<< " and message: " << msg->get_payload()
<< std::endl;
try {
s->send(hdl, msg->get_payload(), msg->get_opcode());
} catch (const websocketpp::lib::error_code& e) {
std::cout << "Echo failed because: " << e
<< "(" << e.message() << ")" << std::endl;
}
}
// No change to TLS init methods from echo_server_tls
std::string get_password() {
return "test";
}
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));
try {
ctx->set_options(boost::asio::ssl::context::default_workarounds |
boost::asio::ssl::context::no_sslv2 |
boost::asio::ssl::context::single_dh_use);
ctx->set_password_callback(bind(&get_password));
ctx->use_certificate_chain_file("server.pem");
ctx->use_private_key_file("server.pem", boost::asio::ssl::context::pem);
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
return ctx;
}
int main() {
// set up an external io_service to run both endpoints on. This is not
// strictly necessary, but simplifies thread management a bit.
boost::asio::io_service ios;
// set up plain endpoint
server_plain endpoint_plain;
// initialize asio with our external io_service rather than an internal one
endpoint_plain.init_asio(&ios);
endpoint_plain.set_message_handler(
bind(&on_message<server_plain>,&endpoint_plain,::_1,::_2));
endpoint_plain.listen(80);
endpoint_plain.start_accept();
// set up tls endpoint
server_tls endpoint_tls;
endpoint_tls.init_asio(&ios);
endpoint_tls.set_message_handler(
bind(&on_message<server_tls>,&endpoint_tls,::_1,::_2));
// TLS endpoint has an extra handler for the tls init
endpoint_tls.set_tls_init_handler(bind(&on_tls_init,::_1));
// tls endpoint listens on a different port
endpoint_tls.listen(443);
endpoint_tls.start_accept();
// Start the ASIO io_service run loop running both endpoints
ios.run();
}
-58
View File
@@ -1,58 +0,0 @@
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,A0ED66EF872A48A9
gXuvKojXzApVhhPVNdRliiajbC4PtwQG5c8TA7JADLgwOR7o9t6KtXEr37bDRpvB
9aO9P+SJaK5OOp3XKPGthOdqv+tvCRTlmzmC8GjPLBX389DWT2xoGu7JkGwDtdSm
rnF49Rlp5bfjpACk5xKNiKeDo1CWfeEJzw9Kto0g+5eMaEdors64oPzjXs3geA2g
TxCJSHv9qSX6++pCLKKCUTbyzidAxV/Zb0AAubt5V40QKqX4HhSwwstFnTaX3tlb
3QOdY+y04VIkM6d7qN5W8M7NzRkMpZ1qBpQcUMpkhQcRzWP2wub5AAff9D2GntRd
4Dz1vn3u41U3Okdr0CNj+iH7byCzuokoAhk6ZQEN6WB+GTpGgfBXdtUZrfpb0MKm
UNYP5AF2AmUqJRXhViTDVtu/V2tHF3LGuNT+W2Dz+spFZEq0byEO0N858eR0dikc
6jOASvNQbSwD0+mkgBC1gXKKU3ngj2gpJUwljeACdWFd8N2egrZfyI05CmX7vPNC
NXbs7k2buWNdjP4/D8IM+HDVidWzQa/kG/qokXKqllem9Egg37lUucwnP3cX2/Hw
U2mfaBWzeZtqc+GqRp08rYIql+Reai3sUYlQMnNk01prVY47UQb+dxuqjaxGV5Xx
Xkx0s2mfQnNRjL4S7Hjhqelufi6GpkCQ2EGsPpA+6K1ztZ0ame9Q2BE1SXeM/6vU
rxT5nRrCxueyXAyQSGcqMX9//gSeK8WWBqG/c1IAMVDa0NWrJeOJhSziE+ta3B0m
bHAPBY6vh0iB3lLdRlbUOPbC6R1TpxMOs+6Vbs2+OTifFpvOVymEoZq/nroyg68P
vn5uCKogwWA7o8EArf/UTlIwWJmH9bgILdZKld4wMel2HQg16RDzm+mEXAJi52a/
FC+fgfphdxltmUJ+rqOyR4AHULjaTWUQqTIB6sdlzgmES1nXAiE71zX//KFqomar
O60SPPk3C1bs0x5DsvmGJa8SIfDhyd+D7NPyqwEKqrZsaotYGklNkfqxa6pa8mrc
ejxquW1PK4FvBk26+osu5a90Jih0PcQM7DUMMr2WHdTiMSXWAiK2ToYF8Itt25Qv
Cd0CsSYw9CJkXNr1u1+mObheaY9QYOmztnSJLy4ZO2JsMhqNwuAueIcwmhXOREq7
kzlnGMgJcuSeAS/OBNj8Zgx0c7QQ0kzc+YmnOCsqoMtPsu/CsXJ4iJiM3Tki/2jT
bywrTiQwE6R3a/87GREOREX+WLicZBWX3k9/4tBL5XSe1p5wPpuIRQUDvAGNfNHP
JN7kujDF4SehilF1qtvCygAwvxHFDj+EwhXKNDKJzoZZIM15rAk3k92n2j6nz1qH
a3xOU05yydOlO6F6w51I1QoDddmkzCRNB0TeO3D6rekHsCK1aDWmC+qRcm2ZFtVz
sY6fdZN2NEmMQokIh9Opi1f8CSYSizPESMzdu2SF0xVO9n/IGIkn1ksK04O2BZo0
X3LBPHLfCRsQNY1eF17bj07fYU2oPZKs/XzJiwxkqK6LFvpeAVaYrtg9fqRO/UVe
QhUIj3BL550ocEpa15xLehLrmwzYiW5zwGjSHQ4EgZluGLCwyKGTh4QswEJRA9Rt
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
MIIE0DCCA7igAwIBAgIJAM5MuKJezXq0MA0GCSqGSIb3DQEBBQUAMIGgMQswCQYD
VQQGEwJVUzERMA8GA1UECBMISWxsaW5vaXMxEDAOBgNVBAcTB0NoaWNhZ28xGDAW
BgNVBAoTD1phcGhveWQgU3R1ZGlvczEUMBIGA1UECxMLV2ViU29ja2V0KysxFjAU
BgNVBAMTDVBldGVyIFRob3Jzb24xJDAiBgkqhkiG9w0BCQEWFXdlYm1hc3RlckB6
YXBob3lkLmNvbTAeFw0xMTExMTUyMTIwMDZaFw0xMjExMTQyMTIwMDZaMIGgMQsw
CQYDVQQGEwJVUzERMA8GA1UECBMISWxsaW5vaXMxEDAOBgNVBAcTB0NoaWNhZ28x
GDAWBgNVBAoTD1phcGhveWQgU3R1ZGlvczEUMBIGA1UECxMLV2ViU29ja2V0Kysx
FjAUBgNVBAMTDVBldGVyIFRob3Jzb24xJDAiBgkqhkiG9w0BCQEWFXdlYm1hc3Rl
ckB6YXBob3lkLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANR0
tdwAnIB8I9qRZ7QbzEWY95RpM7GIn0u/9oH90PzdHiE0rXSkKT+yw3XUzH0iw5t0
5dEwSC+srSP5Vm4cA6kXc94agVVaPW89tGcdP4fHptCruSrzQsDXELCPl5UUvMpA
YUcGisdXYPN/EeOoqb9wKWxoW5mREsyyeWWS89fYN5qU/d0QpbSvEWghqLbL/ZS2
hOlXT9LufOeA+vHiV1/T/h5xC7ecIH02YDQw1EnqxbPmkLPcWThztLS9FiufNDRM
Rhcoaj2b9VDHvDwdbeA0T5v5qNdG34LaapYOelxzQMOtM0f9Dgqehodyxl2qm9mR
lq432dlOEzDnVCPNHwECAwEAAaOCAQkwggEFMB0GA1UdDgQWBBTTPKfNMnKOykhv
+vKS7vql5JsMyzCB1QYDVR0jBIHNMIHKgBTTPKfNMnKOykhv+vKS7vql5JsMy6GB
pqSBozCBoDELMAkGA1UEBhMCVVMxETAPBgNVBAgTCElsbGlub2lzMRAwDgYDVQQH
EwdDaGljYWdvMRgwFgYDVQQKEw9aYXBob3lkIFN0dWRpb3MxFDASBgNVBAsTC1dl
YlNvY2tldCsrMRYwFAYDVQQDEw1QZXRlciBUaG9yc29uMSQwIgYJKoZIhvcNAQkB
FhV3ZWJtYXN0ZXJAemFwaG95ZC5jb22CCQDOTLiiXs16tDAMBgNVHRMEBTADAQH/
MA0GCSqGSIb3DQEBBQUAA4IBAQB+SH0s/hrv5VYqgX6SNLzxdSLvCVsUkCdTpxwY
wOJ84XmYcXDMhKDtZqLtOtN6pfEwVusFlC9mkieuunztCnWNmsSG83RuljJPjFSi
1d4Id4bKEQkQ4cfnjoHKivRrViWLnxuNnLzC6tpyGH/35kKWhhr6T58AXerFgVw3
mHvLPTr1DuhdAZA0ZuvuseVAFFAjI3RetSySwHJE3ak8KswDVfLi6E3XxMVsIWTS
/iFsC2WwoZQlljya2V/kRYIhu+uCdqJ01wunn2BvmURPSgr4GTBF0FQ9JGpNbXxM
TAU7oQJgyFc5sCcuEgPTO0dWVQTvdZVgay4tkmduKDRkmJBF
-----END CERTIFICATE-----
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2012, 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:
@@ -25,30 +25,13 @@
*
*/
#ifndef WEBSOCKETPP_COMMON_TIME_HPP
#define WEBSOCKETPP_COMMON_TIME_HPP
#ifndef WEBSOCKETPP_ECHO_SERVER_HANDLER_HPP
#define WEBSOCKETPP_ECHO_SERVER_HANDLER_HPP
#include <time.h>
class echo_handler : public server::handler {
void on_message(connection_ptr con, std::string msg) {
con->write(msg);
}
};
namespace websocketpp {
namespace lib {
// Code in this header was inspired by the following article and includes some
// code from the related project g2log. The g2log code is public domain licensed
// http://kjellkod.wordpress.com/2013/01/22/exploring-c11-part-2-localtime-and-time-again/
/// Thread safe cross platform localtime
inline std::tm localtime(std::time_t const & time) {
std::tm tm_snapshot;
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
localtime_s(&tm_snapshot, &time);
#else
localtime_r(&time, &tm_snapshot); // POSIX
#endif
return tm_snapshot;
}
} // lib
} // websocketpp
#endif // WEBSOCKETPP_COMMON_TIME_HPP
#endif // WEBSOCKETPP_ECHO_SERVER_HANDLER_HPP
+9 -9
View File
@@ -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 = websocketpp::lib::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::tlsv1);
context_ptr ctx(new boost::asio::ssl::context(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();
}
+4 -4
View File
@@ -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);
+1 -1
View File
@@ -5,7 +5,7 @@
typedef websocketpp::server<websocketpp::config::asio> server;
void on_message(websocketpp::connection_hdl, server::message_ptr msg) {
void on_message(websocketpp::connection_hdl hdl, server::message_ptr msg) {
std::cout << msg->get_payload() << std::endl;
}
+6 -6
View File
@@ -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) {
@@ -37,13 +37,13 @@ public:
// 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 @@ public:
}
// The open handler will signal that we are ready to start sending telemetry
void on_open(websocketpp::connection_hdl) {
void on_open(websocketpp::connection_hdl hdl) {
m_client.get_alog().write(websocketpp::log::alevel::app,
"Connection opened, starting telemetry!");
@@ -74,7 +74,7 @@ public:
}
// The close handler will signal that we should stop sending telemetry
void on_close(websocketpp::connection_hdl) {
void on_close(websocketpp::connection_hdl hdl) {
m_client.get_alog().write(websocketpp::log::alevel::app,
"Connection closed, stopping telemetry!");
@@ -83,7 +83,7 @@ public:
}
// The fail handler will signal that we should stop sending telemetry
void on_fail(websocketpp::connection_hdl) {
void on_fail(websocketpp::connection_hdl hdl) {
m_client.get_alog().write(websocketpp::log::alevel::app,
"Connection failed, stopping telemetry!");
@@ -128,7 +128,7 @@ public:
// 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;
}
+7 -7
View File
@@ -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;
+5 -6
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -45,7 +45,7 @@ struct testee_config : public websocketpp::config::asio {
typedef core::rng_type rng_type;
typedef core::endpoint_base endpoint_base;
static bool const enable_multithreading = true;
static bool const enable_multithreading = false;
struct transport_config : public core::transport_config {
typedef core::concurrency_type concurrency_type;
@@ -54,7 +54,7 @@ struct testee_config : public websocketpp::config::asio {
typedef core::request_type request_type;
typedef core::response_type response_type;
static bool const enable_multithreading = true;
static bool const enable_multithreading = false;
};
typedef websocketpp::transport::asio::endpoint<transport_config>
@@ -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, boost::asio::ip::tcp::socket & s) {
void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket & s) {
boost::asio::ip::tcp::no_delay option(true);
s.set_option(option);
}
@@ -104,7 +104,6 @@ int main(int argc, char * argv[]) {
// Initialize ASIO
testee_server.init_asio();
testee_server.set_reuse_addr(true);
// Register our message handler
testee_server.set_message_handler(bind(&on_message,&testee_server,::_1,::_2));
@@ -124,7 +123,7 @@ int main(int argc, char * argv[]) {
typedef websocketpp::lib::shared_ptr<websocketpp::lib::thread> thread_ptr;
std::vector<thread_ptr> ts;
for (size_t i = 0; i < num_threads; i++) {
ts.push_back(websocketpp::lib::make_shared<websocketpp::lib::thread>(&server::run, &testee_server));
ts.push_back(thread_ptr(new websocketpp::lib::thread(&server::run, &testee_server)));
}
for (size_t i = 0; i < num_threads; i++) {
+2 -2
View File
@@ -119,7 +119,7 @@ public:
m_endpoint.init_asio();
m_endpoint.start_perpetual();
m_thread = websocketpp::lib::make_shared<websocketpp::lib::thread>(&client::run, &m_endpoint);
m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint));
}
~websocket_endpoint() {
@@ -155,7 +155,7 @@ public:
}
int new_id = m_next_id++;
connection_metadata::ptr metadata_ptr = websocketpp::lib::make_shared<connection_metadata>(new_id, con->get_handle(), uri);
connection_metadata::ptr metadata_ptr(new connection_metadata(new_id, con->get_handle(), uri));
m_connection_list[new_id] = metadata_ptr;
con->set_open_handler(websocketpp::lib::bind(
+1 -1
View File
@@ -1,4 +1,4 @@
WebSocket++ (0.4.0)
WebSocket++ (0.3.0-alpha4)
==========================
WebSocket++ is a header only C++ library that implements RFC6455 The WebSocket
+10 -9
View File
@@ -16,23 +16,24 @@ Complete & Tested:
- open_handler
- close_handler
- echo_server & echo_server_tls
- External io_service support
Implemented, needs more testing
- TLS support
- exception/error handling
- Timeouts
- Subprotocol negotiation
- validate_handler
- Hybi 00/Hixie 76 legacy protocol support
- Outgoing Proxy Support
- External io_service support
- socket_init_handler
- tls_init_handler
- tcp_init_handler
Ongoing work
- exception/error handling
- Subprotocol negotiation
- Hybi 00/Hixie 76 legacy protocol support
- Performance tuning
- Outgoing Proxy Support
- PowerPC support
- Visual Studio / Windows support
- Timeouts
- CMake build/install support
- validate_handler
- http_handler
Future feature roadmap
+33 -33
View File
@@ -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<stub_config> c;
stub_config::rng_type rng;
websocketpp::connection<stub_config> 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<char*>(frames),8);
unsigned char frames[8] = {0x82,0x82,0xFF,0xFF,0xFF,0xFF,0xD5,0xD5};
input.append(reinterpret_cast<char*>(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);
}
+9 -9
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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();
}
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+65 -65
View File
@@ -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 );
+79 -79
View File
@@ -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 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 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 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";
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;
{
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;
}
try {
r.consume(raw.c_str(),raw.size());
} catch (...) {
std::cout << "exception" << std::endl;
}
if (!r.ready()) {
std::cout << "error" << std::endl;
break;
}
}
}
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;
{
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;
}
try {
r.consume2(firefox.c_str(),firefox.size());
} catch (...) {
std::cout << "exception" << std::endl;
}
if (!r.ready()) {
std::cout << "error" << std::endl;
break;
}
}
}
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;
{
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;
}
try {
r.consume(firefox.c_str(),firefox.size());
} catch (...) {
std::cout << "exception" << std::endl;
}
if (!r.ready()) {
std::cout << "error" << std::endl;
break;
}
}
}
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;
{
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;
}
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;
}
}
}
if (!r.ready()) {
std::cout << "error" << std::endl;
break;
}
}
}
return 0;
return 0;
}
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+43 -43
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2012, 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 <template <class> class con_msg_manager>
struct stub {
typedef websocketpp::lib::shared_ptr<stub> ptr;
typedef websocketpp::lib::shared_ptr<stub> ptr;
typedef con_msg_manager<stub> con_msg_man_type;
typedef typename con_msg_man_type::ptr con_msg_man_ptr;
typedef typename con_msg_man_type::weak_ptr con_msg_man_weak_ptr;
typedef con_msg_manager<stub> con_msg_man_type;
typedef typename con_msg_man_type::ptr con_msg_man_ptr;
typedef typename con_msg_man_type::weak_ptr con_msg_man_weak_ptr;
stub(con_msg_man_ptr manager, websocketpp::frame::opcode::value op, size_t size = 128)
: m_opcode(op)
, m_manager(manager)
, m_size(size) {}
stub(con_msg_man_ptr manager, websocketpp::frame::opcode::value op, size_t size = 128)
: m_opcode(op)
, m_manager(manager)
, m_size(size) {}
bool recycle() {
con_msg_man_ptr shared = m_manager.lock();
bool recycle() {
con_msg_man_ptr shared = m_manager.lock();
if (shared) {
return shared->recycle(this);
} else {
return false;
}
}
if (shared) {
return shared->recycle(this);
} else {
return false;
}
}
websocketpp::frame::opcode::value m_opcode;
con_msg_man_weak_ptr m_manager;
size_t m_size;
websocketpp::frame::opcode::value m_opcode;
con_msg_man_weak_ptr m_manager;
size_t m_size;
};
BOOST_AUTO_TEST_CASE( basic_get_message ) {
typedef stub<websocketpp::message_buffer::alloc::con_msg_manager>
message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_man_type;
typedef stub<websocketpp::message_buffer::alloc::con_msg_manager>
message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_man_type;
con_msg_man_type::ptr manager(new con_msg_man_type());
message_type::ptr msg = manager->get_message(websocketpp::frame::opcode::TEXT,512);
con_msg_man_type::ptr manager(new con_msg_man_type());
message_type::ptr msg = manager->get_message(websocketpp::frame::opcode::TEXT,512);
BOOST_CHECK(msg);
BOOST_CHECK(msg->m_opcode == websocketpp::frame::opcode::TEXT);
BOOST_CHECK(msg->m_manager.lock() == manager);
BOOST_CHECK(msg->m_size == 512);
BOOST_CHECK(msg);
BOOST_CHECK(msg->m_opcode == websocketpp::frame::opcode::TEXT);
BOOST_CHECK(msg->m_manager.lock() == manager);
BOOST_CHECK(msg->m_size == 512);
}
BOOST_AUTO_TEST_CASE( basic_get_manager ) {
typedef stub<websocketpp::message_buffer::alloc::con_msg_manager>
message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_man_type;
typedef websocketpp::message_buffer::alloc::endpoint_msg_manager
<con_msg_man_type> endpoint_manager_type;
typedef stub<websocketpp::message_buffer::alloc::con_msg_manager>
message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_man_type;
typedef websocketpp::message_buffer::alloc::endpoint_msg_manager
<con_msg_man_type> endpoint_manager_type;
endpoint_manager_type em;
con_msg_man_type::ptr manager = em.get_manager();
message_type::ptr msg = manager->get_message(websocketpp::frame::opcode::TEXT,512);
endpoint_manager_type em;
con_msg_man_type::ptr manager = em.get_manager();
message_type::ptr msg = manager->get_message(websocketpp::frame::opcode::TEXT,512);
BOOST_CHECK(msg);
BOOST_CHECK(msg->m_opcode == websocketpp::frame::opcode::TEXT);
BOOST_CHECK(msg->m_manager.lock() == manager);
BOOST_CHECK(msg->m_size == 512);
BOOST_CHECK(msg);
BOOST_CHECK(msg->m_opcode == websocketpp::frame::opcode::TEXT);
BOOST_CHECK(msg->m_manager.lock() == manager);
BOOST_CHECK(msg->m_size == 512);
}
+21 -21
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2012, 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,38 +35,38 @@
template <typename message>
struct stub {
typedef websocketpp::lib::weak_ptr<stub> weak_ptr;
typedef websocketpp::lib::shared_ptr<stub> ptr;
typedef websocketpp::lib::weak_ptr<stub> weak_ptr;
typedef websocketpp::lib::shared_ptr<stub> ptr;
stub() : recycled(false) {}
stub() : recycled(false) {}
bool recycle(message *) {
this->recycled = true;
return false;
}
bool recycle(message * msg) {
this->recycled = true;
return false;
}
bool recycled;
bool recycled;
};
BOOST_AUTO_TEST_CASE( basic_size_check ) {
typedef websocketpp::message_buffer::message<stub> message_type;
typedef stub<message_type> stub_type;
typedef websocketpp::message_buffer::message<stub> message_type;
typedef stub<message_type> stub_type;
stub_type::ptr s(new stub_type());
message_type::ptr msg(new message_type(s,websocketpp::frame::opcode::TEXT,500));
stub_type::ptr s(new stub_type());
message_type::ptr msg(new message_type(s,websocketpp::frame::opcode::TEXT,500));
BOOST_CHECK(msg->get_payload().capacity() >= 500);
BOOST_CHECK(msg->get_payload().capacity() >= 500);
}
BOOST_AUTO_TEST_CASE( recycle ) {
typedef websocketpp::message_buffer::message<stub> message_type;
typedef stub<message_type> stub_type;
typedef websocketpp::message_buffer::message<stub> message_type;
typedef stub<message_type> stub_type;
stub_type::ptr s(new stub_type());
message_type::ptr msg(new message_type(s,websocketpp::frame::opcode::TEXT,500));
stub_type::ptr s(new stub_type());
message_type::ptr msg(new message_type(s,websocketpp::frame::opcode::TEXT,500));
BOOST_CHECK(s->recycled == false);
BOOST_CHECK(msg->recycle() == false);
BOOST_CHECK(s->recycled == true);
BOOST_CHECK(s->recycled == false);
BOOST_CHECK(msg->recycle() == false);
BOOST_CHECK(s->recycled == true);
}
+4 -4
View File
@@ -54,9 +54,9 @@ BOOST_AUTO_TEST_CASE( exact_match ) {
bool exception;
try {
u = p.get_uri(r);
u = p.get_uri(r);
} catch (const websocketpp::uri_exception& e) {
exception = true;
exception = true;
}
BOOST_CHECK(exception == false);
@@ -147,9 +147,9 @@ BOOST_AUTO_TEST_CASE( bad_host ) {
BOOST_CHECK(!p.validate_handshake(r));
try {
u = p.get_uri(r);
u = p.get_uri(r);
} catch (const websocketpp::uri_exception& e) {
exception = true;
exception = true;
}
BOOST_CHECK(exception == true);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+19 -19
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -38,15 +38,15 @@
#include <websocketpp/message_buffer/alloc.hpp>
struct stub_config {
typedef websocketpp::http::parser::request request_type;
typedef websocketpp::http::parser::response response_type;
typedef websocketpp::http::parser::request request_type;
typedef websocketpp::http::parser::response response_type;
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
static const size_t max_message_size = 16000000;
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
static const size_t max_message_size = 16000000;
};
struct processor_setup {
@@ -55,16 +55,16 @@ struct processor_setup {
, p(false,server,msg_manager) {}
websocketpp::lib::error_code ec;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::request_type req;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::request_type req;
stub_config::response_type res;
websocketpp::processor::hybi00<stub_config> p;
websocketpp::processor::hybi00<stub_config> p;
};
typedef stub_config::message_type::ptr message_ptr;
BOOST_AUTO_TEST_CASE( exact_match ) {
processor_setup env(true);
processor_setup env(true);
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nOrigin: http://example.com\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
@@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE( exact_match ) {
}
BOOST_AUTO_TEST_CASE( non_get_method ) {
processor_setup env(true);
processor_setup env(true);
std::string handshake = "POST / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
@@ -109,7 +109,7 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
}
BOOST_AUTO_TEST_CASE( old_http_version ) {
processor_setup env(true);
processor_setup env(true);
std::string handshake = "GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
@@ -122,7 +122,7 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
}
BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
processor_setup env(true);
processor_setup env(true);
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\n\r\n";
@@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
}
BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
processor_setup env(true);
processor_setup env(true);
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
@@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
}
BOOST_AUTO_TEST_CASE( bad_host ) {
processor_setup env(true);
processor_setup env(true);
websocketpp::uri_ptr u;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: upgrade\r\nUpgrade: websocket\r\nOrigin: http://example.com\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
@@ -164,7 +164,7 @@ BOOST_AUTO_TEST_CASE( bad_host ) {
}
BOOST_AUTO_TEST_CASE( extract_subprotocols ) {
processor_setup env(true);
processor_setup env(true);
std::vector<std::string> subps;
+25 -25
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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,13 +40,13 @@
#include <websocketpp/random/none.hpp>
struct stub_config {
typedef websocketpp::http::parser::request request_type;
typedef websocketpp::http::parser::response response_type;
typedef websocketpp::http::parser::request request_type;
typedef websocketpp::http::parser::response response_type;
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
@@ -67,10 +67,10 @@ struct stub_config {
};
BOOST_AUTO_TEST_CASE( exact_match ) {
stub_config::request_type r;
stub_config::request_type r;
stub_config::response_type response;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
@@ -101,10 +101,10 @@ BOOST_AUTO_TEST_CASE( exact_match ) {
}
BOOST_AUTO_TEST_CASE( non_get_method ) {
stub_config::request_type r;
stub_config::request_type r;
stub_config::response_type response;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
@@ -119,10 +119,10 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
}
BOOST_AUTO_TEST_CASE( old_http_version ) {
stub_config::request_type r;
stub_config::request_type r;
stub_config::response_type response;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
@@ -137,10 +137,10 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
}
BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
stub_config::request_type r;
stub_config::request_type r;
stub_config::response_type response;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
@@ -155,10 +155,10 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
}
BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
stub_config::request_type r;
stub_config::request_type r;
stub_config::response_type response;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
@@ -173,10 +173,10 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
}
BOOST_AUTO_TEST_CASE( bad_host ) {
stub_config::request_type r;
stub_config::request_type r;
stub_config::response_type response;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
+24 -24
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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,13 +40,13 @@
#include <websocketpp/random/none.hpp>
struct stub_config {
typedef websocketpp::http::parser::request request_type;
typedef websocketpp::http::parser::response response_type;
typedef websocketpp::http::parser::request request_type;
typedef websocketpp::http::parser::response response_type;
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
@@ -67,10 +67,10 @@ struct stub_config {
};
BOOST_AUTO_TEST_CASE( exact_match ) {
stub_config::request_type r;
stub_config::request_type r;
stub_config::response_type response;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
@@ -101,10 +101,10 @@ BOOST_AUTO_TEST_CASE( exact_match ) {
}
BOOST_AUTO_TEST_CASE( non_get_method ) {
stub_config::request_type r;
stub_config::request_type r;
stub_config::response_type response;
stub_config::rng_type rng;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::con_msg_manager_type::ptr msg_manager;
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
@@ -119,10 +119,10 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
}
BOOST_AUTO_TEST_CASE( old_http_version ) {
stub_config::request_type r;
stub_config::request_type r;
stub_config::response_type response;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
@@ -137,10 +137,10 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
}
BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
stub_config::request_type r;
stub_config::request_type r;
stub_config::response_type response;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
@@ -155,10 +155,10 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
}
BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
stub_config::request_type r;
stub_config::request_type r;
stub_config::response_type response;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
@@ -173,10 +173,10 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
}
BOOST_AUTO_TEST_CASE( bad_host ) {
stub_config::request_type r;
stub_config::request_type r;
stub_config::response_type response;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
websocketpp::uri_ptr u;
websocketpp::lib::error_code ec;
+180 -180
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -43,13 +43,13 @@
#include <websocketpp/extensions/permessage_deflate/enabled.hpp>
struct stub_config {
typedef websocketpp::http::parser::request request_type;
typedef websocketpp::http::parser::response response_type;
typedef websocketpp::http::parser::request request_type;
typedef websocketpp::http::parser::response response_type;
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
@@ -65,13 +65,13 @@ struct stub_config {
};
struct stub_config_ext {
typedef websocketpp::http::parser::request request_type;
typedef websocketpp::http::parser::response response_type;
typedef websocketpp::http::parser::request request_type;
typedef websocketpp::http::parser::response response_type;
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
@@ -97,11 +97,11 @@ struct processor_setup {
, p(false,server,msg_manager,rng) {}
websocketpp::lib::error_code ec;
con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::request_type req;
con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::request_type req;
stub_config::response_type res;
websocketpp::processor::hybi13<stub_config> p;
websocketpp::processor::hybi13<stub_config> p;
};
struct processor_setup_ext {
@@ -110,15 +110,15 @@ struct processor_setup_ext {
, p(false,server,msg_manager,rng) {}
websocketpp::lib::error_code ec;
con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::request_type req;
con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
stub_config::request_type req;
stub_config::response_type res;
websocketpp::processor::hybi13<stub_config_ext> p;
websocketpp::processor::hybi13<stub_config_ext> p;
};
BOOST_AUTO_TEST_CASE( exact_match ) {
processor_setup env(true);
processor_setup env(true);
std::string handshake = "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\n\r\n";
@@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE( exact_match ) {
}
BOOST_AUTO_TEST_CASE( non_get_method ) {
processor_setup env(true);
processor_setup env(true);
std::string handshake = "POST / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: foo\r\n\r\n";
@@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
}
BOOST_AUTO_TEST_CASE( old_http_version ) {
processor_setup env(true);
processor_setup env(true);
std::string handshake = "GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: foo\r\n\r\n";
@@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
}
BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
processor_setup env(true);
processor_setup env(true);
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\n\r\n";
@@ -193,7 +193,7 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
}
BOOST_AUTO_TEST_CASE( bad_host ) {
processor_setup env(true);
processor_setup env(true);
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: foo\r\n\r\n";
@@ -220,243 +220,243 @@ BOOST_AUTO_TEST_CASE( bad_host ) {
// 0x81 0x80
BOOST_AUTO_TEST_CASE( frame_empty_binary_unmasked ) {
uint8_t frame[2] = {0x82, 0x00};
uint8_t frame[2] = {0x82, 0x00};
// all in one chunk
processor_setup env1(false);
// all in one chunk
processor_setup env1(false);
size_t ret1 = env1.p.consume(frame,2,env1.ec);
size_t ret1 = env1.p.consume(frame,2,env1.ec);
BOOST_CHECK_EQUAL( ret1, 2 );
BOOST_CHECK( !env1.ec );
BOOST_CHECK_EQUAL( env1.p.ready(), true );
BOOST_CHECK_EQUAL( ret1, 2 );
BOOST_CHECK( !env1.ec );
BOOST_CHECK_EQUAL( env1.p.ready(), true );
// two separate chunks
processor_setup env2(false);
// two separate chunks
processor_setup env2(false);
BOOST_CHECK_EQUAL( env2.p.consume(frame,1,env2.ec), 1 );
BOOST_CHECK( !env2.ec );
BOOST_CHECK_EQUAL( env2.p.ready(), false );
BOOST_CHECK_EQUAL( env2.p.consume(frame,1,env2.ec), 1 );
BOOST_CHECK( !env2.ec );
BOOST_CHECK_EQUAL( env2.p.ready(), false );
BOOST_CHECK_EQUAL( env2.p.consume(frame+1,1,env2.ec), 1 );
BOOST_CHECK( !env2.ec );
BOOST_CHECK_EQUAL( env2.p.ready(), true );
BOOST_CHECK_EQUAL( env2.p.consume(frame+1,1,env2.ec), 1 );
BOOST_CHECK( !env2.ec );
BOOST_CHECK_EQUAL( env2.p.ready(), true );
}
BOOST_AUTO_TEST_CASE( frame_small_binary_unmasked ) {
processor_setup env(false);
processor_setup env(false);
uint8_t frame[4] = {0x82, 0x02, 0x2A, 0x2A};
uint8_t frame[4] = {0x82, 0x02, 0x2A, 0x2A};
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env.p.consume(frame,4,env.ec), 4 );
BOOST_CHECK( !env.ec );
BOOST_CHECK_EQUAL( env.p.ready(), true );
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env.p.consume(frame,4,env.ec), 4 );
BOOST_CHECK( !env.ec );
BOOST_CHECK_EQUAL( env.p.ready(), true );
message_ptr foo = env.p.get_message();
message_ptr foo = env.p.get_message();
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( foo->get_payload(), "**" );
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( foo->get_payload(), "**" );
}
BOOST_AUTO_TEST_CASE( frame_extended_binary_unmasked ) {
processor_setup env(false);
processor_setup env(false);
uint8_t frame[130] = {0x82, 0x7E, 0x00, 0x7E};
frame[0] = 0x82;
frame[1] = 0x7E;
frame[2] = 0x00;
frame[3] = 0x7E;
std::fill_n(frame+4,126,0x2A);
uint8_t frame[130] = {0x82, 0x7E, 0x00, 0x7E};
frame[0] = 0x82;
frame[1] = 0x7E;
frame[2] = 0x00;
frame[3] = 0x7E;
std::fill_n(frame+4,126,0x2A);
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env.p.consume(frame,130,env.ec), 130 );
BOOST_CHECK( !env.ec );
BOOST_CHECK_EQUAL( env.p.ready(), true );
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env.p.consume(frame,130,env.ec), 130 );
BOOST_CHECK( !env.ec );
BOOST_CHECK_EQUAL( env.p.ready(), true );
message_ptr foo = env.p.get_message();
message_ptr foo = env.p.get_message();
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( foo->get_payload().size(), 126 );
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( foo->get_payload().size(), 126 );
}
BOOST_AUTO_TEST_CASE( frame_jumbo_binary_unmasked ) {
processor_setup env(false);
processor_setup env(false);
uint8_t frame[130] = {0x82, 0x7E, 0x00, 0x7E};
std::fill_n(frame+4,126,0x2A);
uint8_t frame[130] = {0x82, 0x7E, 0x00, 0x7E};
std::fill_n(frame+4,126,0x2A);
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env.p.consume(frame,130,env.ec), 130 );
BOOST_CHECK( !env.ec );
BOOST_CHECK_EQUAL( env.p.ready(), true );
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env.p.consume(frame,130,env.ec), 130 );
BOOST_CHECK( !env.ec );
BOOST_CHECK_EQUAL( env.p.ready(), true );
message_ptr foo = env.p.get_message();
message_ptr foo = env.p.get_message();
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( foo->get_payload().size(), 126 );
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( foo->get_payload().size(), 126 );
}
BOOST_AUTO_TEST_CASE( control_frame_too_large ) {
processor_setup env(false);
processor_setup env(false);
uint8_t frame[130] = {0x88, 0x7E, 0x00, 0x7E};
std::fill_n(frame+4,126,0x2A);
uint8_t frame[130] = {0x88, 0x7E, 0x00, 0x7E};
std::fill_n(frame+4,126,0x2A);
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame,130,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::control_too_big );
BOOST_CHECK_EQUAL( env.p.ready(), false );
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame,130,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::control_too_big );
BOOST_CHECK_EQUAL( env.p.ready(), false );
}
BOOST_AUTO_TEST_CASE( rsv_bits_used ) {
uint8_t frame[3][2] = {{0x90, 0x00},
{0xA0, 0x00},
{0xC0, 0x00}};
uint8_t frame[3][2] = {{0x90, 0x00},
{0xA0, 0x00},
{0xC0, 0x00}};
for (int i = 0; i < 3; i++) {
processor_setup env(false);
for (int i = 0; i < 3; i++) {
processor_setup env(false);
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame[i],2,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_rsv_bit );
BOOST_CHECK_EQUAL( env.p.ready(), false );
}
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame[i],2,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_rsv_bit );
BOOST_CHECK_EQUAL( env.p.ready(), false );
}
}
BOOST_AUTO_TEST_CASE( reserved_opcode_used ) {
uint8_t frame[10][2] = {{0x83, 0x00},
{0x84, 0x00},
{0x85, 0x00},
{0x86, 0x00},
{0x87, 0x00},
{0x8B, 0x00},
{0x8C, 0x00},
{0x8D, 0x00},
{0x8E, 0x00},
{0x8F, 0x00}};
uint8_t frame[10][2] = {{0x83, 0x00},
{0x84, 0x00},
{0x85, 0x00},
{0x86, 0x00},
{0x87, 0x00},
{0x8B, 0x00},
{0x8C, 0x00},
{0x8D, 0x00},
{0x8E, 0x00},
{0x8F, 0x00}};
for (int i = 0; i < 10; i++) {
processor_setup env(false);
for (int i = 0; i < 10; i++) {
processor_setup env(false);
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame[i],2,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_opcode );
BOOST_CHECK_EQUAL( env.p.ready(), false );
}
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame[i],2,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_opcode );
BOOST_CHECK_EQUAL( env.p.ready(), false );
}
}
BOOST_AUTO_TEST_CASE( fragmented_control_message ) {
processor_setup env(false);
processor_setup env(false);
uint8_t frame[2] = {0x08, 0x00};
uint8_t frame[2] = {0x08, 0x00};
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame,2,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::fragmented_control );
BOOST_CHECK_EQUAL( env.p.ready(), false );
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame,2,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::fragmented_control );
BOOST_CHECK_EQUAL( env.p.ready(), false );
}
BOOST_AUTO_TEST_CASE( fragmented_binary_message ) {
processor_setup env0(false);
processor_setup env1(false);
processor_setup env0(false);
processor_setup env1(false);
uint8_t frame0[6] = {0x02, 0x01, 0x2A, 0x80, 0x01, 0x2A};
uint8_t frame1[8] = {0x02, 0x01, 0x2A, 0x89, 0x00, 0x80, 0x01, 0x2A};
uint8_t frame0[6] = {0x02, 0x01, 0x2A, 0x80, 0x01, 0x2A};
uint8_t frame1[8] = {0x02, 0x01, 0x2A, 0x89, 0x00, 0x80, 0x01, 0x2A};
// read fragmented message in one chunk
BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env0.p.consume(frame0,6,env0.ec), 6 );
// read fragmented message in one chunk
BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env0.p.consume(frame0,6,env0.ec), 6 );
BOOST_CHECK( !env0.ec );
BOOST_CHECK_EQUAL( env0.p.ready(), true );
BOOST_CHECK_EQUAL( env0.p.get_message()->get_payload(), "**" );
BOOST_CHECK_EQUAL( env0.p.ready(), true );
BOOST_CHECK_EQUAL( env0.p.get_message()->get_payload(), "**" );
// read fragmented message in two chunks
BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env0.p.consume(frame0,3,env0.ec), 3 );
// read fragmented message in two chunks
BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env0.p.consume(frame0,3,env0.ec), 3 );
BOOST_CHECK( !env0.ec );
BOOST_CHECK_EQUAL( env0.p.ready(), false );
BOOST_CHECK_EQUAL( env0.p.consume(frame0+3,3,env0.ec), 3 );
BOOST_CHECK_EQUAL( env0.p.ready(), false );
BOOST_CHECK_EQUAL( env0.p.consume(frame0+3,3,env0.ec), 3 );
BOOST_CHECK( !env0.ec );
BOOST_CHECK_EQUAL( env0.p.ready(), true );
BOOST_CHECK_EQUAL( env0.p.get_message()->get_payload(), "**" );
BOOST_CHECK_EQUAL( env0.p.ready(), true );
BOOST_CHECK_EQUAL( env0.p.get_message()->get_payload(), "**" );
// read fragmented message with control message in between
BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env0.p.consume(frame1,8,env0.ec), 5 );
// read fragmented message with control message in between
BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env0.p.consume(frame1,8,env0.ec), 5 );
BOOST_CHECK( !env0.ec );
BOOST_CHECK_EQUAL( env0.p.ready(), true );
BOOST_CHECK_EQUAL( env0.p.get_message()->get_opcode(), websocketpp::frame::opcode::PING);
BOOST_CHECK_EQUAL( env0.p.consume(frame1+5,3,env0.ec), 3 );
BOOST_CHECK_EQUAL( env0.p.ready(), true );
BOOST_CHECK_EQUAL( env0.p.get_message()->get_opcode(), websocketpp::frame::opcode::PING);
BOOST_CHECK_EQUAL( env0.p.consume(frame1+5,3,env0.ec), 3 );
BOOST_CHECK( !env0.ec );
BOOST_CHECK_EQUAL( env0.p.ready(), true );
BOOST_CHECK_EQUAL( env0.p.get_message()->get_payload(), "**" );
BOOST_CHECK_EQUAL( env0.p.ready(), true );
BOOST_CHECK_EQUAL( env0.p.get_message()->get_payload(), "**" );
// read lone continuation frame
BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env0.p.consume(frame0+3,3,env0.ec), 0);
BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env0.p.consume(frame0+3,3,env0.ec), 0);
BOOST_CHECK_EQUAL( env0.ec, websocketpp::processor::error::invalid_continuation );
// read two start frames in a row
BOOST_CHECK_EQUAL( env1.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env1.p.consume(frame0,3,env1.ec), 3);
BOOST_CHECK_EQUAL( env1.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env1.p.consume(frame0,3,env1.ec), 3);
BOOST_CHECK( !env1.ec );
BOOST_CHECK_GT( env1.p.consume(frame0,3,env1.ec), 0);
BOOST_CHECK_GT( env1.p.consume(frame0,3,env1.ec), 0);
BOOST_CHECK_EQUAL( env1.ec, websocketpp::processor::error::invalid_continuation );
}
BOOST_AUTO_TEST_CASE( unmasked_client_frame ) {
processor_setup env(true);
processor_setup env(true);
uint8_t frame[2] = {0x82, 0x00};
uint8_t frame[2] = {0x82, 0x00};
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame,2,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::masking_required );
BOOST_CHECK_EQUAL( env.p.ready(), false );
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame,2,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::masking_required );
BOOST_CHECK_EQUAL( env.p.ready(), false );
}
BOOST_AUTO_TEST_CASE( masked_server_frame ) {
processor_setup env(false);
processor_setup env(false);
uint8_t frame[8] = {0x82, 0x82, 0xFF, 0xFF, 0xFF, 0xFF, 0xD5, 0xD5};
uint8_t frame[8] = {0x82, 0x82, 0xFF, 0xFF, 0xFF, 0xFF, 0xD5, 0xD5};
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame,8,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::masking_forbidden );
BOOST_CHECK_EQUAL( env.p.ready(), false );
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame,8,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::masking_forbidden );
BOOST_CHECK_EQUAL( env.p.ready(), false );
}
BOOST_AUTO_TEST_CASE( frame_small_binary_masked ) {
processor_setup env(true);
processor_setup env(true);
uint8_t frame[8] = {0x82, 0x82, 0xFF, 0xFF, 0xFF, 0xFF, 0xD5, 0xD5};
uint8_t frame[8] = {0x82, 0x82, 0xFF, 0xFF, 0xFF, 0xFF, 0xD5, 0xD5};
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env.p.consume(frame,8,env.ec), 8 );
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env.p.consume(frame,8,env.ec), 8 );
BOOST_CHECK( !env.ec );
BOOST_CHECK_EQUAL( env.p.ready(), true );
BOOST_CHECK_EQUAL( env.p.get_message()->get_payload(), "**" );
BOOST_CHECK_EQUAL( env.p.ready(), true );
BOOST_CHECK_EQUAL( env.p.get_message()->get_payload(), "**" );
}
BOOST_AUTO_TEST_CASE( masked_fragmented_binary_message ) {
processor_setup env(true);
uint8_t frame0[14] = {0x02, 0x81, 0xAB, 0x23, 0x98, 0x45, 0x81,
0x80, 0x81, 0xB8, 0x34, 0x12, 0xFF, 0x92};
uint8_t frame0[14] = {0x02, 0x81, 0xAB, 0x23, 0x98, 0x45, 0x81,
0x80, 0x81, 0xB8, 0x34, 0x12, 0xFF, 0x92};
// read fragmented message in one chunk
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env.p.consume(frame0,14,env.ec), 14 );
// read fragmented message in one chunk
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env.p.consume(frame0,14,env.ec), 14 );
BOOST_CHECK( !env.ec );
BOOST_CHECK_EQUAL( env.p.ready(), true );
BOOST_CHECK_EQUAL( env.p.get_message()->get_payload(), "**" );
BOOST_CHECK_EQUAL( env.p.ready(), true );
BOOST_CHECK_EQUAL( env.p.get_message()->get_payload(), "**" );
}
BOOST_AUTO_TEST_CASE( prepare_data_frame ) {
processor_setup env(true);
processor_setup env(true);
message_ptr in = env.msg_manager->get_message();
message_ptr out = env.msg_manager->get_message();
@@ -496,10 +496,10 @@ BOOST_AUTO_TEST_CASE( single_frame_message_too_large ) {
env.p.set_max_message_size(3);
uint8_t frame0[10] = {0x82, 0x84, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01};
uint8_t frame0[10] = {0x82, 0x84, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01};
// read message that is one byte too large
BOOST_CHECK_EQUAL( env.p.consume(frame0,10,env.ec), 6 );
// read message that is one byte too large
BOOST_CHECK_EQUAL( env.p.consume(frame0,10,env.ec), 6 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::message_too_big );
}
@@ -508,11 +508,11 @@ BOOST_AUTO_TEST_CASE( multiple_frame_message_too_large ) {
env.p.set_max_message_size(4);
uint8_t frame0[8] = {0x02, 0x82, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01};
uint8_t frame1[9] = {0x80, 0x83, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01};
uint8_t frame0[8] = {0x02, 0x82, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01};
uint8_t frame1[9] = {0x80, 0x83, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01};
// read first message frame with size under the limit
BOOST_CHECK_EQUAL( env.p.consume(frame0,8,env.ec), 8 );
// read first message frame with size under the limit
BOOST_CHECK_EQUAL( env.p.consume(frame0,8,env.ec), 8 );
BOOST_CHECK( !env.ec );
// read second message frame that puts the size over the limit
@@ -638,7 +638,7 @@ BOOST_AUTO_TEST_CASE( extension_negotiation_unknown ) {
}
BOOST_AUTO_TEST_CASE( extract_subprotocols_empty ) {
processor_setup env(true);
processor_setup env(true);
std::vector<std::string> subps;
BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
@@ -646,7 +646,7 @@ BOOST_AUTO_TEST_CASE( extract_subprotocols_empty ) {
}
BOOST_AUTO_TEST_CASE( extract_subprotocols_one ) {
processor_setup env(true);
processor_setup env(true);
std::vector<std::string> subps;
env.req.replace_header("Sec-WebSocket-Protocol","foo");
@@ -657,7 +657,7 @@ BOOST_AUTO_TEST_CASE( extract_subprotocols_one ) {
}
BOOST_AUTO_TEST_CASE( extract_subprotocols_multiple ) {
processor_setup env(true);
processor_setup env(true);
std::vector<std::string> subps;
env.req.replace_header("Sec-WebSocket-Protocol","foo,bar");
@@ -669,7 +669,7 @@ BOOST_AUTO_TEST_CASE( extract_subprotocols_multiple ) {
}
BOOST_AUTO_TEST_CASE( extract_subprotocols_invalid) {
processor_setup env(true);
processor_setup env(true);
std::vector<std::string> subps;
env.req.replace_header("Sec-WebSocket-Protocol","foo,bar,,,,");
+1 -1
View File
@@ -10,7 +10,7 @@ Import('polyfill_libs')
env = env.Clone ()
env_cpp11 = env_cpp11.Clone ()
BOOST_LIBS = boostlibs(['unit_test_framework','random','system'],env) + [platform_libs]
BOOST_LIBS = boostlibs(['unit_test_framework','random'],env) + [platform_libs]
objs = env.Object('random_none_boost.o', ["none.cpp"], LIBS = BOOST_LIBS)
objs += env.Object('random_device_boost.o', ["random_device.cpp"], LIBS = BOOST_LIBS)
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+6 -6
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -130,8 +130,8 @@ BOOST_AUTO_TEST_CASE( connect_con ) {
// TODO: more tests related to reading the HTTP response
std::stringstream channel2;
channel2 << "e\r\n\r\n";
channel2 >> *con;
channel2 << "e\r\n\r\n";
channel2 >> *con;
}
BOOST_AUTO_TEST_CASE( select_subprotocol ) {
@@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE( select_subprotocol ) {
con->select_subprotocol("foo",ec);
BOOST_CHECK_EQUAL( ec , make_error_code(websocketpp::error::server_only) );
BOOST_CHECK_THROW( con->select_subprotocol("foo") , websocketpp::exception );
BOOST_CHECK_THROW( con->select_subprotocol("foo") , websocketpp::lib::error_code );
}
BOOST_AUTO_TEST_CASE( add_subprotocols_invalid ) {
@@ -158,11 +158,11 @@ BOOST_AUTO_TEST_CASE( add_subprotocols_invalid ) {
con->add_subprotocol("",ec);
BOOST_CHECK_EQUAL( ec , make_error_code(websocketpp::error::invalid_subprotocol) );
BOOST_CHECK_THROW( con->add_subprotocol("") , websocketpp::exception );
BOOST_CHECK_THROW( con->add_subprotocol("") , websocketpp::lib::error_code );
con->add_subprotocol("foo,bar",ec);
BOOST_CHECK_EQUAL( ec , make_error_code(websocketpp::error::invalid_subprotocol) );
BOOST_CHECK_THROW( con->add_subprotocol("foo,bar") , websocketpp::exception );
BOOST_CHECK_THROW( con->add_subprotocol("foo,bar") , websocketpp::lib::error_code );
}
BOOST_AUTO_TEST_CASE( add_subprotocols ) {
+38 -38
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -67,19 +67,19 @@ std::string run_server_test(server& s, std::string input) {
server::connection_ptr con;
std::stringstream output;
s.register_ostream(&output);
s.clear_access_channels(websocketpp::log::alevel::all);
s.register_ostream(&output);
s.clear_access_channels(websocketpp::log::alevel::all);
s.clear_error_channels(websocketpp::log::elevel::all);
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();
}
/* handler library*/
@@ -121,8 +121,8 @@ BOOST_AUTO_TEST_CASE( basic_websocket_request ) {
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: test\r\nUpgrade: websocket\r\n\r\n";
server s;
s.set_user_agent("test");
server s;
s.set_user_agent("test");
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
}
@@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE( invalid_websocket_version ) {
server s;
s.set_user_agent("test");
//s.set_message_handler(bind(&echo_func,&s,::_1,::_2));
//s.set_message_handler(bind(&echo_func,&s,::_1,::_2));
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
}
@@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE( unimplemented_websocket_version ) {
std::string output = "HTTP/1.1 400 Bad Request\r\nSec-WebSocket-Version: 0,7,8,13\r\nServer: test\r\n\r\n";
server s;
server s;
s.set_user_agent("test");
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
@@ -154,11 +154,11 @@ BOOST_AUTO_TEST_CASE( list_subprotocol_empty ) {
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
std::string subprotocol;
std::string subprotocol;
server s;
server s;
s.set_user_agent("test");
s.set_open_handler(bind(&open_func_subprotocol,&s,&subprotocol,::_1));
s.set_open_handler(bind(&open_func_subprotocol,&s,&subprotocol,::_1));
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
BOOST_CHECK_EQUAL(subprotocol, "");
@@ -169,13 +169,13 @@ BOOST_AUTO_TEST_CASE( list_subprotocol_one ) {
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
std::string validate;
std::string open;
std::string validate;
std::string open;
server s;
server s;
s.set_user_agent("test");
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"",::_1));
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"",::_1));
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
BOOST_CHECK_EQUAL(validate, "foo,");
@@ -187,13 +187,13 @@ BOOST_AUTO_TEST_CASE( accept_subprotocol_one ) {
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nSec-WebSocket-Protocol: foo\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
std::string validate;
std::string open;
std::string validate;
std::string open;
server s;
server s;
s.set_user_agent("test");
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"foo",::_1));
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"foo",::_1));
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
BOOST_CHECK_EQUAL(validate, "foo,");
@@ -205,17 +205,17 @@ BOOST_AUTO_TEST_CASE( accept_subprotocol_invalid ) {
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nSec-WebSocket-Protocol: foo\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
std::string validate;
std::string open;
std::string validate;
std::string open;
server s;
server s;
s.set_user_agent("test");
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"foo2",::_1));
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"foo2",::_1));
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
std::string o;
std::string o;
BOOST_CHECK_THROW(o = run_server_test(s,input), websocketpp::exception);
BOOST_CHECK_THROW(o = run_server_test(s,input), websocketpp::lib::error_code);
}
BOOST_AUTO_TEST_CASE( accept_subprotocol_two ) {
@@ -223,13 +223,13 @@ BOOST_AUTO_TEST_CASE( accept_subprotocol_two ) {
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nSec-WebSocket-Protocol: bar\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
std::string validate;
std::string open;
std::string validate;
std::string open;
server s;
server s;
s.set_user_agent("test");
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"bar",::_1));
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"bar",::_1));
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
BOOST_CHECK_EQUAL(validate, "foo,bar,");
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -107,7 +107,7 @@ struct config {
// Mock context that does no validation
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
context_ptr on_tls_init(websocketpp::connection_hdl) {
context_ptr on_tls_init(websocketpp::connection_hdl hdl) {
return context_ptr(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1));
}
+7 -7
View File
@@ -273,11 +273,11 @@ void run_dummy_client(std::string port) {
}
}
bool on_ping(websocketpp::connection_hdl, std::string) {
bool on_ping(websocketpp::connection_hdl, std::string payload) {
return false;
}
void cancel_on_open(server * s, websocketpp::connection_hdl) {
void cancel_on_open(server * s, websocketpp::connection_hdl hdl) {
s->stop_listening();
}
@@ -294,25 +294,25 @@ void ping_on_open(T * c, std::string payload, websocketpp::connection_hdl hdl) {
con->ping(payload);
}
void fail_on_pong(websocketpp::connection_hdl, std::string) {
void fail_on_pong(websocketpp::connection_hdl hdl, std::string payload) {
BOOST_FAIL( "expected no pong handler" );
}
void fail_on_pong_timeout(websocketpp::connection_hdl, std::string) {
void fail_on_pong_timeout(websocketpp::connection_hdl hdl, std::string payload) {
BOOST_FAIL( "expected no pong timeout" );
}
void req_pong(std::string expected_payload, websocketpp::connection_hdl,
void req_pong(std::string expected_payload, websocketpp::connection_hdl hdl,
std::string payload)
{
BOOST_CHECK_EQUAL( expected_payload, payload );
}
void fail_on_open(websocketpp::connection_hdl) {
void fail_on_open(websocketpp::connection_hdl hdl) {
BOOST_FAIL( "expected no open handler" );
}
void delay(websocketpp::connection_hdl, long duration) {
void delay(websocketpp::connection_hdl hdl, long duration) {
sleep(duration);
}
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+16 -92
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -63,7 +63,6 @@ struct stub_con : public iostream_con {
// Set the error to a known code that is unused by the library
// This way we can easily confirm that the handler was run at all.
, ec(websocketpp::error::make_error_code(websocketpp::error::test))
, indef_read_total(0)
{}
/// Get a shared pointer to this component
@@ -95,7 +94,7 @@ struct stub_con : public iostream_con {
}
void async_read_at_least(size_t num_bytes, char *buf, size_t len)
{
{
iostream_con::async_read_at_least(
num_bytes,
buf,
@@ -112,41 +111,7 @@ struct stub_con : public iostream_con {
ec = e;
}
void async_read_indef(size_t num_bytes, char *buf, size_t len)
{
indef_read_size = num_bytes;
indef_read_buf = buf;
indef_read_len = len;
indef_read();
}
void indef_read() {
iostream_con::async_read_at_least(
indef_read_size,
indef_read_buf,
indef_read_len,
websocketpp::lib::bind(
&stub_con::handle_indef,
type::get_shared(),
websocketpp::lib::placeholders::_1,
websocketpp::lib::placeholders::_2
)
);
}
void handle_indef(websocketpp::lib::error_code const & e, size_t amt_read) {
ec = e;
indef_read_total += amt_read;
indef_read();
}
websocketpp::lib::error_code ec;
size_t indef_read_size;
char * indef_read_buf;
size_t indef_read_len;
size_t indef_read_total;
};
// Stubs
@@ -266,22 +231,22 @@ BOOST_AUTO_TEST_CASE( async_read_at_least ) {
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
std::stringstream channel;
channel << "abcd";
channel >> *con;
BOOST_CHECK( channel.tellg() == -1 );
channel << "abcd";
channel >> *con;
BOOST_CHECK( channel.tellg() == -1 );
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
std::stringstream channel2;
channel2 << "e";
channel2 >> *con;
BOOST_CHECK( channel2.tellg() == -1 );
channel2 << "e";
channel2 >> *con;
BOOST_CHECK( channel2.tellg() == -1 );
BOOST_CHECK( !con->ec );
BOOST_CHECK( std::string(buf,10) == "abcdexxxxx" );
std::stringstream channel3;
channel3 << "f";
channel3 >> *con;
BOOST_CHECK( channel3.tellg() == 0 );
channel3 << "f";
channel3 >> *con;
BOOST_CHECK( channel3.tellg() == 0 );
BOOST_CHECK( !con->ec );
BOOST_CHECK( std::string(buf,10) == "abcdexxxxx" );
con->async_read_at_least(1,buf+5,5);
@@ -302,20 +267,20 @@ BOOST_AUTO_TEST_CASE( async_read_at_least2 ) {
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
std::stringstream channel;
channel << "abcdefg";
channel >> *con;
channel << "abcdefg";
channel >> *con;
BOOST_CHECK( channel.tellg() == 5 );
BOOST_CHECK( !con->ec );
BOOST_CHECK( std::string(buf,10) == "abcdexxxxx" );
con->async_read_at_least(1,buf+5,5);
channel >> *con;
BOOST_CHECK( channel.tellg() == -1 );
channel >> *con;
BOOST_CHECK( channel.tellg() == -1 );
BOOST_CHECK( !con->ec );
BOOST_CHECK( std::string(buf,10) == "abcdefgxxx" );
}
void timer_callback_stub(websocketpp::lib::error_code const &) {}
void timer_callback_stub(const websocketpp::lib::error_code & ec) {}
BOOST_AUTO_TEST_CASE( set_timer ) {
stub_con::ptr con(new stub_con(true,alogger,elogger));
@@ -349,47 +314,6 @@ BOOST_AUTO_TEST_CASE( async_read_at_least_read_some ) {
BOOST_CHECK_EQUAL( std::string(buf,10), "abcdefgxxx" );
}
BOOST_AUTO_TEST_CASE( async_read_at_least_read_some_indef ) {
stub_con::ptr con(new stub_con(true,alogger,elogger));
char buf[20];
memset(buf,'x',20);
con->async_read_indef(5,buf,5);
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
// here we expect to return early from read some because the outstanding
// read was for 5 bytes and we were called with 10.
char input[11] = "aaaaabbbbb";
BOOST_CHECK_EQUAL(con->read_some(input,10), 5);
BOOST_CHECK( !con->ec );
BOOST_CHECK_EQUAL( std::string(buf,10), "aaaaaxxxxx" );
BOOST_CHECK_EQUAL( con->indef_read_total, 5 );
// A subsequent read should read 5 more because the indef read refreshes
// itself. The new read will start again at the beginning of the buffer.
BOOST_CHECK_EQUAL(con->read_some(input+5,5), 5);
BOOST_CHECK( !con->ec );
BOOST_CHECK_EQUAL( std::string(buf,10), "bbbbbxxxxx" );
BOOST_CHECK_EQUAL( con->indef_read_total, 10 );
}
BOOST_AUTO_TEST_CASE( async_read_at_least_read_all ) {
stub_con::ptr con(new stub_con(true,alogger,elogger));
char buf[20];
memset(buf,'x',20);
con->async_read_indef(5,buf,5);
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
char input[11] = "aaaaabbbbb";
BOOST_CHECK_EQUAL(con->read_all(input,10), 10);
BOOST_CHECK( !con->ec );
BOOST_CHECK_EQUAL( std::string(buf,10), "bbbbbxxxxx" );
BOOST_CHECK_EQUAL( con->indef_read_total, 10 );
}
BOOST_AUTO_TEST_CASE( eof_flag ) {
stub_con::ptr con(new stub_con(true,alogger,elogger));
char buf[10];
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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,7 +35,7 @@
BOOST_AUTO_TEST_CASE( placeholder ) {}
/*BOOST_AUTO_TEST_CASE( blank_error ) {
websocketpp::lib::error_code ec;
websocketpp::lib::error_code ec;
BOOST_CHECK( !ec );
}*/
+60 -60
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2012, 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:
@@ -37,89 +37,89 @@
using namespace websocketpp;
BOOST_AUTO_TEST_CASE( reserved_values ) {
BOOST_CHECK( !close::status::reserved(999) );
BOOST_CHECK( close::status::reserved(1004) );
BOOST_CHECK( close::status::reserved(1014) );
BOOST_CHECK( close::status::reserved(1016) );
BOOST_CHECK( close::status::reserved(2999) );
BOOST_CHECK( !close::status::reserved(1000) );
BOOST_CHECK( !close::status::reserved(999) );
BOOST_CHECK( close::status::reserved(1004) );
BOOST_CHECK( close::status::reserved(1014) );
BOOST_CHECK( close::status::reserved(1016) );
BOOST_CHECK( close::status::reserved(2999) );
BOOST_CHECK( !close::status::reserved(1000) );
}
BOOST_AUTO_TEST_CASE( invalid_values ) {
BOOST_CHECK( close::status::invalid(0) );
BOOST_CHECK( close::status::invalid(999) );
BOOST_CHECK( !close::status::invalid(1000) );
BOOST_CHECK( close::status::invalid(1005) );
BOOST_CHECK( close::status::invalid(1006) );
BOOST_CHECK( close::status::invalid(1015) );
BOOST_CHECK( !close::status::invalid(2999) );
BOOST_CHECK( !close::status::invalid(3000) );
BOOST_CHECK( close::status::invalid(5000) );
BOOST_CHECK( close::status::invalid(0) );
BOOST_CHECK( close::status::invalid(999) );
BOOST_CHECK( !close::status::invalid(1000) );
BOOST_CHECK( close::status::invalid(1005) );
BOOST_CHECK( close::status::invalid(1006) );
BOOST_CHECK( close::status::invalid(1015) );
BOOST_CHECK( !close::status::invalid(2999) );
BOOST_CHECK( !close::status::invalid(3000) );
BOOST_CHECK( close::status::invalid(5000) );
}
BOOST_AUTO_TEST_CASE( value_extraction ) {
lib::error_code ec;
std::string payload = "oo";
lib::error_code ec;
std::string payload = "oo";
// Value = 1000
payload[0] = 0x03;
payload[1] = char(0xe8);
BOOST_CHECK( close::extract_code(payload,ec) == close::status::normal );
BOOST_CHECK( !ec );
// Value = 1000
payload[0] = 0x03;
payload[1] = char(0xe8);
BOOST_CHECK( close::extract_code(payload,ec) == close::status::normal );
BOOST_CHECK( !ec );
// Value = 1004
payload[0] = 0x03;
payload[1] = char(0xec);
BOOST_CHECK( close::extract_code(payload,ec) == 1004 );
BOOST_CHECK( ec == error::reserved_close_code );
// Value = 1004
payload[0] = 0x03;
payload[1] = char(0xec);
BOOST_CHECK( close::extract_code(payload,ec) == 1004 );
BOOST_CHECK( ec == error::reserved_close_code );
// Value = 1005
payload[0] = 0x03;
payload[1] = char(0xed);
BOOST_CHECK( close::extract_code(payload,ec) == close::status::no_status );
BOOST_CHECK( ec == error::invalid_close_code );
// Value = 1005
payload[0] = 0x03;
payload[1] = char(0xed);
BOOST_CHECK( close::extract_code(payload,ec) == close::status::no_status );
BOOST_CHECK( ec == error::invalid_close_code );
// Value = 3000
payload[0] = 0x0b;
payload[1] = char(0xb8);
BOOST_CHECK( close::extract_code(payload,ec) == 3000 );
BOOST_CHECK( !ec );
// Value = 3000
payload[0] = 0x0b;
payload[1] = char(0xb8);
BOOST_CHECK( close::extract_code(payload,ec) == 3000 );
BOOST_CHECK( !ec );
}
BOOST_AUTO_TEST_CASE( extract_empty ) {
lib::error_code ec;
std::string payload = "";
lib::error_code ec;
std::string payload = "";
BOOST_CHECK( close::extract_code(payload,ec) == close::status::no_status );
BOOST_CHECK( !ec );
BOOST_CHECK( close::extract_code(payload,ec) == close::status::no_status );
BOOST_CHECK( !ec );
}
BOOST_AUTO_TEST_CASE( extract_short ) {
lib::error_code ec;
std::string payload = "0";
lib::error_code ec;
std::string payload = "0";
BOOST_CHECK( close::extract_code(payload,ec) == close::status::protocol_error );
BOOST_CHECK( ec == error::bad_close_code );
BOOST_CHECK( close::extract_code(payload,ec) == close::status::protocol_error );
BOOST_CHECK( ec == error::bad_close_code );
}
BOOST_AUTO_TEST_CASE( extract_reason ) {
lib::error_code ec;
std::string payload = "00Foo";
lib::error_code ec;
std::string payload = "00Foo";
BOOST_CHECK( close::extract_reason(payload,ec) == "Foo" );
BOOST_CHECK( !ec );
BOOST_CHECK( close::extract_reason(payload,ec) == "Foo" );
BOOST_CHECK( !ec );
payload = "";
BOOST_CHECK( close::extract_reason(payload,ec) == "" );
BOOST_CHECK( !ec );
payload = "";
BOOST_CHECK( close::extract_reason(payload,ec) == "" );
BOOST_CHECK( !ec );
payload = "00";
BOOST_CHECK( close::extract_reason(payload,ec) == "" );
BOOST_CHECK( !ec );
payload = "00";
BOOST_CHECK( close::extract_reason(payload,ec) == "" );
BOOST_CHECK( !ec );
payload = "000";
payload[2] = char(0xFF);
payload = "000";
payload[2] = char(0xFF);
close::extract_reason(payload,ec);
BOOST_CHECK( ec == error::invalid_utf8 );
close::extract_reason(payload,ec);
BOOST_CHECK( ec == error::invalid_utf8 );
}
+302 -302
View File
@@ -37,98 +37,98 @@
using namespace websocketpp;
BOOST_AUTO_TEST_CASE( basic_bits ) {
frame::basic_header h1(0x00,0x00); // all false
frame::basic_header h2(0xF0,0x80); // all true
frame::basic_header h1(0x00,0x00); // all false
frame::basic_header h2(0xF0,0x80); // all true
// Read Values
BOOST_CHECK( frame::get_fin(h1) == false );
BOOST_CHECK( frame::get_rsv1(h1) == false );
BOOST_CHECK( frame::get_rsv2(h1) == false );
BOOST_CHECK( frame::get_rsv3(h1) == false );
BOOST_CHECK( frame::get_masked(h1) == false );
// Read Values
BOOST_CHECK( frame::get_fin(h1) == false );
BOOST_CHECK( frame::get_rsv1(h1) == false );
BOOST_CHECK( frame::get_rsv2(h1) == false );
BOOST_CHECK( frame::get_rsv3(h1) == false );
BOOST_CHECK( frame::get_masked(h1) == false );
BOOST_CHECK( frame::get_fin(h2) == true );
BOOST_CHECK( frame::get_rsv1(h2) == true );
BOOST_CHECK( frame::get_rsv2(h2) == true );
BOOST_CHECK( frame::get_rsv3(h2) == true );
BOOST_CHECK( frame::get_masked(h2) == true );
BOOST_CHECK( frame::get_fin(h2) == true );
BOOST_CHECK( frame::get_rsv1(h2) == true );
BOOST_CHECK( frame::get_rsv2(h2) == true );
BOOST_CHECK( frame::get_rsv3(h2) == true );
BOOST_CHECK( frame::get_masked(h2) == true );
// Set Values
frame::set_fin(h1,true);
BOOST_CHECK( h1.b0 == 0x80 );
// Set Values
frame::set_fin(h1,true);
BOOST_CHECK( h1.b0 == 0x80 );
frame::set_rsv1(h1,true);
BOOST_CHECK( h1.b0 == 0xC0 );
frame::set_rsv1(h1,true);
BOOST_CHECK( h1.b0 == 0xC0 );
frame::set_rsv2(h1,true);
BOOST_CHECK( h1.b0 == 0xE0 );
frame::set_rsv2(h1,true);
BOOST_CHECK( h1.b0 == 0xE0 );
frame::set_rsv3(h1,true);
BOOST_CHECK( h1.b0 == 0xF0 );
frame::set_rsv3(h1,true);
BOOST_CHECK( h1.b0 == 0xF0 );
frame::set_masked(h1,true);
BOOST_CHECK( h1.b1 == 0x80 );
frame::set_masked(h1,true);
BOOST_CHECK( h1.b1 == 0x80 );
}
BOOST_AUTO_TEST_CASE( basic_constructors ) {
// Read Values
frame::basic_header h1(frame::opcode::TEXT,12,true,false);
BOOST_CHECK( frame::get_opcode(h1) == frame::opcode::TEXT );
BOOST_CHECK( frame::get_basic_size(h1) == 12 );
BOOST_CHECK( frame::get_fin(h1) == true );
BOOST_CHECK( frame::get_rsv1(h1) == false );
BOOST_CHECK( frame::get_rsv2(h1) == false );
BOOST_CHECK( frame::get_rsv3(h1) == false );
BOOST_CHECK( frame::get_masked(h1) == false );
// Read Values
frame::basic_header h1(frame::opcode::TEXT,12,true,false);
BOOST_CHECK( frame::get_opcode(h1) == frame::opcode::TEXT );
BOOST_CHECK( frame::get_basic_size(h1) == 12 );
BOOST_CHECK( frame::get_fin(h1) == true );
BOOST_CHECK( frame::get_rsv1(h1) == false );
BOOST_CHECK( frame::get_rsv2(h1) == false );
BOOST_CHECK( frame::get_rsv3(h1) == false );
BOOST_CHECK( frame::get_masked(h1) == false );
frame::basic_header h2(frame::opcode::BINARY,0,false,false,false,true);
BOOST_CHECK( frame::get_opcode(h2) == frame::opcode::BINARY );
BOOST_CHECK( frame::get_basic_size(h2) == 0 );
BOOST_CHECK( frame::get_fin(h2) == false );
BOOST_CHECK( frame::get_rsv1(h2) == false );
BOOST_CHECK( frame::get_rsv2(h2) == true );
BOOST_CHECK( frame::get_rsv3(h2) == false );
BOOST_CHECK( frame::get_masked(h2) == false );
frame::basic_header h2(frame::opcode::BINARY,0,false,false,false,true);
BOOST_CHECK( frame::get_opcode(h2) == frame::opcode::BINARY );
BOOST_CHECK( frame::get_basic_size(h2) == 0 );
BOOST_CHECK( frame::get_fin(h2) == false );
BOOST_CHECK( frame::get_rsv1(h2) == false );
BOOST_CHECK( frame::get_rsv2(h2) == true );
BOOST_CHECK( frame::get_rsv3(h2) == false );
BOOST_CHECK( frame::get_masked(h2) == false );
}
BOOST_AUTO_TEST_CASE( basic_size ) {
frame::basic_header h1(0x00,0x00); // length 0
frame::basic_header h2(0x00,0x01); // length 1
frame::basic_header h3(0x00,0x7D); // length 125
frame::basic_header h4(0x00,0x7E); // length 126
frame::basic_header h5(0x00,0x7F); // length 127
frame::basic_header h6(0x00,0x80); // length 0, mask bit set
frame::basic_header h1(0x00,0x00); // length 0
frame::basic_header h2(0x00,0x01); // length 1
frame::basic_header h3(0x00,0x7D); // length 125
frame::basic_header h4(0x00,0x7E); // length 126
frame::basic_header h5(0x00,0x7F); // length 127
frame::basic_header h6(0x00,0x80); // length 0, mask bit set
BOOST_CHECK( frame::get_basic_size(h1) == 0 );
BOOST_CHECK( frame::get_basic_size(h2) == 1 );
BOOST_CHECK( frame::get_basic_size(h3) == 125 );
BOOST_CHECK( frame::get_basic_size(h4) == 126 );
BOOST_CHECK( frame::get_basic_size(h5) == 127 );
BOOST_CHECK( frame::get_basic_size(h6) == 0 );
BOOST_CHECK( frame::get_basic_size(h1) == 0 );
BOOST_CHECK( frame::get_basic_size(h2) == 1 );
BOOST_CHECK( frame::get_basic_size(h3) == 125 );
BOOST_CHECK( frame::get_basic_size(h4) == 126 );
BOOST_CHECK( frame::get_basic_size(h5) == 127 );
BOOST_CHECK( frame::get_basic_size(h6) == 0 );
/*frame::set_basic_size(h1,1);
BOOST_CHECK( h1.b1 == 0x01 );
/*frame::set_basic_size(h1,1);
BOOST_CHECK( h1.b1 == 0x01 );
frame::set_basic_size(h1,125);
BOOST_CHECK( h1.b1 == 0x7D );
frame::set_basic_size(h1,125);
BOOST_CHECK( h1.b1 == 0x7D );
frame::set_basic_size(h1,126);
BOOST_CHECK( h1.b1 == 0x7E );
frame::set_basic_size(h1,126);
BOOST_CHECK( h1.b1 == 0x7E );
frame::set_basic_size(h1,127);
BOOST_CHECK( h1.b1 == 0x7F );
frame::set_basic_size(h1,127);
BOOST_CHECK( h1.b1 == 0x7F );
frame::set_basic_size(h1,0);
BOOST_CHECK( h1.b1 == 0x00 );*/
frame::set_basic_size(h1,0);
BOOST_CHECK( h1.b1 == 0x00 );*/
}
BOOST_AUTO_TEST_CASE( basic_header_length ) {
frame::basic_header h1(0x82,0x00); // short binary frame, unmasked
frame::basic_header h2(0x82,0x80); // short binary frame, masked
frame::basic_header h3(0x82,0x7E); // medium binary frame, unmasked
frame::basic_header h4(0x82,0xFE); // medium binary frame, masked
frame::basic_header h5(0x82,0x7F); // jumbo binary frame, unmasked
frame::basic_header h6(0x82,0xFF); // jumbo binary frame, masked
frame::basic_header h1(0x82,0x00); // short binary frame, unmasked
frame::basic_header h2(0x82,0x80); // short binary frame, masked
frame::basic_header h3(0x82,0x7E); // medium binary frame, unmasked
frame::basic_header h4(0x82,0xFE); // medium binary frame, masked
frame::basic_header h5(0x82,0x7F); // jumbo binary frame, unmasked
frame::basic_header h6(0x82,0xFF); // jumbo binary frame, masked
BOOST_CHECK( frame::get_header_len(h1) == 2);
BOOST_CHECK( frame::get_header_len(h2) == 6);
@@ -139,127 +139,127 @@ BOOST_AUTO_TEST_CASE( basic_header_length ) {
}
BOOST_AUTO_TEST_CASE( basic_opcode ) {
frame::basic_header h1(0x00,0x00);
frame::basic_header h1(0x00,0x00);
BOOST_CHECK( is_control(frame::opcode::CONTINUATION) == false);
BOOST_CHECK( is_control(frame::opcode::TEXT) == false);
BOOST_CHECK( is_control(frame::opcode::BINARY) == false);
BOOST_CHECK( is_control(frame::opcode::CLOSE) == true);
BOOST_CHECK( is_control(frame::opcode::PING) == true);
BOOST_CHECK( is_control(frame::opcode::PONG) == true);
BOOST_CHECK( is_control(frame::opcode::CONTINUATION) == false);
BOOST_CHECK( is_control(frame::opcode::TEXT) == false);
BOOST_CHECK( is_control(frame::opcode::BINARY) == false);
BOOST_CHECK( is_control(frame::opcode::CLOSE) == true);
BOOST_CHECK( is_control(frame::opcode::PING) == true);
BOOST_CHECK( is_control(frame::opcode::PONG) == true);
BOOST_CHECK( frame::get_opcode(h1) == frame::opcode::CONTINUATION );
BOOST_CHECK( frame::get_opcode(h1) == frame::opcode::CONTINUATION );
}
BOOST_AUTO_TEST_CASE( extended_header_basics ) {
frame::extended_header h1;
uint8_t h1_solution[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
frame::extended_header h1;
uint8_t h1_solution[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
frame::extended_header h2(uint16_t(255));
uint8_t h2_solution[12] = {0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
frame::extended_header h2(uint16_t(255));
uint8_t h2_solution[12] = {0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
frame::extended_header h3(uint16_t(256),htonl(0x8040201));
uint8_t h3_solution[12] = {0x01, 0x00, 0x08, 0x04, 0x02, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
frame::extended_header h3(uint16_t(256),htonl(0x8040201));
uint8_t h3_solution[12] = {0x01, 0x00, 0x08, 0x04, 0x02, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
frame::extended_header h4(uint64_t(0x0807060504030201LL));
uint8_t h4_solution[12] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
0x02, 0x01, 0x00, 0x00, 0x00, 0x00};
frame::extended_header h4(uint64_t(0x0807060504030201LL));
uint8_t h4_solution[12] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
0x02, 0x01, 0x00, 0x00, 0x00, 0x00};
frame::extended_header h5(uint64_t(0x0807060504030201LL),htonl(0x8040201));
uint8_t h5_solution[12] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
0x02, 0x01, 0x08, 0x04, 0x02, 0x01};
frame::extended_header h5(uint64_t(0x0807060504030201LL),htonl(0x8040201));
uint8_t h5_solution[12] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
0x02, 0x01, 0x08, 0x04, 0x02, 0x01};
BOOST_CHECK( std::equal(h1_solution,h1_solution+12,h1.bytes) );
BOOST_CHECK( std::equal(h2_solution,h2_solution+12,h2.bytes) );
BOOST_CHECK( std::equal(h3_solution,h3_solution+12,h3.bytes) );
BOOST_CHECK( std::equal(h4_solution,h4_solution+12,h4.bytes) );
BOOST_CHECK( std::equal(h5_solution,h5_solution+12,h5.bytes) );
BOOST_CHECK( std::equal(h1_solution,h1_solution+12,h1.bytes) );
BOOST_CHECK( std::equal(h2_solution,h2_solution+12,h2.bytes) );
BOOST_CHECK( std::equal(h3_solution,h3_solution+12,h3.bytes) );
BOOST_CHECK( std::equal(h4_solution,h4_solution+12,h4.bytes) );
BOOST_CHECK( std::equal(h5_solution,h5_solution+12,h5.bytes) );
}
BOOST_AUTO_TEST_CASE( extended_header_extractors ) {
frame::basic_header h1(0x00,0x7E);
frame::extended_header e1(uint16_t(255));
BOOST_CHECK( get_extended_size(e1) == 255 );
BOOST_CHECK( get_payload_size(h1,e1) == 255 );
BOOST_CHECK( get_masking_key_offset(h1) == 2 );
BOOST_CHECK( get_masking_key(h1,e1).i == 0 );
frame::basic_header h1(0x00,0x7E);
frame::extended_header e1(uint16_t(255));
BOOST_CHECK( get_extended_size(e1) == 255 );
BOOST_CHECK( get_payload_size(h1,e1) == 255 );
BOOST_CHECK( get_masking_key_offset(h1) == 2 );
BOOST_CHECK( get_masking_key(h1,e1).i == 0 );
frame::basic_header h2(0x00,0x7F);
frame::extended_header e2(uint64_t(0x0807060504030201LL));
BOOST_CHECK( get_jumbo_size(e2) == 0x0807060504030201LL );
BOOST_CHECK( get_payload_size(h2,e2) == 0x0807060504030201LL );
BOOST_CHECK( get_masking_key_offset(h2) == 8 );
BOOST_CHECK( get_masking_key(h2,e2).i == 0 );
frame::basic_header h2(0x00,0x7F);
frame::extended_header e2(uint64_t(0x0807060504030201LL));
BOOST_CHECK( get_jumbo_size(e2) == 0x0807060504030201LL );
BOOST_CHECK( get_payload_size(h2,e2) == 0x0807060504030201LL );
BOOST_CHECK( get_masking_key_offset(h2) == 8 );
BOOST_CHECK( get_masking_key(h2,e2).i == 0 );
frame::basic_header h3(0x00,0xFE);
frame::extended_header e3(uint16_t(255),0x08040201);
BOOST_CHECK( get_extended_size(e3) == 255 );
BOOST_CHECK( get_payload_size(h3,e3) == 255 );
BOOST_CHECK( get_masking_key_offset(h3) == 2 );
BOOST_CHECK( get_masking_key(h3,e3).i == 0x08040201 );
frame::basic_header h3(0x00,0xFE);
frame::extended_header e3(uint16_t(255),0x08040201);
BOOST_CHECK( get_extended_size(e3) == 255 );
BOOST_CHECK( get_payload_size(h3,e3) == 255 );
BOOST_CHECK( get_masking_key_offset(h3) == 2 );
BOOST_CHECK( get_masking_key(h3,e3).i == 0x08040201 );
frame::basic_header h4(0x00,0xFF);
frame::extended_header e4(uint64_t(0x0807060504030201LL),0x08040201);
BOOST_CHECK( get_jumbo_size(e4) == 0x0807060504030201LL );
BOOST_CHECK( get_payload_size(h4,e4) == 0x0807060504030201LL );
BOOST_CHECK( get_masking_key_offset(h4) == 8 );
BOOST_CHECK( get_masking_key(h4,e4).i == 0x08040201 );
frame::basic_header h4(0x00,0xFF);
frame::extended_header e4(uint64_t(0x0807060504030201LL),0x08040201);
BOOST_CHECK( get_jumbo_size(e4) == 0x0807060504030201LL );
BOOST_CHECK( get_payload_size(h4,e4) == 0x0807060504030201LL );
BOOST_CHECK( get_masking_key_offset(h4) == 8 );
BOOST_CHECK( get_masking_key(h4,e4).i == 0x08040201 );
frame::basic_header h5(0x00,0x7D);
frame::extended_header e5;
BOOST_CHECK( get_payload_size(h5,e5) == 125 );
frame::basic_header h5(0x00,0x7D);
frame::extended_header e5;
BOOST_CHECK( get_payload_size(h5,e5) == 125 );
}
BOOST_AUTO_TEST_CASE( header_preparation ) {
frame::basic_header h1(0x81,0xFF); //
frame::extended_header e1(uint64_t(0xFFFFFLL),htonl(0xD5FB70EE));
std::string p1 = prepare_header(h1, e1);
uint8_t s1[14] = {0x81, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF,
0xD5, 0xFB, 0x70, 0xEE};
frame::basic_header h1(0x81,0xFF); //
frame::extended_header e1(uint64_t(0xFFFFFLL),htonl(0xD5FB70EE));
std::string p1 = prepare_header(h1, e1);
uint8_t s1[14] = {0x81, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF,
0xD5, 0xFB, 0x70, 0xEE};
BOOST_CHECK( p1.size() == 14);
BOOST_CHECK( std::equal(p1.begin(),p1.end(),reinterpret_cast<char*>(s1)) );
BOOST_CHECK( p1.size() == 14);
BOOST_CHECK( std::equal(p1.begin(),p1.end(),reinterpret_cast<char*>(s1)) );
frame::basic_header h2(0x81,0x7E); //
frame::extended_header e2(uint16_t(255));
std::string p2 = prepare_header(h2, e2);
uint8_t s2[4] = {0x81, 0x7E, 0x00, 0xFF};
frame::basic_header h2(0x81,0x7E); //
frame::extended_header e2(uint16_t(255));
std::string p2 = prepare_header(h2, e2);
uint8_t s2[4] = {0x81, 0x7E, 0x00, 0xFF};
BOOST_CHECK( p2.size() == 4);
BOOST_CHECK( std::equal(p2.begin(),p2.end(),reinterpret_cast<char*>(s2)) );
BOOST_CHECK( p2.size() == 4);
BOOST_CHECK( std::equal(p2.begin(),p2.end(),reinterpret_cast<char*>(s2)) );
}
BOOST_AUTO_TEST_CASE( prepare_masking_key ) {
frame::masking_key_type key;
frame::masking_key_type key;
key.i = htonl(0x12345678);
key.i = htonl(0x12345678);
if (sizeof(size_t) == 8) {
BOOST_CHECK(
frame::prepare_masking_key(key) == lib::net::_htonll(0x1234567812345678LL)
);
} else {
BOOST_CHECK( frame::prepare_masking_key(key) == htonl(0x12345678) );
}
if (sizeof(size_t) == 8) {
BOOST_CHECK(
frame::prepare_masking_key(key) == lib::net::htonll(0x1234567812345678LL)
);
} else {
BOOST_CHECK( frame::prepare_masking_key(key) == htonl(0x12345678) );
}
}
BOOST_AUTO_TEST_CASE( prepare_masking_key2 ) {
frame::masking_key_type key;
frame::masking_key_type key;
key.i = htonl(0xD5FB70EE);
key.i = htonl(0xD5FB70EE);
// One call
if (sizeof(size_t) == 8) {
BOOST_CHECK(
frame::prepare_masking_key(key) == lib::net::_htonll(0xD5FB70EED5FB70EELL)
);
} else {
BOOST_CHECK( frame::prepare_masking_key(key) == htonl(0xD5FB70EE) );
}
// One call
if (sizeof(size_t) == 8) {
BOOST_CHECK(
frame::prepare_masking_key(key) == lib::net::htonll(0xD5FB70EED5FB70EELL)
);
} else {
BOOST_CHECK( frame::prepare_masking_key(key) == htonl(0xD5FB70EE) );
}
}
// TODO: figure out a way to run/test both 4 and 8 byte versions.
@@ -282,241 +282,241 @@ BOOST_AUTO_TEST_CASE( circshift ) {
}
BOOST_AUTO_TEST_CASE( block_byte_mask ) {
uint8_t input[15] = {0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
uint8_t input[15] = {0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00};
uint8_t output[15];
uint8_t output[15];
uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02};
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
byte_mask(input,input+15,output,key);
byte_mask(input,input+15,output,key);
BOOST_CHECK( std::equal(output,output+15,masked) );
BOOST_CHECK( std::equal(output,output+15,masked) );
}
BOOST_AUTO_TEST_CASE( block_byte_mask_inplace ) {
uint8_t buffer[15] = {0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
uint8_t buffer[15] = {0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00};
uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02};
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
byte_mask(buffer,buffer+15,key);
byte_mask(buffer,buffer+15,key);
BOOST_CHECK( std::equal(buffer,buffer+15,masked) );
BOOST_CHECK( std::equal(buffer,buffer+15,masked) );
}
BOOST_AUTO_TEST_CASE( block_word_mask ) {
uint8_t input[15] = {0x00, 0x00, 0x00, 0x00,
uint8_t input[15] = {0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00};
uint8_t output[15];
uint8_t output[15];
uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02};
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
word_mask_exact(input,output,15,key);
word_mask_exact(input,output,15,key);
BOOST_CHECK( std::equal(output,output+15,masked) );
BOOST_CHECK( std::equal(output,output+15,masked) );
}
BOOST_AUTO_TEST_CASE( block_word_mask_inplace ) {
uint8_t buffer[15] = {0x00, 0x00, 0x00, 0x00,
uint8_t buffer[15] = {0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00};
uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02};
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
word_mask_exact(buffer,15,key);
word_mask_exact(buffer,15,key);
BOOST_CHECK( std::equal(buffer,buffer+15,masked) );
BOOST_CHECK( std::equal(buffer,buffer+15,masked) );
}
BOOST_AUTO_TEST_CASE( continuous_word_mask ) {
uint8_t input[16];
uint8_t output[16];
uint8_t input[16];
uint8_t output[16];
uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x00};
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
// One call
size_t pkey,pkey_temp;
pkey = frame::prepare_masking_key(key);
std::fill_n(input,16,0x00);
std::fill_n(output,16,0x00);
frame::word_mask_circ(input,output,15,pkey);
BOOST_CHECK( std::equal(output,output+16,masked) );
// One call
size_t pkey,pkey_temp;
pkey = frame::prepare_masking_key(key);
std::fill_n(input,16,0x00);
std::fill_n(output,16,0x00);
frame::word_mask_circ(input,output,15,pkey);
BOOST_CHECK( std::equal(output,output+16,masked) );
// calls not split on word boundaries
pkey = frame::prepare_masking_key(key);
std::fill_n(input,16,0x00);
std::fill_n(output,16,0x00);
// calls not split on word boundaries
pkey = frame::prepare_masking_key(key);
std::fill_n(input,16,0x00);
std::fill_n(output,16,0x00);
pkey_temp = frame::word_mask_circ(input,output,7,pkey);
BOOST_CHECK( std::equal(output,output+7,masked) );
BOOST_CHECK( pkey_temp == frame::circshift_prepared_key(pkey,3) );
pkey_temp = frame::word_mask_circ(input,output,7,pkey);
BOOST_CHECK( std::equal(output,output+7,masked) );
BOOST_CHECK( pkey_temp == frame::circshift_prepared_key(pkey,3) );
pkey_temp = frame::word_mask_circ(input+7,output+7,8,pkey_temp);
BOOST_CHECK( std::equal(output,output+16,masked) );
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
pkey_temp = frame::word_mask_circ(input+7,output+7,8,pkey_temp);
BOOST_CHECK( std::equal(output,output+16,masked) );
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
}
BOOST_AUTO_TEST_CASE( continuous_byte_mask ) {
uint8_t input[16];
uint8_t output[16];
uint8_t input[16];
uint8_t output[16];
uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x00};
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
// One call
size_t pkey,pkey_temp;
pkey = frame::prepare_masking_key(key);
std::fill_n(input,16,0x00);
std::fill_n(output,16,0x00);
frame::byte_mask_circ(input,output,15,pkey);
BOOST_CHECK( std::equal(output,output+16,masked) );
// One call
size_t pkey,pkey_temp;
pkey = frame::prepare_masking_key(key);
std::fill_n(input,16,0x00);
std::fill_n(output,16,0x00);
frame::byte_mask_circ(input,output,15,pkey);
BOOST_CHECK( std::equal(output,output+16,masked) );
// calls not split on word boundaries
pkey = frame::prepare_masking_key(key);
std::fill_n(input,16,0x00);
std::fill_n(output,16,0x00);
// calls not split on word boundaries
pkey = frame::prepare_masking_key(key);
std::fill_n(input,16,0x00);
std::fill_n(output,16,0x00);
pkey_temp = frame::byte_mask_circ(input,output,7,pkey);
BOOST_CHECK( std::equal(output,output+7,masked) );
BOOST_CHECK( pkey_temp == frame::circshift_prepared_key(pkey,3) );
pkey_temp = frame::byte_mask_circ(input,output,7,pkey);
BOOST_CHECK( std::equal(output,output+7,masked) );
BOOST_CHECK( pkey_temp == frame::circshift_prepared_key(pkey,3) );
pkey_temp = frame::byte_mask_circ(input+7,output+7,8,pkey_temp);
BOOST_CHECK( std::equal(output,output+16,masked) );
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
pkey_temp = frame::byte_mask_circ(input+7,output+7,8,pkey_temp);
BOOST_CHECK( std::equal(output,output+16,masked) );
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
}
BOOST_AUTO_TEST_CASE( continuous_word_mask_inplace ) {
uint8_t buffer[16];
uint8_t buffer[16];
uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x00};
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
// One call
size_t pkey,pkey_temp;
pkey = frame::prepare_masking_key(key);
std::fill_n(buffer,16,0x00);
frame::word_mask_circ(buffer,15,pkey);
BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
// One call
size_t pkey,pkey_temp;
pkey = frame::prepare_masking_key(key);
std::fill_n(buffer,16,0x00);
frame::word_mask_circ(buffer,15,pkey);
BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
// calls not split on word boundaries
pkey = frame::prepare_masking_key(key);
std::fill_n(buffer,16,0x00);
// calls not split on word boundaries
pkey = frame::prepare_masking_key(key);
std::fill_n(buffer,16,0x00);
pkey_temp = frame::word_mask_circ(buffer,7,pkey);
BOOST_CHECK( std::equal(buffer,buffer+7,masked) );
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
pkey_temp = frame::word_mask_circ(buffer,7,pkey);
BOOST_CHECK( std::equal(buffer,buffer+7,masked) );
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
pkey_temp = frame::word_mask_circ(buffer+7,8,pkey_temp);
BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
pkey_temp = frame::word_mask_circ(buffer+7,8,pkey_temp);
BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
}
BOOST_AUTO_TEST_CASE( continuous_byte_mask_inplace ) {
uint8_t buffer[16];
uint8_t buffer[16];
uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x03,
0x00, 0x01, 0x02, 0x00};
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
frame::masking_key_type key;
key.c[0] = 0x00;
key.c[1] = 0x01;
key.c[2] = 0x02;
key.c[3] = 0x03;
// One call
size_t pkey,pkey_temp;
pkey = frame::prepare_masking_key(key);
std::fill_n(buffer,16,0x00);
frame::byte_mask_circ(buffer,15,pkey);
BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
// One call
size_t pkey,pkey_temp;
pkey = frame::prepare_masking_key(key);
std::fill_n(buffer,16,0x00);
frame::byte_mask_circ(buffer,15,pkey);
BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
// calls not split on word boundaries
pkey = frame::prepare_masking_key(key);
std::fill_n(buffer,16,0x00);
// calls not split on word boundaries
pkey = frame::prepare_masking_key(key);
std::fill_n(buffer,16,0x00);
pkey_temp = frame::byte_mask_circ(buffer,7,pkey);
BOOST_CHECK( std::equal(buffer,buffer+7,masked) );
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
pkey_temp = frame::byte_mask_circ(buffer,7,pkey);
BOOST_CHECK( std::equal(buffer,buffer+7,masked) );
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
pkey_temp = frame::byte_mask_circ(buffer+7,8,pkey_temp);
BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
pkey_temp = frame::byte_mask_circ(buffer+7,8,pkey_temp);
BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
}
BOOST_AUTO_TEST_CASE( continuous_word_mask2 ) {
uint8_t buffer[12] = {0xA6, 0x15, 0x97, 0xB9,
uint8_t buffer[12] = {0xA6, 0x15, 0x97, 0xB9,
0x81, 0x50, 0xAC, 0xBA,
0x9C, 0x1C, 0x9F, 0xF4};
@@ -524,15 +524,15 @@ BOOST_AUTO_TEST_CASE( continuous_word_mask2 ) {
0x6F, 0x20, 0x57, 0x6F,
0x72, 0x6C, 0x64, 0x21};
frame::masking_key_type key;
key.c[0] = 0xEE;
key.c[1] = 0x70;
key.c[2] = 0xFB;
key.c[3] = 0xD5;
frame::masking_key_type key;
key.c[0] = 0xEE;
key.c[1] = 0x70;
key.c[2] = 0xFB;
key.c[3] = 0xD5;
// One call
size_t pkey;
pkey = frame::prepare_masking_key(key);
frame::word_mask_circ(buffer,12,pkey);
BOOST_CHECK( std::equal(buffer,buffer+12,unmasked) );
// One call
size_t pkey;
pkey = frame::prepare_masking_key(key);
frame::word_mask_circ(buffer,12,pkey);
BOOST_CHECK( std::equal(buffer,buffer+12,unmasked) );
}
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -48,7 +48,7 @@ public:
m_endpoint.init_asio();
m_endpoint.start_perpetual();
m_thread = websocketpp::lib::make_shared<websocketpp::lib::thread>(&client::run, &m_endpoint);
m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint));
}
private:
client m_endpoint;
+2 -2
View File
@@ -97,7 +97,7 @@ public:
m_endpoint.init_asio();
m_endpoint.start_perpetual();
m_thread = websocketpp::lib::make_shared<websocketpp::lib::thread>(&client::run, &m_endpoint);
m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint));
}
int connect(std::string const & uri) {
@@ -111,7 +111,7 @@ public:
}
int new_id = m_next_id++;
connection_metadata::ptr metadata_ptr = websocketpp::lib::make_shared<connection_metadata>(new_id, con->get_handle(), uri);
connection_metadata::ptr metadata_ptr(new connection_metadata(new_id, con->get_handle(), uri));
m_connection_list[new_id] = metadata_ptr;
con->set_open_handler(websocketpp::lib::bind(
+2 -2
View File
@@ -119,7 +119,7 @@ public:
m_endpoint.init_asio();
m_endpoint.start_perpetual();
m_thread = websocketpp::lib::make_shared<websocketpp::lib::thread>(&client::run, &m_endpoint);
m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint));
}
~websocket_endpoint() {
@@ -155,7 +155,7 @@ public:
}
int new_id = m_next_id++;
connection_metadata::ptr metadata_ptr = websocketpp::lib::make_shared<connection_metadata>(new_id, con->get_handle(), uri);
connection_metadata::ptr metadata_ptr(new connection_metadata(new_id, con->get_handle(), uri));
m_connection_list[new_id] = metadata_ptr;
con->set_open_handler(websocketpp::lib::bind(
+13 -35
View File
@@ -45,11 +45,6 @@ static std::string const base64_chars =
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
/// Test whether a character is a valid base64 character
/**
* @param c The character to test
* @return true if c is a valid base64 character
*/
static inline bool is_base64(unsigned char c) {
return (c == 43 || // +
(c >= 47 && c <= 57) || // /-9
@@ -57,21 +52,17 @@ static inline bool is_base64(unsigned char c) {
(c >= 97 && c <= 122)); // a-z
}
/// Encode a char buffer into a base64 string
/**
* @param input The input data
* @param len The length of input in bytes
* @return A base64 encoded string representing input
*/
inline std::string base64_encode(unsigned char const * input, size_t len) {
inline std::string base64_encode(unsigned char const * bytes_to_encode, unsigned
int in_len)
{
std::string ret;
int i = 0;
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];
while (len--) {
char_array_3[i++] = *(input++);
while (in_len--) {
char_array_3[i++] = *(bytes_to_encode++);
if (i == 3) {
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) +
@@ -106,38 +97,25 @@ inline std::string base64_encode(unsigned char const * input, size_t len) {
while((i++ < 3)) {
ret += '=';
}
}
}
return ret;
return ret;
}
/// Encode a string into a base64 string
/**
* @param input The input data
* @return A base64 encoded string representing input
*/
inline std::string base64_encode(std::string const & input) {
return base64_encode(
reinterpret_cast<const unsigned char *>(input.data()),
input.size()
);
inline std::string base64_encode(std::string const & data) {
return base64_encode(reinterpret_cast<const unsigned char *>(data.data()),data.size());
}
/// Decode a base64 encoded string into a string of raw bytes
/**
* @param input The base64 encoded input data
* @return A string representing the decoded raw bytes
*/
inline std::string base64_decode(std::string const & input) {
size_t in_len = input.size();
inline std::string base64_decode(std::string const & encoded_string) {
size_t in_len = encoded_string.size();
int i = 0;
int j = 0;
int in_ = 0;
unsigned char char_array_4[4], char_array_3[3];
std::string ret;
while (in_len-- && ( input[in_] != '=') && is_base64(input[in_])) {
char_array_4[i++] = input[in_]; in_++;
while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
char_array_4[i++] = encoded_string[in_]; in_++;
if (i ==4) {
for (i = 0; i <4; i++) {
char_array_4[i] = static_cast<unsigned char>(base64_chars.find(char_array_4[i]));
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+2 -2
View File
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -204,7 +204,7 @@ namespace status {
/**
* See https://tools.ietf.org/html/rfc6455#section-7.4 for more details.
*
* @since 0.3.0
* @since 0.4.0-beta1
*
* @param [in] code The code to look up.
* @return A human readable interpretation of the code.
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+6 -32
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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,29 +40,12 @@
#define __has_extension __has_feature // Compatibility with pre-3.0 compilers.
#endif
// The code below attempts to use information provided by the build system or
// user supplied defines to selectively enable C++11 language and library
// features. In most cases features that are targeted individually may also be
// selectively disabled via an associated _WEBSOCKETPP_NOXXX_ define.
#if defined(_WEBSOCKETPP_CPP11_STL_) || __cplusplus >= 201103L || defined(_WEBSOCKETPP_CPP11_STRICT_)
// This check tests for blanket c++11 coverage. It can be activated in one
// of three ways. Either the compiler itself reports that it is a full
// C++11 compiler via the __cplusplus macro or the user/build system
// supplies one of the two preprocessor defines below:
// _WEBSOCKETPP_CPP11_STRICT_
//
// This define reports to WebSocket++ that 100% of the language and library
// features of C++11 are available. Using this define on a non-C++11
// compiler will result in problems.
// _WEBSOCKETPP_CPP11_STL_
//
// This define enables *most* C++11 options that were implemented early on
// by compilers. It is typically used for compilers that have many, but not
// all C++11 features. It should be safe to use on GCC 4.7-4.8 and perhaps
// earlier.
#if defined(_WEBSOCKETPP_CPP11_STL_) || __cplusplus >= 201103L
// _WEBSOCKETPP_CPP11_STL_ is a flag from the build system that forces
// WebSocket++ into C++11 mode. __cplusplus is a define set by the compiler
// if it has full support for C++11 language features. If either are set use
// C++11 language features
#ifndef _WEBSOCKETPP_NOEXCEPT_TOKEN_
#define _WEBSOCKETPP_NOEXCEPT_TOKEN_ noexcept
#endif
@@ -75,16 +58,7 @@
#ifndef _WEBSOCKETPP_NULLPTR_TOKEN_
#define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr
#endif
#ifndef __GNUC__
// GCC as of version 4.9 (latest) does not support std::put_time yet.
// so ignore it
#define _WEBSOCKETPP_PUTTIME_
#endif
#else
// In the absence of a blanket define, try to use compiler versions or
// feature testing macros to selectively enable what we can.
// Test for noexcept
#ifndef _WEBSOCKETPP_NOEXCEPT_TOKEN_
#ifdef _WEBSOCKETPP_NOEXCEPT_
+1 -24
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -39,11 +39,8 @@
#else
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/ref.hpp>
#endif
namespace websocketpp {
namespace lib {
@@ -52,18 +49,6 @@ namespace lib {
using std::bind;
using std::ref;
namespace placeholders = std::placeholders;
// There are some cases where a C++11 compiler balks at using std::ref
// but a C++03 compiler using boost function requires boost::ref. As such
// lib::ref is not useful in these cases. Instead this macro allows the use
// of boost::ref in the case of a boost compile or no reference wrapper at
// all in the case of a C++11 compile
#define _WEBSOCKETPP_REF(x) x
template <typename T>
void clear_function(T & x) {
x = nullptr;
}
#else
using boost::function;
using boost::bind;
@@ -73,14 +58,6 @@ namespace lib {
using ::_1;
using ::_2;
}
// See above definition for more details on what this is and why it exists
#define _WEBSOCKETPP_REF(x) boost::ref(x)
template <typename T>
void clear_function(T & x) {
x.clear();
}
#endif
} // namespace lib
+1 -4
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -38,7 +38,6 @@
#include <memory>
#else
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/scoped_array.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/pointer_cast.hpp>
@@ -52,7 +51,6 @@ namespace lib {
using std::weak_ptr;
using std::enable_shared_from_this;
using std::static_pointer_cast;
using std::make_shared;
typedef std::unique_ptr<unsigned char[]> unique_ptr_uchar_array;
#else
@@ -60,7 +58,6 @@ namespace lib {
using boost::weak_ptr;
using boost::enable_shared_from_this;
using boost::static_pointer_cast;
using boost::make_shared;
typedef boost::scoped_array<unsigned char> unique_ptr_uchar_array;
#endif
+4 -26
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -50,18 +50,7 @@ inline bool is_little_endian() {
#define TYP_SMLE 1
#define TYP_BIGE 2
/// Convert 64 bit value to network byte order
/**
* This method is prefixed to avoid conflicts with operating system level
* macros for this functionality.
*
* TODO: figure out if it would be beneficial to use operating system level
* macros for this.
*
* @param src The integer in host byte order
* @return src converted to network byte order
*/
inline uint64_t _htonll(uint64_t src) {
inline uint64_t htonll(uint64_t src) {
static int typ = TYP_INIT;
unsigned char c;
union {
@@ -82,19 +71,8 @@ inline uint64_t _htonll(uint64_t src) {
return x.ull;
}
/// Convert 64 bit value to host byte order
/**
* This method is prefixed to avoid conflicts with operating system level
* macros for this functionality.
*
* TODO: figure out if it would be beneficial to use operating system level
* macros for this.
*
* @param src The integer in network byte order
* @return src converted to host byte order
*/
inline uint64_t _ntohll(uint64_t src) {
return _htonll(src);
inline uint64_t ntohll(uint64_t src) {
return htonll(src);
}
} // net
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+3 -25
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -29,48 +29,26 @@
#define WEBSOCKETPP_CONCURRENCY_NONE_HPP
namespace websocketpp {
/// Concurrency handling support
namespace concurrency {
/// Implementation for no-op locking primitives
namespace none_impl {
/// A fake mutex implementation that does nothing
class fake_mutex {
public:
fake_mutex() {}
~fake_mutex() {}
};
/// A fake lock guard implementation that does nothing
class fake_lock_guard {
public:
explicit fake_lock_guard(fake_mutex) {}
explicit fake_lock_guard(fake_mutex foo) {}
~fake_lock_guard() {}
};
} // namespace none_impl
/// Stub concurrency policy that implements the interface using no-ops.
/**
* This policy documents the concurrency policy interface using no-ops. It can
* be used as a reference or base for building a new concurrency policy. It can
* also be used as is to disable all locking for endpoints used in purely single
* threaded programs.
*/
/// Stub Concurrency policy to remove locking in single threaded projects
class none {
public:
/// The type of a mutex primitive
/**
* std::mutex is an example.
*/
typedef none_impl::fake_mutex mutex_type;
/// The type of a scoped/RAII lock primitive.
/**
* The scoped lock constructor should take a mutex_type as a parameter,
* acquire that lock, and release it in its destructor. std::lock_guard is
* an example.
*/
typedef none_impl::fake_lock_guard scoped_lock_type;
};
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+5 -6
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -25,9 +25,9 @@
*
*/
// This header defines WebSocket++ macros for C++11 compatibility based on the
// Boost.Config library. This will correctly configure most target platforms
// simply by including this header before any other WebSocket++ header.
// This header defines WebSocket++ macros for C++11 compatibility based on the Boost.Config library.
// This will correctly configure most target platforms simply by including this header before
// any other WebSocket++ header.
#ifndef WEBSOCKETPP_CONFIG_BOOST_CONFIG_HPP
#define WEBSOCKETPP_CONFIG_BOOST_CONFIG_HPP
@@ -41,7 +41,7 @@
#define _WEBSOCKETPP_CPP11_FUNCTIONAL_
#endif
#ifdef BOOST_ASIO_HAS_STD_CHRONO
#ifndef BOOST_ASIO_HAS_STD_CHRONO
#define _WEBSOCKETPP_CPP11_CHRONO_
#endif
@@ -67,6 +67,5 @@
#define _WEBSOCKETPP_NOEXCEPT_TOKEN_ BOOST_NOEXCEPT
#define _WEBSOCKETPP_CONSTEXPR_TOKEN_ BOOST_CONSTEXPR
// TODO: nullptr support
#endif // WEBSOCKETPP_CONFIG_BOOST_CONFIG_HPP
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -223,7 +223,7 @@ struct core {
*
* The default is 32MB
*
* @since 0.3.0
* @since 0.4.0-alpha1
*/
static const size_t max_message_size = 32000000;
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -232,7 +232,7 @@ struct core_client {
*
* The default is 32MB
*
* @since 0.3.0
* @since 0.4.0-alpha1
*/
static const size_t max_message_size = 32000000;
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -224,7 +224,7 @@ struct debug_core {
*
* The default is 32MB
*
* @since 0.3.0
* @since 0.4.0-alpha1
*/
static const size_t max_message_size = 32000000;
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
-72
View File
@@ -1,72 +0,0 @@
/*
* 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:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef WEBSOCKETPP_CONFIG_MINIMAL_CLIENT_HPP
#define WEBSOCKETPP_CONFIG_MINIMAL_CLIENT_HPP
#include <websocketpp/config/minimal_server.hpp>
namespace websocketpp {
namespace config {
/// Client config with minimal dependencies
/**
* This config strips out as many dependencies as possible. It is suitable for
* use as a base class for custom configs that want to implement or choose their
* own policies for components that even the core config includes.
*
* NOTE: this config stubs out enough that it cannot be used directly. You must
* supply at least a transport policy and a cryptographically secure random
* number generation policy for a config based on `minimal_client` to do
* anything useful.
*
* Present dependency list for minimal_server config:
*
* C++98 STL:
* <algorithm>
* <map>
* <sstream>
* <string>
* <vector>
*
* C++11 STL or Boost
* <memory>
* <functional>
* <system_error>
*
* Operating System:
* <stdint.h> or <boost/cstdint.hpp>
* <netinet/in.h> or <winsock2.h> (for ntohl.. could potentially bundle this)
*
* @since 0.4.0-dev
*/
typedef minimal_server minimal_client;
} // namespace config
} // namespace websocketpp
#endif // WEBSOCKETPP_CONFIG_MINIMAL_CLIENT_HPP
-302
View File
@@ -1,302 +0,0 @@
/*
* 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:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef WEBSOCKETPP_CONFIG_MINIMAL_HPP
#define WEBSOCKETPP_CONFIG_MINIMAL_HPP
// Non-Policy common stuff
#include <websocketpp/common/platforms.hpp>
#include <websocketpp/common/cpp11.hpp>
#include <websocketpp/common/stdint.hpp>
// Concurrency
#include <websocketpp/concurrency/none.hpp>
// Transport
#include <websocketpp/transport/stub/endpoint.hpp>
// HTTP
#include <websocketpp/http/request.hpp>
#include <websocketpp/http/response.hpp>
// Messages
#include <websocketpp/message_buffer/message.hpp>
#include <websocketpp/message_buffer/alloc.hpp>
// Loggers
#include <websocketpp/logger/stub.hpp>
// RNG
#include <websocketpp/random/none.hpp>
// User stub base classes
#include <websocketpp/endpoint_base.hpp>
#include <websocketpp/connection_base.hpp>
// Extensions
#include <websocketpp/extensions/permessage_deflate/disabled.hpp>
namespace websocketpp {
namespace config {
/// Server config with minimal dependencies
/**
* This config strips out as many dependencies as possible. It is suitable for
* use as a base class for custom configs that want to implement or choose their
* own policies for components that even the core config includes.
*
* NOTE: this config stubs out enough that it cannot be used directly. You must
* supply at least a transport policy for a config based on `minimal_server` to
* do anything useful.
*
* Present dependency list for minimal_server config:
*
* C++98 STL:
* <algorithm>
* <map>
* <sstream>
* <string>
* <vector>
*
* C++11 STL or Boost
* <memory>
* <functional>
* <system_error>
*
* Operating System:
* <stdint.h> or <boost/cstdint.hpp>
* <netinet/in.h> or <winsock2.h> (for ntohl.. could potentially bundle this)
*
* @since 0.4.0-dev
*/
struct minimal_server {
typedef minimal_server type;
// Concurrency policy
typedef websocketpp::concurrency::none concurrency_type;
// HTTP Parser Policies
typedef http::parser::request request_type;
typedef http::parser::response response_type;
// Message Policies
typedef message_buffer::message<message_buffer::alloc::con_msg_manager>
message_type;
typedef message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef message_buffer::alloc::endpoint_msg_manager<con_msg_manager_type>
endpoint_msg_manager_type;
/// Logging policies
typedef websocketpp::log::stub<concurrency_type,
websocketpp::log::elevel> elog_type;
typedef websocketpp::log::stub<concurrency_type,
websocketpp::log::alevel> alog_type;
/// RNG policies
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
/// Controls compile time enabling/disabling of thread syncronization
/// code Disabling can provide a minor performance improvement to single
/// threaded applications
static bool const enable_multithreading = true;
struct transport_config {
typedef type::concurrency_type concurrency_type;
typedef type::elog_type elog_type;
typedef type::alog_type alog_type;
typedef type::request_type request_type;
typedef type::response_type response_type;
/// Controls compile time enabling/disabling of thread syncronization
/// code Disabling can provide a minor performance improvement to single
/// threaded applications
static bool const enable_multithreading = true;
/// Default timer values (in ms)
/// Length of time to wait for socket pre-initialization
/**
* Exactly what this includes depends on the socket policy in use
*/
static const long timeout_socket_pre_init = 5000;
/// Length of time to wait before a proxy handshake is aborted
static const long timeout_proxy = 5000;
/// Length of time to wait for socket post-initialization
/**
* Exactly what this includes depends on the socket policy in use.
* Often this means the TLS handshake
*/
static const long timeout_socket_post_init = 5000;
/// Length of time to wait for dns resolution
static const long timeout_dns_resolve = 5000;
/// Length of time to wait for TCP connect
static const long timeout_connect = 5000;
/// Length of time to wait for socket shutdown
static const long timeout_socket_shutdown = 5000;
};
/// Transport Endpoint Component
typedef websocketpp::transport::stub::endpoint<transport_config>
transport_type;
/// User overridable Endpoint base class
typedef websocketpp::endpoint_base endpoint_base;
/// User overridable Connection base class
typedef websocketpp::connection_base connection_base;
/// Default timer values (in ms)
/// Length of time before an opening handshake is aborted
static const long timeout_open_handshake = 5000;
/// Length of time before a closing handshake is aborted
static const long timeout_close_handshake = 5000;
/// Length of time to wait for a pong after a ping
static const long timeout_pong = 5000;
/// WebSocket Protocol version to use as a client
/**
* What version of the WebSocket Protocol to use for outgoing client
* connections. Setting this to a value other than 13 (RFC6455) is not
* recommended.
*/
static const int client_version = 13; // RFC6455
/// Default static error logging channels
/**
* Which error logging channels to enable at compile time. Channels not
* enabled here will be unable to be selected by programs using the library.
* This option gives an optimizing compiler the ability to remove entirely
* code to test whether or not to print out log messages on a certain
* channel
*
* Default is all except for development/debug level errors
*/
static const websocketpp::log::level elog_level =
websocketpp::log::elevel::none;
/// Default static access logging channels
/**
* Which access logging channels to enable at compile time. Channels not
* enabled here will be unable to be selected by programs using the library.
* This option gives an optimizing compiler the ability to remove entirely
* code to test whether or not to print out log messages on a certain
* channel
*
* Default is all except for development/debug level access messages
*/
static const websocketpp::log::level alog_level =
websocketpp::log::alevel::none;
///
static const size_t connection_read_buffer_size = 16384;
/// Drop connections immediately on protocol error.
/**
* Drop connections on protocol error rather than sending a close frame.
* Off by default. This may result in legit messages near the error being
* dropped as well. It may free up resources otherwise spent dealing with
* misbehaving clients.
*/
static const bool drop_on_protocol_error = false;
/// Suppresses the return of detailed connection close information
/**
* Silence close suppresses the return of detailed connection close
* information during the closing handshake. This information is useful
* for debugging and presenting useful errors to end users but may be
* undesirable for security reasons in some production environments.
* Close reasons could be used by an attacker to confirm that the endpoint
* is out of resources or be used to identify the WebSocket implementation
* in use.
*
* Note: this will suppress *all* close codes, including those explicitly
* sent by local applications.
*/
static const bool silent_close = false;
/// Default maximum message size
/**
* Default value for the processor's maximum message size. Maximum message size
* determines the point at which the library will fail a connection with the
* message_too_big protocol error.
*
* The default is 32MB
*
* @since 0.4.0-alpha1
*/
static const size_t max_message_size = 32000000;
/// Global flag for enabling/disabling extensions
static const bool enable_extensions = true;
/// Extension specific settings:
/// permessage_compress extension
struct permessage_deflate_config {
typedef core::request_type request_type;
/// If the remote endpoint requests that we reset the compression
/// context after each message should we honor the request?
static const bool allow_disabling_context_takeover = true;
/// If the remote endpoint requests that we reduce the size of the
/// LZ77 sliding window size this is the lowest value that will be
/// allowed. Values range from 8 to 15. A value of 8 means we will
/// allow any possible window size. A value of 15 means do not allow
/// negotiation of the window size (ie require the default).
static const uint8_t minimum_outgoing_window_bits = 8;
};
typedef websocketpp::extensions::permessage_deflate::disabled
<permessage_deflate_config> permessage_deflate_type;
/// Autonegotiate permessage-deflate
/**
* Automatically enables the permessage-deflate extension.
*
* For clients this results in a permessage-deflate extension request being
* sent with every request rather than requiring it to be requested manually
*
* For servers this results in accepting the first set of extension settings
* requested by the client that we understand being used. The alternative is
* requiring the extension to be manually negotiated in `validate`. With
* auto-negotiate on, you may still override the auto-negotiate manually if
* needed.
*/
//static const bool autonegotiate_compression = false;
};
} // namespace config
} // namespace websocketpp
#endif // WEBSOCKETPP_CONFIG_MINIMAL_HPP
+2 -2
View File
@@ -538,7 +538,7 @@ public:
*
* The default is set by the endpoint that creates the connection.
*
* @since 0.3.0
* @since 0.4.0-alpha1
*/
size_t get_max_message_size() const {
return m_max_message_size;
@@ -552,7 +552,7 @@ public:
*
* The default is set by the endpoint that creates the connection.
*
* @since 0.3.0
* @since 0.4.0-alpha1
*
* @param new_value The value to set as the maximum message size.
*/
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+7 -6
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -32,6 +32,7 @@
#include <websocketpp/logger/levels.hpp>
#include <websocketpp/version.hpp>
#include <iostream>
#include <set>
namespace websocketpp {
@@ -87,8 +88,8 @@ public:
typedef lib::shared_ptr<connection_weak_ptr> hdl_type;
explicit endpoint(bool p_is_server)
: m_alog(config::alog_level, log::channel_type_hint::access)
, m_elog(config::elog_level, log::channel_type_hint::error)
: m_alog(config::alog_level, &std::cout)
, m_elog(config::elog_level, &std::cerr)
, m_user_agent(::websocketpp::user_agent)
, m_open_handshake_timeout_dur(config::timeout_open_handshake)
, m_close_handshake_timeout_dur(config::timeout_close_handshake)
@@ -356,7 +357,7 @@ public:
*
* The default is set by the max_message_size value from the template config
*
* @since 0.3.0
* @since 0.4.0-alpha1
*/
size_t get_max_message_size() const {
return m_max_message_size;
@@ -370,7 +371,7 @@ public:
*
* The default is set by the max_message_size value from the template config
*
* @since 0.3.0
* @since 0.4.0-alpha1
*
* @param new_value The value to set as the maximum message size.
*/
@@ -537,7 +538,7 @@ public:
lib::error_code ec;
connection_ptr con = this->get_con_from_hdl(hdl,ec);
if (ec) {
throw exception(ec);
throw ec;
}
return con;
}
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
+10 -20
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -38,7 +38,7 @@ namespace websocketpp {
/// Combination error code / string type for returning two values
typedef std::pair<lib::error_code,std::string> err_str_pair;
/// Library level error codes
// setup for errors that should be propogated back to the user.
namespace error {
enum value {
/// Catch-all library error
@@ -86,8 +86,7 @@ enum value {
/// Invalid subprotocol
invalid_subprotocol,
/// An operation was attempted on a connection that did not exist or was
/// already deleted.
/// Bad or unknown connection
bad_connection,
/// Unit testing utility error code
@@ -116,11 +115,11 @@ enum value {
/// Invalid port in URI
invalid_port,
/// An async accept operation failed because the underlying transport has been
/// requested to not listen for new connections anymore.
async_accept_not_listening,
/// The requested operation was canceled
operation_canceled
}; // enum value
@@ -217,30 +216,21 @@ namespace websocketpp {
class exception : public std::exception {
public:
exception(std::string const & msg, lib::error_code ec = make_error_code(error::general))
: m_msg(msg), m_code(ec)
{}
explicit exception(lib::error_code ec)
: m_code(ec)
{}
exception(std::string const & msg, error::value p_code = error::general)
: m_msg(msg), m_code(p_code) {}
~exception() throw() {}
virtual char const * what() const throw() {
if (m_msg.empty()) {
return m_code.message().c_str();
} else {
return m_msg.c_str();
}
return m_msg.c_str();
}
lib::error_code code() const throw() {
error::value code() const throw() {
return m_code;
}
std::string m_msg;
lib::error_code m_code;
error::value m_code;
};
} // namespace websocketpp
+24 -24
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2012, 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:
@@ -36,34 +36,34 @@ namespace websocketpp {
*/
class error_msg {
public:
const std::string& get_msg() const {
return m_error_msg;
}
const std::string& get_msg() const {
return m_error_msg;
}
void set_msg(const std::string& msg) {
m_error_msg = msg;
}
void set_msg(const std::string& msg) {
m_error_msg = msg;
}
void append_msg(const std::string& msg) {
m_error_msg.append(msg);
}
void append_msg(const std::string& msg) {
m_error_msg.append(msg);
}
template <typename T>
void set_msg(const T& thing) {
std::stringsteam val;
val << thing;
this->set_msg(val.str());
}
template <typename T>
void set_msg(const T& thing) {
std::stringsteam val;
val << thing;
this->set_msg(val.str());
}
template <typename T>
void append_msg(const T& thing) {
std::stringsteam val;
val << thing;
this->append_msg(val.str());
}
template <typename T>
void append_msg(const T& thing) {
std::stringsteam val;
val << thing;
this->append_msg(val.str());
}
private:
// error resources
std::string m_error_msg;
// error resources
std::string m_error_msg;
};
} // namespace websocketpp
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -53,15 +53,7 @@ class disabled {
typedef std::pair<lib::error_code,std::string> err_str_pair;
public:
/// Negotiate extension
/**
* The disabled extension always fails the negotiation with a disabled
* error.
*
* @param offer Attribute from client's offer
* @return Status code and value to return to remote endpoint
*/
err_str_pair negotiate(http::attribute_list const &) {
err_str_pair negotiate(http::attribute_list const & attributes) {
return make_pair(make_error_code(error::disabled),std::string());
}
@@ -77,24 +69,17 @@ public:
return false;
}
/// Compress bytes
/**
* @param [in] in String to compress
* @param [out] out String to append compressed bytes to
* @return Error or status code
*/
lib::error_code compress(std::string const &, std::string &) {
lib::error_code compress(std::string const & in, std::string & out) {
return make_error_code(error::disabled);
}
/// Decompress bytes
/**
* @param buf Byte buffer to decompress
* @param len Length of buf
* @param out String to append decompressed bytes to
* @return Error or status code
*/
lib::error_code decompress(uint8_t const *, size_t, std::string &) {
lib::error_code decompress(uint8_t const * buf, size_t len,
std::string & out)
{
return make_error_code(error::disabled);
}
lib::error_code decompress(std::string const & in, std::string & out) {
return make_error_code(error::disabled);
}
};
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2013, 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:
@@ -434,7 +434,7 @@ public:
* @param response The server response attribute list to validate
* @return Validation error or 0 on success
*/
lib::error_code validate_offer(http::attribute_list const &) {
lib::error_code validate_offer(http::attribute_list const & response) {
return make_error_code(error::general);
}
@@ -643,7 +643,7 @@ private:
m_s2c_max_window_bits = bits;
break;
case mode::largest:
m_s2c_max_window_bits = (std::min)(bits,m_s2c_max_window_bits);
m_s2c_max_window_bits = std::min(bits,m_s2c_max_window_bits);
break;
case mode::smallest:
m_s2c_max_window_bits = min_s2c_max_window_bits;

Some files were not shown because too many files have changed in this diff Show More