From 2e7a902ef7116c5a93c32d5c5bcc9e77797eadf9 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Tue, 14 Oct 2014 08:08:30 -0400 Subject: [PATCH] prefix htonll/ntohll fixes #381 fixes #382 references #358 This avoids conflicts with OS level macros --- changelog.md | 26 +++++++++++++++++--------- test/utility/frame.cpp | 4 ++-- websocketpp/common/network.hpp | 30 ++++++++++++++++++++++++++---- websocketpp/frame.hpp | 4 ++-- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/changelog.md b/changelog.md index 87c3f5dafb..d79b6100d3 100644 --- a/changelog.md +++ b/changelog.md @@ -1,20 +1,25 @@ HEAD -- BREAKING API CHANGE: All WebSocket++ methods now throw an exception of type +- 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. -- API BREAKING 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 +- 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. -- 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 +- 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. +- 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. +- 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. - Compatibility: Adjust usage of std::min to be more compatible with systems @@ -22,6 +27,9 @@ HEAD - 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 diff --git a/test/utility/frame.cpp b/test/utility/frame.cpp index 5da9d2e22e..879c2ef4be 100644 --- a/test/utility/frame.cpp +++ b/test/utility/frame.cpp @@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE( prepare_masking_key ) { if (sizeof(size_t) == 8) { BOOST_CHECK( - frame::prepare_masking_key(key) == lib::net::htonll(0x1234567812345678LL) + frame::prepare_masking_key(key) == lib::net::_htonll(0x1234567812345678LL) ); } else { BOOST_CHECK( frame::prepare_masking_key(key) == htonl(0x12345678) ); @@ -255,7 +255,7 @@ BOOST_AUTO_TEST_CASE( prepare_masking_key2 ) { // One call if (sizeof(size_t) == 8) { BOOST_CHECK( - frame::prepare_masking_key(key) == lib::net::htonll(0xD5FB70EED5FB70EELL) + frame::prepare_masking_key(key) == lib::net::_htonll(0xD5FB70EED5FB70EELL) ); } else { BOOST_CHECK( frame::prepare_masking_key(key) == htonl(0xD5FB70EE) ); diff --git a/websocketpp/common/network.hpp b/websocketpp/common/network.hpp index 9ba8b538bc..ac90644086 100644 --- a/websocketpp/common/network.hpp +++ b/websocketpp/common/network.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Peter Thorson. All rights reserved. + * Copyright (c) 2014, Peter Thorson. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -50,7 +50,18 @@ inline bool is_little_endian() { #define TYP_SMLE 1 #define TYP_BIGE 2 -inline uint64_t htonll(uint64_t src) { +/// 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) { static int typ = TYP_INIT; unsigned char c; union { @@ -71,8 +82,19 @@ inline uint64_t htonll(uint64_t src) { return x.ull; } -inline uint64_t ntohll(uint64_t src) { - return htonll(src); +/// 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); } } // net diff --git a/websocketpp/frame.hpp b/websocketpp/frame.hpp index 85792cfa20..c71f70c2a5 100644 --- a/websocketpp/frame.hpp +++ b/websocketpp/frame.hpp @@ -266,7 +266,7 @@ private: } uint64_converter temp64; - temp64.i = lib::net::htonll(payload_size); + temp64.i = lib::net::_htonll(payload_size); std::copy(temp64.c+payload_offset,temp64.c+8,bytes); return 8-payload_offset; @@ -554,7 +554,7 @@ inline uint16_t get_extended_size(const extended_header &e) { inline uint64_t get_jumbo_size(const extended_header &e) { uint64_converter temp64; std::copy(e.bytes,e.bytes+8,temp64.c); - return lib::net::ntohll(temp64.i); + return lib::net::_ntohll(temp64.i); } /// Extract the full payload size field from a WebSocket header