Skip to content

added string_view support for sending message #1052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions websocketpp/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,21 @@ class connection
lib::error_code send(std::string const & payload, frame::opcode::value op =
frame::opcode::text);

/// Create a message and then add it to the outgoing send queue
/**
* Convenience method to send a message given a payload string and
* optionally an opcode. Default opcode is utf8 text.
*
* This method locks the m_write_lock mutex
*
* @param payload The payload string to generated the message with
*
* @param op The opcode to generated the message with. Default is
* frame::opcode::text
*/
lib::error_code send(std::string_view 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
Expand Down
9 changes: 9 additions & 0 deletions websocketpp/impl/connection_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ lib::error_code connection<config>::send(std::string const & payload,
return send(msg);
}

template<typename config>
lib::error_code connection<config>::send(std::string_view payload, frame::opcode::value op)
{
message_ptr msg = m_msg_manager->get_message(op,payload.size());
msg->append_payload(payload);
msg->set_compressed(true);
return send(msg);
}

template <typename config>
lib::error_code connection<config>::send(void const * payload, size_t len,
frame::opcode::value op)
Expand Down
10 changes: 10 additions & 0 deletions websocketpp/message_buffer/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ class message {
m_payload.append(payload);
}

/// Append payload data
/**
* Append data to the message buffer's payload.
*
* @param payload A string_view containing the data array to append.
*/
void append_payload(std::string_view payload) {
m_payload.append(payload);
}

/// Append payload data
/**
* Append data to the message buffer's payload.
Expand Down