Compare commits

...

13 Commits

Author SHA1 Message Date
Peter Thorson c1161f859b Merge pull request #316 from MortimerGoro/0.2.x
ARM requires 8-byte alignment for 64-bit variables. The reinterpret_cast...
2014-01-25 14:44:27 -08:00
Imanol Fernandez ae49a83c64 get rid of some reinterpret_cast operators to avoid memory alignment issues 2014-01-17 11:01:26 +01:00
Imanol Fernandez 528a91ff7f ARM requires 8-byte alignment for 64-bit variables. The reinterpret_cast<uint64_t*> is not 8-byte memory aligned so it causes crashes on some ARM devices, specially on Android. 2014-01-16 17:23:44 +01:00
Peter Thorson d645ccc36f bump version number 2013-06-08 09:20:45 -05:00
Peter Thorson cd2bab2ec5 adds travis settings to ignore 0.2.x branch 2013-06-08 09:00:54 -05:00
Peter Thorson 71300f047b removes use of uint64_t* references #223 2013-06-08 08:58:25 -05:00
Peter Thorson e96edc8cc4 Adds missing boost header 2013-06-08 08:57:48 -05:00
Peter Thorson 1cfa069dab typo 2013-04-22 17:14:55 -05:00
Peter Thorson 7d60ad5849 changes readme to markdown 2013-04-22 17:14:30 -05:00
Peter Thorson 3e8195588f updates readme for legacy 0.2.x branch 2013-04-22 17:13:37 -05:00
Peter Thorson a6d2c325b1 Updates readme with updated project status 2013-03-19 11:42:48 -05:00
Peter Thorson 6c8908f493 Merge pull request #173 from zarnce/master
Added interface for sending generic array and length. A similar interface is now available in the 0.3.x branch as well.
2013-02-01 05:27:09 -08:00
bmehaffey a10b3a1704 Brian - Adding interface for sending messages.
- Added interface for sending an array and length for sending messages.
2012-12-31 13:54:49 -06:00
9 changed files with 127 additions and 28 deletions
+20
View File
@@ -0,0 +1,20 @@
language: cpp
compiler:
- gcc
before_install:
- sudo apt-get install libboost-regex1.48-dev libboost-system1.48-dev libboost-thread1.48-dev libboost-test1.48-dev libboost-random1.48-dev -y
env:
global:
- BOOST_INCLUDES=/usr/include
- BOOST_LIBS=/usr/lib
script: scons -j 2 && scons test
branches:
only:
- experimental
- 0.3.x-cmake
notifications:
recipients:
- travis@zaphoyd.com
email:
on_success: change
on_failure: always
+30
View File
@@ -0,0 +1,30 @@
**WARNING: LEGACY VERSION**
NOTE: This is the 0.2.x version of WebSocket++. There some fairly significant
API changes in 0.3.x so upgrading should be done carefully. Due to these
changes, a snapshot of the last 0.2.x version will be tagged in the master
branch and retained in the 0.2.x branch for any 0.2 user's convenience. The
0.2.x branch may be updated if any particularly problematic issues are found.
The 0.3.x+ line is the preferred code for any new development. 0.3.x can be
found in the 'Experimental' branch on GitHub. In the near future it will be
promoted to the master branch.
--------------------------------------------------------------------------------
WebSocket++ is a C++ library that impliments RFC6455, the WebSocket protocol.
It can be used to build applications that feature WebSocket functionality.
For more information, please visit: http://www.zaphoyd.com/websocketpp/
0.2.x Features:
* Fully supports RFC6455 protocol
* Partial support for Hixie draft 76 and Hybi drafts 7-17
* Easy to use message/event based API
* Boost ASIO based asynchronous network core
* Supports secure WebSockets (TLS) and IPv6
* Fully passes the AutoBahn 0.4.10 test suite
* Includes WebSocket performance and stress testing tools
* Open-source (BSD license)
-15
View File
@@ -1,15 +0,0 @@
WebSocket++ is a full featured C++/Boost ASIO implimentation of RFC6455, the
WebSocket protocol which can be used to build applications that feature
WebSocket client and server functionality.
* Fully supports RFC6455 protocol
* Partial support for Hixie draft 76 and Hybi drafts 7-17
* Easy to use message/event based API
* Boost ASIO based asynchronous network core
* Supports secure WebSockets (TLS) and IPv6
* Fully passes the AutoBahn 0.4.10 test suite
* Includes WebSocket performance and stress testing tools
* Open-source (BSD license)
For more information, please visit: http://www.zaphoyd.com/websocketpp/ or the
project's github wiki at: https://github.com/zaphoyd/websocketpp/wiki
+6 -1
View File
@@ -53,7 +53,12 @@
// Defaults
namespace websocketpp {
static const std::string USER_AGENT = "WebSocket++/0.2.2dev";
union uint64_converter {
uint64_t i;
uint8_t c[8];
};
static const std::string USER_AGENT = "WebSocket++/0.2.3dev";
typedef std::vector<unsigned char> binary_string;
typedef boost::shared_ptr<binary_string> binary_string_ptr;
+38
View File
@@ -200,6 +200,9 @@ public:
}
void send(const std::string& payload, frame::opcode::value op = frame::opcode::TEXT);
// In the future this could be changed to string_ref if it is adopted by
// the standard http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3334.html
void send(const void *payload, uint64_t length, frame::opcode::value op = frame::opcode::BINARY);
void send(message::data_ptr msg);
/// Close connection
@@ -1573,6 +1576,41 @@ connection<endpoint,role,socket>::send(const std::string& payload,frame::opcode:
send(msg);
}
/// convenience overload for sending a one off message.
/**
* Creates a message, fills in payload, and queues a write as a message of
* type op. Default type is BINARY.
*
* Visibility: public
* State: Valid from OPEN, ignored otherwise
* Concurrency: callable from any thread
*
* @param payload Payload to write_state
* @param op opcode to send the message as
*/
template <typename endpoint,template <class> class role,template <class> class socket>
void
connection<endpoint,role,socket>::send(const void *payload, uint64_t length, frame::opcode::value op)
{
{
boost::lock_guard<boost::recursive_mutex> lock(m_lock);
if (m_state != session::state::OPEN) {return;}
}
websocketpp::message::data::ptr msg = get_control_message2();
if (!msg) {
throw exception("Endpoint send queue is full",error::SEND_QUEUE_FULL);
}
if (op != frame::opcode::TEXT && op != frame::opcode::BINARY) {
throw exception("opcode must be either TEXT or BINARY",error::GENERIC);
}
msg->reset(op);
msg->set_payload(payload, length);
send(msg);
}
/// Send message
/**
* Prepares (if necessary) and sends the given message
+10
View File
@@ -26,6 +26,7 @@
*/
#include "data.hpp"
#include <string>
#include "../processors/processor.hpp"
#include "../processors/hybi_header.hpp"
@@ -155,6 +156,15 @@ void data::set_payload(const std::string& payload) {
m_payload.reserve(payload.size());
m_payload = payload;
}
// This could be improved using string_ref if it is ever added to the language.
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3334.html
void data::set_payload(const void *payload, size_t length) {
m_payload.reserve(length);
const char* pl = static_cast<const char*>(payload);
m_payload.assign(pl, pl + length);
}
void data::append_payload(const std::string& payload) {
m_payload.reserve(m_payload.size()+payload.size());
m_payload.append(payload);
+4
View File
@@ -36,6 +36,7 @@
#include <boost/enable_shared_from_this.hpp>
#include <boost/function.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/utility.hpp>
@@ -186,6 +187,9 @@ public:
// sets the payload to payload. Performs max size and UTF8 validation
// immediately and throws processor::exception if it fails
void set_payload(const std::string& payload);
// This could be improved using string_ref if it is ever added to the language.
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3334.html
void set_payload(const void *payload, size_t length);
void append_payload(const std::string& payload);
void set_header(const std::string& header);
+4 -1
View File
@@ -144,7 +144,10 @@ 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])) = zsutil::htonll(size);
uint64_converter temp64;
temp64.i = zsutil::htonll(size);
std::copy(temp64.c,temp64.c+8,m_header+BASIC_HEADER_LENGTH);
} else {
throw processor::exception("set_payload_size called with value that was too large (>2^63)",processor::error::MESSAGE_TOO_BIG);
}
+15 -11
View File
@@ -71,7 +71,8 @@ private:
}
*/
template <class rng_policy>
class parser : boost::noncopyable {
public:
@@ -395,10 +396,13 @@ public:
// this reinterprets the second pair of bytes in m_header as a
// 16 bit int and writes the payload size there as an integer
// in network byte order
*reinterpret_cast<uint16_t*>(&m_header[BASIC_HEADER_LENGTH]) = htons(s);
uint16_t value = htons(s);
memcpy(&m_header[BASIC_HEADER_LENGTH], &value, sizeof(uint16_t));
} else if (s <= limits::PAYLOAD_SIZE_JUMBO) {
m_header[1] = BASIC_PAYLOAD_64BIT_CODE;
*reinterpret_cast<uint64_t*>(&m_header[BASIC_HEADER_LENGTH]) = zsutil::htonll(s);
uint64_converter temp64;
temp64.i = zsutil::htonll(s);
std::copy(temp64.c,temp64.c+8,m_header+BASIC_HEADER_LENGTH);
} else {
throw processor::exception("payload size limit is 63 bits",processor::error::PROTOCOL_VIOLATION);
}
@@ -484,9 +488,9 @@ public:
} else if (s == BASIC_PAYLOAD_16BIT_CODE) {
// reinterpret the second two bytes as a 16 bit integer in network
// byte order. Convert to host byte order and store locally.
payload_size = ntohs(*(
reinterpret_cast<uint16_t*>(&m_header[BASIC_HEADER_LENGTH])
));
uint16_t value;
memcpy(&value, &m_header[BASIC_HEADER_LENGTH], sizeof(uint16_t));
payload_size = ntohs(value);
if (payload_size < s) {
std::stringstream err;
@@ -497,11 +501,10 @@ public:
mask_index += 2;
} else if (s == BASIC_PAYLOAD_64BIT_CODE) {
// reinterpret the second eight bytes as a 64 bit integer in
// reinterpret the second eight bytes as a 64 bit integer in
// network byte order. Convert to host byte order and store.
payload_size = zsutil::ntohll(*(
reinterpret_cast<uint64_t*>(&m_header[BASIC_HEADER_LENGTH])
));
memcpy(&payload_size, &m_header[BASIC_HEADER_LENGTH], sizeof(uint64_t));
payload_size = zsutil::ntohll(payload_size);
if (payload_size <= limits::PAYLOAD_SIZE_EXTENDED) {
m_bytes_needed = payload_size;
@@ -608,7 +611,8 @@ public:
}
void generate_masking_key() {
*(reinterpret_cast<int32_t *>(&m_header[get_header_len()-4])) = m_rng.rand();
int32_t value = m_rng.rand();
memcpy(&m_header[get_header_len()-4], &value, sizeof(int32_t));
}
void clear_masking_key() {
// this is a no-op as clearing the mask bit also changes the get_header_len