Code formatting plus queue unlocking change

Based on commit f7c5c452df5b0918357fc98003aafde9e18304f9  of dumbfixes
branch of 0xFEEDC0DE64 fork of ESPAsyncWebServer.

In addition to indentation changes, now the queues are no longer
unlocked before attempting to write the messages to the socket.
This commit is contained in:
Alex Villacís Lasso
2021-01-02 18:06:19 -05:00
parent 1e8d96631d
commit 04672f4572
2 changed files with 37 additions and 33 deletions

View File

@@ -514,13 +514,16 @@ void AsyncWebSocketClient::_onAck(size_t len, uint32_t time){
_runQueue(); _runQueue();
} }
void AsyncWebSocketClient::_onPoll(){ void AsyncWebSocketClient::_onPoll()
if(_client->canSend() && [this](){ AsyncWebLockGuard l(_lock); return !_controlQueue.empty() || !_messageQueue.empty(); }()) {
AsyncWebLockGuard l(_lock);
if(_client->canSend() && (!_controlQueue.empty() || !_messageQueue.empty()))
{ {
l.unlock();
_runQueue(); _runQueue();
} else if(_keepAlivePeriod > 0 && (millis() - _lastMessageTime) >= _keepAlivePeriod && } else if(_keepAlivePeriod > 0 && (millis() - _lastMessageTime) >= _keepAlivePeriod && (_controlQueue.empty() && _messageQueue.empty()))
[this](){ AsyncWebLockGuard l(_lock); return _controlQueue.empty() && _messageQueue.empty(); }())
{ {
l.unlock();
ping((uint8_t *)AWSC_PING_PAYLOAD, AWSC_PING_PAYLOAD_LEN); ping((uint8_t *)AWSC_PING_PAYLOAD, AWSC_PING_PAYLOAD_LEN);
} }
} }
@@ -533,12 +536,12 @@ void AsyncWebSocketClient::_runQueue()
if(!_controlQueue.empty() && (_messageQueue.empty() || _messageQueue.front().get().betweenFrames()) && webSocketSendFrameWindow(_client) > (size_t)(_controlQueue.front().len() - 1)) if(!_controlQueue.empty() && (_messageQueue.empty() || _messageQueue.front().get().betweenFrames()) && webSocketSendFrameWindow(_client) > (size_t)(_controlQueue.front().len() - 1))
{ {
l.unlock(); //l.unlock();
_controlQueue.front().send(_client); _controlQueue.front().send(_client);
} }
else if (!_messageQueue.empty() && _messageQueue.front().get().betweenFrames() && webSocketSendFrameWindow(_client)) else if (!_messageQueue.empty() && _messageQueue.front().get().betweenFrames() && webSocketSendFrameWindow(_client))
{ {
l.unlock(); //l.unlock();
_messageQueue.front().get().send(_client); _messageQueue.front().get().send(_client);
} }
} }

View File

@@ -47,7 +47,8 @@ private:
mutable TaskHandle_t _lockedBy{}; mutable TaskHandle_t _lockedBy{};
public: public:
AsyncWebLock() { AsyncWebLock()
{
_lock = xSemaphoreCreateBinary(); _lock = xSemaphoreCreateBinary();
// In this fails, the system is likely that much out of memory that // In this fails, the system is likely that much out of memory that
// we should abort anyways. If assertions are disabled, nothing is lost.. // we should abort anyways. If assertions are disabled, nothing is lost..