Skip to content

Commit 7a0d058

Browse files
committed
Some code formatting
Fraction of commit 6ac642b of dumbfixes branch of 0xFEEDC0DE64 fork of ESPAsyncWebServer. Additionally, lock is no longer released between _clearQueue() and _runQueue() in _onAck().
1 parent 4963ce9 commit 7a0d058

File tree

1 file changed

+43
-40
lines changed

1 file changed

+43
-40
lines changed

src/AsyncWebSocket.cpp

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -307,31 +307,29 @@ void AsyncWebSocketClient::_clearQueue()
307307
void AsyncWebSocketClient::_onAck(size_t len, uint32_t time){
308308
_lastMessageTime = millis();
309309

310-
{
311-
AsyncWebLockGuard l(_lock);
310+
AsyncWebLockGuard l(_lock);
312311

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){
324317
_controlQueue.pop_front();
318+
_status = WS_DISCONNECTED;
319+
l.unlock();
320+
_client->close(true);
321+
return;
325322
}
323+
_controlQueue.pop_front();
326324
}
325+
}
327326

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);
333329
}
334330

331+
_clearQueue();
332+
335333
_runQueue();
336334
}
337335

@@ -428,29 +426,34 @@ void AsyncWebSocketClient::_queueMessage(std::shared_ptr<std::vector<uint8_t>> b
428426
_runQueue();
429427
}
430428

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+
}
451455
}
452-
}
453-
_queueControl(WS_DISCONNECT);
456+
_queueControl(WS_DISCONNECT);
454457
}
455458

456459
void AsyncWebSocketClient::ping(const uint8_t *data, size_t len)

0 commit comments

Comments
 (0)