diff --git a/websocketpp/connection.hpp b/websocketpp/connection.hpp index d2ce8fa423..37da591d6d 100644 --- a/websocketpp/connection.hpp +++ b/websocketpp/connection.hpp @@ -359,9 +359,6 @@ public: * Convenience method to send a message given a payload string and * optionally an opcode. Default opcode is utf8 text. * - * Errors are returned via an exception - * TODO: make exception system_error rather than error_code - * * This method locks the m_write_lock mutex * * @param payload The payload string to generated the message with @@ -371,6 +368,23 @@ public: */ lib::error_code send(const std::string& payload, frame::opcode::value op = frame::opcode::TEXT); + + /// Send a message (raw array overload) + /** + * Convenience method to send a message given a raw array and optionally an + * opcode. Default opcode is binary. + * + * This method locks the m_write_lock mutex + * + * @param payload A pointer to the array containing the bytes to send. + * + * @param len Length of the array. + * + * @param op The opcode to generated the message with. Default is + * frame::opcode::binary + */ + lib::error_code send(const void* payload, size_t len, frame::opcode::value + op = frame::opcode::BINARY); /// Add a message to the outgoing send queue /** diff --git a/websocketpp/impl/connection_impl.hpp b/websocketpp/impl/connection_impl.hpp index f732db0255..0fbc410fac 100644 --- a/websocketpp/impl/connection_impl.hpp +++ b/websocketpp/impl/connection_impl.hpp @@ -76,6 +76,16 @@ lib::error_code connection::send(const std::string& payload, return send(msg); } +template +lib::error_code connection::send(const void* payload, size_t len, + frame::opcode::value op) +{ + message_ptr msg = m_msg_manager->get_message(op,len); + msg->append_payload(payload,len); + + return send(msg); +} + template lib::error_code connection::send(typename config::message_type::ptr msg) {