@@ -61,7 +61,7 @@ ref class ReceiveContext sealed
61
61
62
62
private:
63
63
// Public members cannot have native types
64
- ReceiveContext (std::function<void (websocket_incoming_message &> )> receive_handler, std::function<void ()> close_handler): m_receive_handler(receive_handler), m_close_handler(close_handler) {}
64
+ ReceiveContext (std::function<void (websocket_incoming_message &)> receive_handler, std::function<void ()> close_handler): m_receive_handler(receive_handler), m_close_handler(close_handler) {}
65
65
66
66
// Handler to be executed when a message has been received by the client
67
67
std::function<void (websocket_incoming_message &)> m_receive_handler;
@@ -246,13 +246,13 @@ class winrt_client : public _websocket_client_impl, public std::enable_shared_fr
246
246
m_outgoing_msg_queue.push (msg);
247
247
}
248
248
}
249
- return pplx::create_task (msg._m_impl -> msg_sent ());
249
+ return pplx::create_task (msg.body_sent ());
250
250
}
251
251
252
252
void send_msg (websocket_outgoing_message &msg)
253
253
{
254
254
auto this_client = this ->shared_from_this ();
255
- auto & is_buf = msg.m_body . create_istream () ;
255
+ auto & is_buf = msg.m_body ;
256
256
auto length = msg._m_impl ->length ();
257
257
258
258
if (length == SIZE_MAX)
@@ -264,7 +264,7 @@ class winrt_client : public _websocket_client_impl, public std::enable_shared_fr
264
264
auto buf_sz = is_buf.size ();
265
265
if (buf_sz >= SIZE_MAX)
266
266
{
267
- msg.signal_msg_sent (std::make_exception_ptr (websocket_exception (" Cannot send messages larger than SIZE_MAX." )));
267
+ msg.signal_body_sent (std::make_exception_ptr (websocket_exception (" Cannot send messages larger than SIZE_MAX." )));
268
268
return ;
269
269
}
270
270
length = static_cast <size_t >(buf_sz);
@@ -275,7 +275,7 @@ class winrt_client : public _websocket_client_impl, public std::enable_shared_fr
275
275
// The stream needs to be buffered.
276
276
auto is_buf_istream = is_buf.create_istream ();
277
277
msg.m_body = concurrency::streams::container_buffer<std::vector<uint8_t >>();
278
- is_buf_istream.read_to_end (msg.m_body ).then ([this_client, msg](pplx::task<size_t > t)
278
+ is_buf_istream.read_to_end (msg.m_body ).then ([this_client, msg](pplx::task<size_t > t) mutable
279
279
{
280
280
try
281
281
{
@@ -284,7 +284,7 @@ class winrt_client : public _websocket_client_impl, public std::enable_shared_fr
284
284
}
285
285
catch (...)
286
286
{
287
- msg.signal_msg_sent (std::current_exception ());
287
+ msg.signal_body_sent (std::current_exception ());
288
288
}
289
289
});
290
290
// We have postponed the call to send_msg() until after the data is buffered.
@@ -334,7 +334,7 @@ class winrt_client : public _websocket_client_impl, public std::enable_shared_fr
334
334
335
335
// Send the data as one complete message, in WinRT we do not have an option to send fragments.
336
336
return pplx::task<unsigned int >(this_client->m_messageWriter ->StoreAsync ());
337
- }).then ([this_client, msg, is_buf, acquired, sp_allocated, length](pplx::task<unsigned int > previousTask)
337
+ }).then ([this_client, msg, is_buf, acquired, sp_allocated, length](pplx::task<unsigned int > previousTask) mutable
338
338
{
339
339
std::exception_ptr eptr;
340
340
unsigned int bytes_written = 0 ;
@@ -364,7 +364,7 @@ class winrt_client : public _websocket_client_impl, public std::enable_shared_fr
364
364
// Set the send_task_completion_event after calling release.
365
365
if (eptr)
366
366
{
367
- msg.signal_msg_sent (eptr);
367
+ msg.signal_body_sent (eptr);
368
368
}
369
369
370
370
{
@@ -377,7 +377,7 @@ class winrt_client : public _websocket_client_impl, public std::enable_shared_fr
377
377
this_client->send_msg (next_msg);
378
378
}
379
379
}
380
- msg.signal_msg_sent ();
380
+ msg.signal_body_sent ();
381
381
});
382
382
}
383
383
@@ -462,7 +462,7 @@ class winrt_client : public _websocket_client_impl, public std::enable_shared_fr
462
462
void ReceiveContext::OnReceive (MessageWebSocket^ sender, MessageWebSocketMessageReceivedEventArgs^ args)
463
463
{
464
464
websocket_incoming_message ws_incoming_message;
465
- auto &msg = ws_incoming_message-> _m_impl ;
465
+ auto &msg = ws_incoming_message. _m_impl ;
466
466
467
467
switch (args->MessageType )
468
468
{
@@ -478,11 +478,14 @@ void ReceiveContext::OnReceive(MessageWebSocket^ sender, MessageWebSocketMessage
478
478
{
479
479
DataReader^ reader = args->GetDataReader ();
480
480
const auto len = reader->UnconsumedBufferLength ;
481
- std::string payload;
482
- payload.resize (len);
483
- reader->ReadBytes (Platform::ArrayReference<uint8_t >(payload.c_str (), len));
484
- ws_incoming_message.m_body = concurrency::streams::container_buffer<std::string>(std::move (payload));
485
- msg->signal_msg_received (len);
481
+ if (len > 0 )
482
+ {
483
+ std::string payload;
484
+ payload.resize (len);
485
+ reader->ReadBytes (Platform::ArrayReference<uint8_t >(reinterpret_cast <uint8 *>(&payload[0 ]), len));
486
+ ws_incoming_message.m_body = concurrency::streams::container_buffer<std::string>(std::move (payload));
487
+ }
488
+ msg->set_length (len);
486
489
m_receive_handler (ws_incoming_message);
487
490
}
488
491
catch (...)
0 commit comments