25 #include "cpprest/details/basic_types.h"
27 #if !defined(CPPREST_EXCLUDE_WEBSOCKETS)
32 #include "pplx/pplxtasks.h"
33 #include "cpprest/streams.h"
34 #include "cpprest/containerstream.h"
35 #include "cpprest/uri.h"
36 #include "cpprest/asyncrt_utils.h"
47 class winrt_callback_client;
48 class wspp_callback_client;
49 #if defined(__cplusplus_winrt)
50 ref class ReceiveContext;
82 this->set_message(concurrency::streams::container_buffer<std::string>(std::move(data)));
91 this->set_message(concurrency::streams::container_buffer<std::string>(data));
101 this->set_message(istream, SIZE_MAX, websocket_message_type::text_message);
111 this->set_message(istream, len, websocket_message_type::text_message);
121 this->set_message(istream, len, websocket_message_type::binary_message);
131 this->set_message(istream, SIZE_MAX, websocket_message_type::binary_message);
135 friend class details::winrt_callback_client;
136 friend class details::wspp_callback_client;
139 concurrency::streams::streambuf<uint8_t> m_body;
143 void signal_body_sent()
const
148 void signal_body_sent(
const std::exception_ptr &e)
const
150 m_body_sent.set_exception(e);
155 void set_message(
const concurrency::streams::container_buffer<std::string> &buffer)
157 m_msg_type = websocket_message_type::text_message;
158 m_length =
static_cast<size_t>(buffer.size());
162 void set_message(
const concurrency::streams::istream &istream,
size_t len,
websocket_message_type msg_type)
164 m_msg_type = msg_type;
166 m_body = istream.streambuf();
192 concurrency::streams::istream
body()
const
194 auto to_uint8_t_stream = [](
const concurrency::streams::streambuf<uint8_t> &buf) -> concurrency::streams::istream
196 return buf.create_istream();
198 return to_uint8_t_stream(m_body);
206 return static_cast<size_t>(m_body.size());
212 CASABLANCA_DEPRECATED(
"Incorrectly spelled API, use message_type() instead.")
228 friend class details::winrt_callback_client;
229 friend class details::wspp_callback_client;
230 #if defined(__cplusplus_winrt)
231 friend ref class details::ReceiveContext;
236 concurrency::streams::container_buffer<std::string> m_body;
concurrency::streams::istream body() const
Produces a stream which the caller may use to retrieve body from an incoming message. Can be used for both UTF-8 (text) and binary message types.
Definition: ws_msg.h:192
The task_completion_event class allows you to delay the execution of a task until a condition is sati...
Definition: pplxtasks.h:2934
Represents an incoming websocket message
Definition: ws_msg.h:173
websocket_message_type messge_type() const
Returns the type of the received message.
Definition: ws_msg.h:213
The web namespace contains functionality common to multiple protocols like HTTP and WebSockets...
Definition: base_uri.h:37
void set_utf8_message(const std::string &data)
Sets a UTF-8 message as the message body.
Definition: ws_msg.h:89
_ASYNCRTIMP pplx::task< std::string > extract_string() const
Extracts the body of the incoming message as a string value, only if the message type is UTF-8...
websocket_message_type
The different types of websocket message. Text type contains UTF-8 encoded data. Interpretation of Bi...
Definition: ws_msg.h:60
void set_binary_message(const concurrency::streams::istream &istream, size_t len)
Sets binary data as the message body.
Definition: ws_msg.h:119
websocket_message_type message_type() const
Returns the type of the received message, either string or binary.
Definition: ws_msg.h:222
size_t length() const
Returns the length of the received message.
Definition: ws_msg.h:204
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: pplxtasks.h:176
void set_binary_message(const concurrency::streams::istream &istream)
Sets binary data as the message body.
Definition: ws_msg.h:129
void set_utf8_message(const concurrency::streams::istream &istream)
Sets a UTF-8 message as the message body.
Definition: ws_msg.h:99
Represents an outgoing websocket message
Definition: ws_msg.h:72
void set_utf8_message(const concurrency::streams::istream &istream, size_t len)
Sets a UTF-8 message as the message body.
Definition: ws_msg.h:109
void set_utf8_message(std::string &&data)
Sets a UTF-8 message as the message body.
Definition: ws_msg.h:80
bool set() const
Sets the task completion event.
Definition: pplxtasks.h:2950