@@ -307,31 +307,29 @@ void AsyncWebSocketClient::_clearQueue()
307
307
void AsyncWebSocketClient::_onAck (size_t len, uint32_t time){
308
308
_lastMessageTime = millis ();
309
309
310
- {
311
- AsyncWebLockGuard l (_lock);
310
+ AsyncWebLockGuard l (_lock);
312
311
313
- if (!_controlQueue.empty ()) {
314
- auto &head = _controlQueue.front ();
315
- if (head.finished ()){
316
- len -= head.len ();
317
- if (_status == WS_DISCONNECTING && head.opcode () == WS_DISCONNECT){
318
- _controlQueue.pop_front ();
319
- _status = WS_DISCONNECTED;
320
- l.unlock ();
321
- _client->close (true );
322
- return ;
323
- }
312
+ if (!_controlQueue.empty ()) {
313
+ auto &head = _controlQueue.front ();
314
+ if (head.finished ()){
315
+ len -= head.len ();
316
+ if (_status == WS_DISCONNECTING && head.opcode () == WS_DISCONNECT){
324
317
_controlQueue.pop_front ();
318
+ _status = WS_DISCONNECTED;
319
+ l.unlock ();
320
+ _client->close (true );
321
+ return ;
325
322
}
323
+ _controlQueue.pop_front ();
326
324
}
325
+ }
327
326
328
- if (len && !_messageQueue.empty ()){
329
- _messageQueue.front ().ack (len, time);
330
- }
331
-
332
- _clearQueue ();
327
+ if (len && !_messageQueue.empty ()){
328
+ _messageQueue.front ().ack (len, time);
333
329
}
334
330
331
+ _clearQueue ();
332
+
335
333
_runQueue ();
336
334
}
337
335
@@ -428,29 +426,34 @@ void AsyncWebSocketClient::_queueMessage(std::shared_ptr<std::vector<uint8_t>> b
428
426
_runQueue ();
429
427
}
430
428
431
- void AsyncWebSocketClient::close (uint16_t code, const char * message){
432
- if (_status != WS_CONNECTED)
433
- return ;
434
- if (code){
435
- uint8_t packetLen = 2 ;
436
- if (message != NULL ){
437
- size_t mlen = strlen (message);
438
- if (mlen > 123 ) mlen = 123 ;
439
- packetLen += mlen;
440
- }
441
- char * buf = (char *)malloc (packetLen);
442
- if (buf != NULL ){
443
- buf[0 ] = (uint8_t )(code >> 8 );
444
- buf[1 ] = (uint8_t )(code & 0xFF );
445
- if (message != NULL ){
446
- memcpy (buf+2 , message, packetLen -2 );
447
- }
448
- _queueControl (WS_DISCONNECT, (uint8_t *)buf, packetLen);
449
- free (buf);
450
- return ;
429
+ void AsyncWebSocketClient::close (uint16_t code, const char * message)
430
+ {
431
+ if (_status != WS_CONNECTED)
432
+ return ;
433
+
434
+ if (code)
435
+ {
436
+ uint8_t packetLen = 2 ;
437
+ if (message != NULL )
438
+ {
439
+ size_t mlen = strlen (message);
440
+ if (mlen > 123 ) mlen = 123 ;
441
+ packetLen += mlen;
442
+ }
443
+ char * buf = (char *)malloc (packetLen);
444
+ if (buf != NULL )
445
+ {
446
+ buf[0 ] = (uint8_t )(code >> 8 );
447
+ buf[1 ] = (uint8_t )(code & 0xFF );
448
+ if (message != NULL ){
449
+ memcpy (buf+2 , message, packetLen -2 );
450
+ }
451
+ _queueControl (WS_DISCONNECT, (uint8_t *)buf, packetLen);
452
+ free (buf);
453
+ return ;
454
+ }
451
455
}
452
- }
453
- _queueControl (WS_DISCONNECT);
456
+ _queueControl (WS_DISCONNECT);
454
457
}
455
458
456
459
void AsyncWebSocketClient::ping (const uint8_t *data, size_t len)
0 commit comments