From f506c185a89061e8e5d45224c19b52b341e3321a Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Thu, 8 Mar 2012 07:55:41 -0600 Subject: [PATCH 1/3] fixes or silences some VCPP warnings --- examples/wsperf/generic.hpp | 15 ++++++++------- src/roles/client.hpp | 6 ++++++ src/roles/server.hpp | 6 ++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/examples/wsperf/generic.hpp b/examples/wsperf/generic.hpp index 0b86a7f288..88ab45d4c1 100644 --- a/examples/wsperf/generic.hpp +++ b/examples/wsperf/generic.hpp @@ -38,7 +38,6 @@ enum correctness_mode { LENGTH = 1 }; -// test class for 9.1.* and 9.2.* class message_test : public case_handler { public: message_test(uint64_t message_size, @@ -75,7 +74,7 @@ public: m_rtts = extract_bool(cmd,"rtts"); // specific to message_test - m_message_count = extract_number(cmd,"size"); + m_message_count = extract_number(cmd,"size"); m_message_size = extract_number(cmd,"count"); m_timeout = extract_number(cmd,"timeout"); @@ -94,13 +93,13 @@ public: void on_open(connection_ptr con) { m_msg = con->get_data_message(); - m_data.reserve(m_message_size); + m_data.reserve(static_cast(m_message_size)); if (!m_binary) { - fill_utf8(m_data,m_message_size,true); + fill_utf8(m_data,static_cast(m_message_size),true); m_msg->reset(websocketpp::frame::opcode::TEXT); } else { - fill_binary(m_data,m_message_size,true); + fill_binary(m_data,static_cast(m_message_size),true); m_msg->reset(websocketpp::frame::opcode::BINARY); } @@ -118,7 +117,9 @@ public: } void on_message(connection_ptr con,websocketpp::message::data_ptr msg) { - if ((m_mode == LENGTH && msg->get_payload().size() == m_data.size()) || (m_mode == EXACT && msg->get_payload() == m_data)) { + if ((m_mode == LENGTH && msg->get_payload().size() == m_data.size()) || + (m_mode == EXACT && msg->get_payload() == m_data)) + { m_acks++; m_bytes += m_message_size; mark(); @@ -142,7 +143,7 @@ public: } private: // Simulation Parameters - size_t m_message_size; + uint64_t m_message_size; uint64_t m_message_count; uint64_t m_timeout; bool m_binary; diff --git a/src/roles/client.hpp b/src/roles/client.hpp index 68dbe0d3e4..883a848a9d 100644 --- a/src/roles/client.hpp +++ b/src/roles/client.hpp @@ -45,6 +45,12 @@ #include +#ifdef _MSC_VER +// Disable "warning C4355: 'this' : used in base member initializer list". +# pragma warning(push) +# pragma warning(disable:4355) +#endif + using boost::asio::ip::tcp; namespace websocketpp { diff --git a/src/roles/server.hpp b/src/roles/server.hpp index 3eb8f78b85..56ecfc8078 100644 --- a/src/roles/server.hpp +++ b/src/roles/server.hpp @@ -44,6 +44,12 @@ #include #include +#ifdef _MSC_VER +// Disable "warning C4355: 'this' : used in base member initializer list". +# pragma warning(push) +# pragma warning(disable:4355) +#endif + namespace websocketpp { // Forward declarations From a11e66d3f55b5e35a01f60fcb621a55dd8612abd Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Thu, 8 Mar 2012 07:56:58 -0600 Subject: [PATCH 2/3] scons updates --- SConstruct | 121 ++++++++++++++++++++++---- websocketpp.xcodeproj/project.pbxproj | 2 + 2 files changed, 108 insertions(+), 15 deletions(-) diff --git a/SConstruct b/SConstruct index 7045798332..e07ccbb672 100644 --- a/SConstruct +++ b/SConstruct @@ -7,24 +7,115 @@ #env = Environment(PREFIX = GetOption('prefix')) -env = Environment() # Initialize the environment +import os, sys +env = Environment(ENV = os.environ) + +## Boost +## +## Note: You need to either set BOOSTROOT to the root of a stock Boost distribution +## or set BOOST_INCLUDES and BOOST_LIBS if Boost comes with your OS distro e.g. and +## needs BOOST_INCLUDES=/usr/include/boost and BOOST_LIBS=/usr/lib like Ubuntu. +## +if os.environ.has_key('BOOSTROOT'): + env['BOOST_INCLUDES'] = os.environ['BOOSTROOT'] + env['BOOST_LIBS'] = os.path.join(os.environ['BOOSTROOT'], 'stage', 'lib') +elif os.environ.has_key('BOOST_INCLUDES') and os.environ.has_key('BOOST_LIBS'): + env['BOOST_INCLUDES'] = os.environ['BOOST_INCLUDES'] + env['BOOST_LIBS'] = os.environ['BOOST_LIBS'] +else: + raise SCons.Errors.UserError, "Neither BOOSTROOT, nor BOOST_INCLUDES + BOOST_LIBS was set!" + +env.Append(CPPPATH = [env['BOOST_INCLUDES']]) +env.Append(LIBPATH = [env['BOOST_LIBS']]) + +boost_linkshared = False + +def boostlibs(libnames): + if env['PLATFORM'].startswith('win'): + # Win/VC++ supports autolinking. nothing to do. + # http://www.boost.org/doc/libs/1_49_0/more/getting_started/windows.html#auto-linking + return [] + else: + libs = [] + prefix = env['SHLIBPREFIX'] if boost_linkshared else env['LIBPREFIX'] + suffix = env['SHLIBSUFFIX'] if boost_linkshared else env['LIBSUFFIX'] + for name in libnames: + lib = File(os.path.join(env['BOOST_LIBS'], '%sboost_%s%s' % (prefix, name, suffix))) + libs.append(lib) + return libs + + +if env['PLATFORM'].startswith('win'): + env.Append(CPPDEFINES = ['WIN32', 'NDEBUG', '_CONSOLE', '_WEBSOCKETPP_CPP11_FRIEND_']) + arch_flags = '/arch:SSE2' + opt_flags = '/Ox /Oi /fp:fast' + warn_flags = '/W3 /wd4996 /wd4995 /wd4355' + env['CCFLAGS'] = '%s /EHsc /GR /GS- /MD /nologo %s %s' % (warn_flags, arch_flags, opt_flags) + env['LINKFLAGS'] = '/INCREMENTAL:NO /MANIFEST /NOLOGO /OPT:REF /OPT:ICF /MACHINE:X86' + env.VariantDir("release/", "src/"); -lib_sources = ["base64/base64.cpp","md5/md5.c","messages/data.cpp","network_utilities.cpp","processors/hybi_header.cpp","sha1/sha1.cpp","uri.cpp"] -lib_path = ['/usr/lib','/usr/local/lib','#/release'] +if env['PLATFORM'].startswith('win'): + lib_path = env['BOOST_LIBS'] +else: + lib_path = ['/usr/lib', + '/usr/local/lib', + env['BOOST_LIBS'], + '#/release'] -static_lib=env.StaticLibrary(target = 'release/websocketpp', source = lib_sources, srcdir="release") -shared_lib=env.SharedLibrary(target = 'release/websocketpp', source = lib_sources, srcdir="release",LIBS=['boost_regex'],LIBPATH=lib_path) - -# Echo Server -env.VariantDir("#/release/echo_server","examples/echo_server") -env.Program(target="#/release/echo_server/echo_server",srcdir="#/release/echo_server/",source=["echo_server.cpp"],LIBS=[shared_lib,'boost_system','boost_date_time','boost_regex','boost_thread','pthread'],LIBPATH=lib_path) - -lib_rt = '' +platform_libs = [] if env['PLATFORM'] == 'posix': - lib_rt = 'rt' + platform_libs = ['pthread', 'rt'] +elif env['PLATFORM'].startswith('win'): + # Win/VC++ supports autolinking. nothing to do. + pass -# Echo Server -env.VariantDir("#/release/wsperf","examples/wsperf") -env.Program(target="#/release/wsperf/wsperf",srcdir="#/release/wsperf/",source=["wsperf.cpp","request.cpp","case.cpp","generic.cpp"],LIBS=[shared_lib,'boost_system','boost_date_time','boost_regex','boost_thread','pthread',lib_rt,'boost_random','boost_chrono','boost_program_options'],LIBPATH=lib_path) \ No newline at end of file +#### END OF GLOBAL CONF ######################################################## + +## WebSocket++ library +## +lib_sources = ["base64/base64.cpp", + "md5/md5.c", + "messages/data.cpp", + "network_utilities.cpp", + "processors/hybi_header.cpp", + "sha1/sha1.cpp", + "uri.cpp"] + +static_lib = env.StaticLibrary(target = 'release/websocketpp', + source = lib_sources, + srcdir = "release") +#shared_lib=env.SharedLibrary(target = 'release/websocketpp', source = lib_sources, srcdir="release",LIBS=['boost_regex'],LIBPATH=lib_path) + +wslib = static_lib + +## Echo Server +## +env.VariantDir("#/release/echo_server", "examples/echo_server") +env.Program(target = "#/release/echo_server/echo_server", + srcdir = "#/release/echo_server/", + source = ["echo_server.cpp"], + LIBS = [wslib, platform_libs] + boostlibs(['system', + 'date_time', + 'regex', + 'thread']), + LIBPATH = lib_path) + +## wsperf +## +env.VariantDir("#/release/wsperf", "examples/wsperf") +env.Program(target = "#/release/wsperf/wsperf", + srcdir = "#/release/wsperf/", + source = ["wsperf.cpp", + "request.cpp", + "case.cpp", + "generic.cpp"], + LIBS = [wslib, platform_libs] + boostlibs(['system', + 'date_time', + 'regex', + 'thread', + 'random', + 'chrono', + 'program_options']), + LIBPATH = lib_path) \ No newline at end of file diff --git a/websocketpp.xcodeproj/project.pbxproj b/websocketpp.xcodeproj/project.pbxproj index 9f9bcff609..c2c49f7059 100644 --- a/websocketpp.xcodeproj/project.pbxproj +++ b/websocketpp.xcodeproj/project.pbxproj @@ -372,6 +372,7 @@ B6E56D6F150457B8007E1707 /* wscmd.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = wscmd.hpp; path = examples/wsperf/wscmd.hpp; sourceTree = ""; }; B6E56D7E150644A3007E1707 /* request.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = request.cpp; path = examples/wsperf/request.cpp; sourceTree = ""; }; B6E56D7F150644A3007E1707 /* request.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = request.hpp; path = examples/wsperf/request.hpp; sourceTree = ""; }; + B6E56D821508EACA007E1707 /* SConstruct */ = {isa = PBXFileReference; lastKnownFileType = text; path = SConstruct; sourceTree = ""; }; B6E7E7731505532E00394909 /* wsperf */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = wsperf; sourceTree = BUILT_PRODUCTS_DIR; }; B6E7E78A150553D000394909 /* libboost_chrono.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libboost_chrono.dylib; path = usr/local/lib/libboost_chrono.dylib; sourceTree = SDKROOT; }; B6FE8CE2144DE17F00B32547 /* readme.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = readme.txt; sourceTree = ""; }; @@ -749,6 +750,7 @@ B6DF1CC51435ECE40029A1B1 /* libraries */, B6138791145CA6F700ED9B19 /* Makefile */, B6DE901314C4D875009A1591 /* readme.txt */, + B6E56D821508EACA007E1707 /* SConstruct */, B64E12D014BDE132006F20F0 /* test */, B6DF1C7F1434ABB70029A1B1 /* src */, B6DF1C6A1434A7A30029A1B1 /* Products */, From 1d9e0caeb66950d73abe0c18ce9808d493c28be0 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Thu, 8 Mar 2012 08:29:50 -0600 Subject: [PATCH 3/3] adds namespace to network utilities, fixes #80 --- src/connection.hpp | 2 +- src/network_utilities.cpp | 12 ++++++++---- src/network_utilities.hpp | 4 ++++ src/processors/hybi_header.cpp | 14 +++++++------- src/websocket_frame.hpp | 4 ++-- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/connection.hpp b/src/connection.hpp index 4a14d054a1..17b3131407 100644 --- a/src/connection.hpp +++ b/src/connection.hpp @@ -578,7 +578,7 @@ public: m_write_buf.push_back(boost::asio::buffer(m_write_queue.front()->get_header())); m_write_buf.push_back(boost::asio::buffer(m_write_queue.front()->get_payload())); - m_endpoint.alog().at(log::alevel::DEVEL) << "write header: " << to_hex(m_write_queue.front()->get_header()) << log::endl; + m_endpoint.alog().at(log::alevel::DEVEL) << "write header: " << zsutil::to_hex(m_write_queue.front()->get_header()) << log::endl; boost::asio::async_write( socket_type::get_socket(), diff --git a/src/network_utilities.cpp b/src/network_utilities.cpp index f5ea279a1c..30cc9f9166 100644 --- a/src/network_utilities.cpp +++ b/src/network_utilities.cpp @@ -27,7 +27,9 @@ #include "network_utilities.hpp" -uint64_t htonll(uint64_t src) { + + +uint64_t zsutil::htonll(uint64_t src) { static int typ = TYP_INIT; unsigned char c; union { @@ -48,11 +50,11 @@ uint64_t htonll(uint64_t src) { return x.ull; } -uint64_t ntohll(uint64_t src) { +uint64_t zsutil::ntohll(uint64_t src) { return htonll(src); } -std::string lookup_ws_close_status_string(uint16_t code) { +std::string zsutil::lookup_ws_close_status_string(uint16_t code) { switch (code) { case 1000: return "Normal closure"; @@ -76,12 +78,14 @@ std::string lookup_ws_close_status_string(uint16_t code) { return "Message too large"; case 1010: return "Missing required extensions"; + case 1011: + return "Internal server error"; default: return "Unknown"; } } -std::string to_hex(const std::string& input) { +std::string zsutil::to_hex(const std::string& input) { std::string output; std::string hex = "0123456789ABCDEF"; diff --git a/src/network_utilities.hpp b/src/network_utilities.hpp index 7d247502e9..465fb14a3d 100644 --- a/src/network_utilities.hpp +++ b/src/network_utilities.hpp @@ -35,6 +35,8 @@ // TODO: impliment stuff from here: // http://stackoverflow.com/questions/809902/64-bit-ntohl-in-c +namespace zsutil { + #define TYP_INIT 0 #define TYP_SMLE 1 #define TYP_BIGE 2 @@ -46,4 +48,6 @@ std::string lookup_ws_close_status_string(uint16_t code); std::string to_hex(const std::string& input); +} // namespace zsutil + #endif // NETWORK_UTILITIES_HPP diff --git a/src/processors/hybi_header.cpp b/src/processors/hybi_header.cpp index 49a89888df..053f75a489 100644 --- a/src/processors/hybi_header.cpp +++ b/src/processors/hybi_header.cpp @@ -76,7 +76,7 @@ void hybi_header::consume(std::istream& input) { default: break; } - //std::cout << "header so far: " << to_hex(std::string(m_header,MAX_HEADER_LENGTH)) << std::endl; + //std::cout << "header so far: " << zsutil::to_hex(std::string(m_header,MAX_HEADER_LENGTH)) << std::endl; } uint64_t hybi_header::get_bytes_needed() const { return m_bytes_needed; @@ -136,7 +136,7 @@ void hybi_header::set_payload_size(uint64_t size) { m_header[1] |= BASIC_PAYLOAD_64BIT_CODE; } m_payload_size = size; - *(reinterpret_cast(&m_header[BASIC_HEADER_LENGTH])) = htonll(size); + *(reinterpret_cast(&m_header[BASIC_HEADER_LENGTH])) = zsutil::htonll(size); } else { throw processor::exception("set_payload_size called with value that was too large (>2^63)",processor::error::MESSAGE_TOO_BIG); } @@ -245,8 +245,8 @@ void hybi_header::process_extended_header() { // reinterpret the second two bytes as a 16 bit integer in network // byte order. Convert to host byte order and store locally. m_payload_size = ntohs(*( - reinterpret_cast(&m_header[BASIC_HEADER_LENGTH]) - )); + reinterpret_cast(&m_header[BASIC_HEADER_LENGTH]) + )); if (m_payload_size < s) { std::stringstream err; @@ -257,9 +257,9 @@ void hybi_header::process_extended_header() { } else if (s == BASIC_PAYLOAD_64BIT_CODE) { // reinterpret the second eight bytes as a 64 bit integer in // network byte order. Convert to host byte order and store. - m_payload_size = ntohll(*( - reinterpret_cast(&m_header[BASIC_HEADER_LENGTH]) - )); + m_payload_size = zsutil::ntohll(*( + reinterpret_cast(&m_header[BASIC_HEADER_LENGTH]) + )); if (m_payload_size <= frame::limits::PAYLOAD_SIZE_EXTENDED) { throw processor::exception("payload length not minimally encoded", diff --git a/src/websocket_frame.hpp b/src/websocket_frame.hpp index 86c3a6219d..3c39f620ca 100644 --- a/src/websocket_frame.hpp +++ b/src/websocket_frame.hpp @@ -397,7 +397,7 @@ public: *reinterpret_cast(&m_header[BASIC_HEADER_LENGTH]) = htons(s); } else if (s <= limits::PAYLOAD_SIZE_JUMBO) { m_header[1] = BASIC_PAYLOAD_64BIT_CODE; - *reinterpret_cast(&m_header[BASIC_HEADER_LENGTH]) = htonll(s); + *reinterpret_cast(&m_header[BASIC_HEADER_LENGTH]) = zsutil::htonll(s); } else { throw processor::exception("payload size limit is 63 bits",processor::error::PROTOCOL_VIOLATION); } @@ -498,7 +498,7 @@ public: } else if (s == BASIC_PAYLOAD_64BIT_CODE) { // reinterpret the second eight bytes as a 64 bit integer in // network byte order. Convert to host byte order and store. - payload_size = ntohll(*( + payload_size = zsutil::ntohll(*( reinterpret_cast(&m_header[BASIC_HEADER_LENGTH]) ));