Skip to content

Commit

Permalink
prefix htonll/ntohll fixes #381 fixes #382 references #358
Browse files Browse the repository at this point in the history
This avoids conflicts with OS level macros
  • Loading branch information
Peter Thorson committed Oct 14, 2014
1 parent 55b6cfa commit 2e7a902
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
26 changes: 17 additions & 9 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
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
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

Expand Down
4 changes: 2 additions & 2 deletions test/utility/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) );
Expand All @@ -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) );
Expand Down
30 changes: 26 additions & 4 deletions websocketpp/common/network.hpp
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions websocketpp/frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ struct extended_header {
}

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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2e7a902

Please sign in to comment.