@@ -294,7 +294,7 @@ AsyncWebSocketClient::AsyncWebSocketClient(AsyncClient *client, AsyncWebSocket *
294294
295295AsyncWebSocketClient::~AsyncWebSocketClient () {
296296 {
297- LOCK (_lock);
297+ lock_guard_type lock (_lock);
298298 _messageQueue.clear ();
299299 _controlQueue.clear ();
300300 }
@@ -310,7 +310,7 @@ void AsyncWebSocketClient::_clearQueue() {
310310void AsyncWebSocketClient::_onAck (size_t len, uint32_t time) {
311311 _lastMessageTime = millis ();
312312
313- UNIQUE_LOCK (_lock);
313+ unique_lock_type lock (_lock);
314314
315315 async_ws_log_v (" [%s][%" PRIu32 " ] START ACK(%u, %" PRIu32 " ) Q:%u" , _server->url (), _clientId, len, time, _messageQueue.size ());
316316
@@ -328,7 +328,7 @@ void AsyncWebSocketClient::_onAck(size_t len, uint32_t time) {
328328 Due to _client->close() shall call the callback function _onDisconnect()
329329 The calling flow _onDisconnect() --> _handleDisconnect() --> ~AsyncWebSocketClient()
330330 */
331- UNLOCK ();
331+ lock. unlock ();
332332 _client->close ();
333333 }
334334 return ;
@@ -358,11 +358,11 @@ void AsyncWebSocketClient::_onPoll() {
358358 return ;
359359 }
360360
361- UNIQUE_LOCK (_lock);
361+ unique_lock_type lock (_lock);
362362 if (_client && _client->canSend () && (!_controlQueue.empty () || !_messageQueue.empty ())) {
363363 _runQueue ();
364364 } else if (_keepAlivePeriod > 0 && (millis () - _lastMessageTime) >= _keepAlivePeriod && (_controlQueue.empty () && _messageQueue.empty ())) {
365- UNLOCK ();
365+ lock. unlock ();
366366 ping ((uint8_t *)AWSC_PING_PAYLOAD , AWSC_PING_PAYLOAD_LEN );
367367 }
368368}
@@ -426,17 +426,17 @@ void AsyncWebSocketClient::_runQueue() {
426426}
427427
428428bool AsyncWebSocketClient::queueIsFull () const {
429- LOCK (_lock);
429+ lock_guard_type lock (_lock);
430430 return (_messageQueue.size () >= WS_MAX_QUEUED_MESSAGES ) || (_status != WS_CONNECTED );
431431}
432432
433433size_t AsyncWebSocketClient::queueLen () const {
434- LOCK (_lock);
434+ lock_guard_type lock (_lock);
435435 return _messageQueue.size ();
436436}
437437
438438bool AsyncWebSocketClient::canSend () const {
439- LOCK (_lock);
439+ lock_guard_type lock (_lock);
440440 return _messageQueue.size () < WS_MAX_QUEUED_MESSAGES ;
441441}
442442
@@ -445,7 +445,7 @@ bool AsyncWebSocketClient::_queueControl(uint8_t opcode, const uint8_t *data, si
445445 return false ;
446446 }
447447
448- LOCK (_lock);
448+ lock_guard_type lock (_lock);
449449
450450 _controlQueue.emplace_back (opcode, data, len, mask);
451451 async_ws_log_v (" [%s][%" PRIu32 " ] QUEUE CTRL (%u) << %" PRIu8, _server->url (), _clientId, _controlQueue.size (), opcode);
@@ -462,7 +462,7 @@ bool AsyncWebSocketClient::_queueMessage(AsyncWebSocketSharedBuffer buffer, uint
462462 return false ;
463463 }
464464
465- UNIQUE_LOCK (_lock);
465+ unique_lock_type lock (_lock);
466466
467467 if (_messageQueue.size () >= WS_MAX_QUEUED_MESSAGES ) {
468468 if (closeWhenFull) {
@@ -474,7 +474,7 @@ bool AsyncWebSocketClient::_queueMessage(AsyncWebSocketSharedBuffer buffer, uint
474474 Due to _client->close() shall call the callback function _onDisconnect()
475475 The calling flow _onDisconnect() --> _handleDisconnect() --> ~AsyncWebSocketClient()
476476 */
477- UNLOCK ();
477+ lock. unlock ();
478478 _client->close ();
479479 }
480480
@@ -969,7 +969,7 @@ void AsyncWebSocket::_handleEvent(AsyncWebSocketClient *client, AwsEventType typ
969969}
970970
971971AsyncWebSocketClient *AsyncWebSocket::_newClient (AsyncWebServerRequest *request) {
972- LOCK (_lock);
972+ lock_guard_type lock (_lock);
973973 _clients.emplace_back (request, this );
974974 // we've just detached AsyncTCP client from AsyncWebServerRequest
975975 _handleEvent (&_clients.back (), WS_EVT_CONNECT , request, NULL , 0 );
@@ -979,7 +979,7 @@ AsyncWebSocketClient *AsyncWebSocket::_newClient(AsyncWebServerRequest *request)
979979}
980980
981981void AsyncWebSocket::_handleDisconnect (AsyncWebSocketClient *client) {
982- LOCK (_lock);
982+ lock_guard_type lock (_lock);
983983 const auto client_id = client->id ();
984984 const auto iter = std::find_if (std::begin (_clients), std::end (_clients), [client_id](const AsyncWebSocketClient &c) {
985985 return c.id () == client_id;
@@ -990,14 +990,14 @@ void AsyncWebSocket::_handleDisconnect(AsyncWebSocketClient *client) {
990990}
991991
992992bool AsyncWebSocket::availableForWriteAll () {
993- LOCK (_lock);
993+ lock_guard_type lock (_lock);
994994 return std::none_of (std::begin (_clients), std::end (_clients), [](const AsyncWebSocketClient &c) {
995995 return c.queueIsFull ();
996996 });
997997}
998998
999999bool AsyncWebSocket::availableForWrite (uint32_t id) {
1000- LOCK (_lock);
1000+ lock_guard_type lock (_lock);
10011001 const auto iter = std::find_if (std::begin (_clients), std::end (_clients), [id](const AsyncWebSocketClient &c) {
10021002 return c.id () == id;
10031003 });
@@ -1008,14 +1008,14 @@ bool AsyncWebSocket::availableForWrite(uint32_t id) {
10081008}
10091009
10101010size_t AsyncWebSocket::count () const {
1011- LOCK (_lock);
1011+ lock_guard_type lock (_lock);
10121012 return std::count_if (std::begin (_clients), std::end (_clients), [](const AsyncWebSocketClient &c) {
10131013 return c.status () == WS_CONNECTED ;
10141014 });
10151015}
10161016
10171017AsyncWebSocketClient *AsyncWebSocket::client (uint32_t id) {
1018- LOCK (_lock);
1018+ lock_guard_type lock (_lock);
10191019 const auto iter = std::find_if (_clients.begin (), _clients.end (), [id](const AsyncWebSocketClient &c) {
10201020 return c.id () == id && c.status () == WS_CONNECTED ;
10211021 });
@@ -1033,7 +1033,7 @@ void AsyncWebSocket::close(uint32_t id, uint16_t code, const char *message) {
10331033}
10341034
10351035void AsyncWebSocket::closeAll (uint16_t code, const char *message) {
1036- LOCK (_lock);
1036+ lock_guard_type lock (_lock);
10371037 for (auto &c : _clients) {
10381038 if (c.status () == WS_CONNECTED ) {
10391039 c.close (code, message);
@@ -1042,7 +1042,7 @@ void AsyncWebSocket::closeAll(uint16_t code, const char *message) {
10421042}
10431043
10441044void AsyncWebSocket::cleanupClients (uint16_t maxClients) {
1045- LOCK (_lock);
1045+ lock_guard_type lock (_lock);
10461046 const size_t c = count ();
10471047 if (c > maxClients) {
10481048 async_ws_log_v (" [%s] CLEANUP %" PRIu32 " (%u/%" PRIu16 " )" , _url.c_str (), _clients.front ().id (), c, maxClients);
@@ -1063,7 +1063,7 @@ bool AsyncWebSocket::ping(uint32_t id, const uint8_t *data, size_t len) {
10631063}
10641064
10651065AsyncWebSocket::SendStatus AsyncWebSocket::pingAll (const uint8_t *data, size_t len) {
1066- LOCK (_lock);
1066+ lock_guard_type lock (_lock);
10671067 size_t hit = 0 ;
10681068 size_t miss = 0 ;
10691069 for (auto &c : _clients) {
@@ -1172,7 +1172,7 @@ AsyncWebSocket::SendStatus AsyncWebSocket::textAll(AsyncWebSocketMessageBuffer *
11721172}
11731173
11741174AsyncWebSocket::SendStatus AsyncWebSocket::textAll (AsyncWebSocketSharedBuffer buffer) {
1175- LOCK (_lock);
1175+ lock_guard_type lock (_lock);
11761176 size_t hit = 0 ;
11771177 size_t miss = 0 ;
11781178 for (auto &c : _clients) {
@@ -1262,7 +1262,7 @@ AsyncWebSocket::SendStatus AsyncWebSocket::binaryAll(AsyncWebSocketMessageBuffer
12621262 return status;
12631263}
12641264AsyncWebSocket::SendStatus AsyncWebSocket::binaryAll (AsyncWebSocketSharedBuffer buffer) {
1265- LOCK (_lock);
1265+ lock_guard_type lock (_lock);
12661266 size_t hit = 0 ;
12671267 size_t miss = 0 ;
12681268 for (auto &c : _clients) {
0 commit comments