adds namespace to network utilities, fixes #80

This commit is contained in:
Peter Thorson
2012-03-08 08:29:50 -06:00
parent a11e66d3f5
commit 1d9e0caeb6
5 changed files with 22 additions and 14 deletions

View File

@@ -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(),

View File

@@ -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";

View File

@@ -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

View File

@@ -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<uint64_t*>(&m_header[BASIC_HEADER_LENGTH])) = htonll(size);
*(reinterpret_cast<uint64_t*>(&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<uint16_t*>(&m_header[BASIC_HEADER_LENGTH])
));
reinterpret_cast<uint16_t*>(&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<uint64_t*>(&m_header[BASIC_HEADER_LENGTH])
));
m_payload_size = zsutil::ntohll(*(
reinterpret_cast<uint64_t*>(&m_header[BASIC_HEADER_LENGTH])
));
if (m_payload_size <= frame::limits::PAYLOAD_SIZE_EXTENDED) {
throw processor::exception("payload length not minimally encoded",

View File

@@ -397,7 +397,7 @@ public:
*reinterpret_cast<uint16_t*>(&m_header[BASIC_HEADER_LENGTH]) = htons(s);
} else if (s <= limits::PAYLOAD_SIZE_JUMBO) {
m_header[1] = BASIC_PAYLOAD_64BIT_CODE;
*reinterpret_cast<uint64_t*>(&m_header[BASIC_HEADER_LENGTH]) = htonll(s);
*reinterpret_cast<uint64_t*>(&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<uint64_t*>(&m_header[BASIC_HEADER_LENGTH])
));