18
18
#include " cpprest/details/x509_cert_utilities.h"
19
19
#include " pplx/threadpool.h"
20
20
21
+ #include " ws_client_impl.h"
22
+
21
23
// Force websocketpp to use C++ std::error_code instead of Boost.
22
24
#define _WEBSOCKETPP_CPP11_SYSTEM_ERROR_
23
25
#if defined(_MSC_VER)
@@ -401,10 +403,10 @@ class wspp_callback_client : public websocket_client_callback_impl, public std::
401
403
{
402
404
case websocket_message_type::text_message:
403
405
case websocket_message_type::binary_message:
404
- case websocket_message_type::pong:
406
+ case websocket_message_type::pong:
405
407
break ;
406
408
default :
407
- return pplx::task_from_exception<void >(websocket_exception (" Invalid message type " ));
409
+ return pplx::task_from_exception<void >(websocket_exception (" Message Type not supported. " ));
408
410
}
409
411
410
412
const auto length = msg.m_length ;
@@ -417,22 +419,13 @@ class wspp_callback_client : public websocket_client_callback_impl, public std::
417
419
return pplx::task_from_exception<void >(websocket_exception (" Message size too large. Ensure message length is less than UINT_MAX." ));
418
420
}
419
421
420
- bool msg_pending = false ;
421
- {
422
- std::lock_guard<std::mutex> lock (m_send_lock);
423
- if (m_outgoing_msg_queue.size () > 0 )
424
- {
425
- msg_pending = true ;
426
- }
427
-
428
- m_outgoing_msg_queue.push (msg);
429
- }
422
+ auto msg_pending = m_out_queue.push (msg);
430
423
431
424
// No sends in progress
432
- if (msg_pending == false )
425
+ if (msg_pending == outgoing_msg_queue::state::was_empty )
433
426
{
434
- // Start sending the message
435
- send_msg (msg);
427
+ // Start sending the message
428
+ send_msg (msg);
436
429
}
437
430
438
431
return pplx::create_task (msg.body_sent ());
@@ -568,21 +561,8 @@ class wspp_callback_client : public websocket_client_callback_impl, public std::
568
561
msg.signal_body_sent ();
569
562
}
570
563
571
- bool msg_pending = false ;
572
564
websocket_outgoing_message next_msg;
573
- {
574
- // Only hold the lock when actually touching the queue.
575
- std::lock_guard<std::mutex> lock (this_client->m_send_lock );
576
-
577
- // First message in queue has been sent
578
- this_client->m_outgoing_msg_queue .pop ();
579
-
580
- if (this_client->m_outgoing_msg_queue .size () > 0 )
581
- {
582
- next_msg = this_client->m_outgoing_msg_queue .front ();
583
- msg_pending = true ;
584
- }
585
- }
565
+ bool msg_pending = this_client->m_out_queue .pop_and_peek (next_msg);
586
566
587
567
if (msg_pending)
588
568
{
@@ -681,19 +661,19 @@ class wspp_callback_client : public websocket_client_callback_impl, public std::
681
661
ec);
682
662
break ;
683
663
case websocket_message_type::binary_message:
684
- client.send (
664
+ client.send (
685
665
this_client->m_con ,
686
666
sp_allocated.get (),
687
667
length,
688
668
websocketpp::frame::opcode::binary,
689
669
ec);
690
670
break ;
691
- case websocket_message_type::pong:
692
- client.pong (
693
- this_client->m_con ,
694
- " " ,
695
- ec);
696
- break ;
671
+ case websocket_message_type::pong:
672
+ client.pong (
673
+ this_client->m_con ,
674
+ " " ,
675
+ ec);
676
+ break ;
697
677
default :
698
678
// This case should have already been filtered above.
699
679
std::abort ();
@@ -775,11 +755,8 @@ class wspp_callback_client : public websocket_client_callback_impl, public std::
775
755
State m_state;
776
756
std::unique_ptr<websocketpp_client_base> m_client;
777
757
778
- // Guards access to m_outgoing_msg_queue
779
- std::mutex m_send_lock;
780
-
781
758
// Queue to track pending sends
782
- std::queue<websocket_outgoing_message> m_outgoing_msg_queue ;
759
+ outgoing_msg_queue m_out_queue ;
783
760
784
761
// External callback for handling received and close event
785
762
std::function<void (websocket_incoming_message)> m_external_message_handler;
0 commit comments