Code formatting

This commit is contained in:
2020-12-20 05:48:13 +01:00
parent 84833546f0
commit f7c5c452df
2 changed files with 58 additions and 61 deletions

View File

@ -517,6 +517,7 @@ void AsyncWebSocketClient::_onAck(size_t len, uint32_t time)
if (_status == WS_DISCONNECTING && head.opcode() == WS_DISCONNECT){ if (_status == WS_DISCONNECTING && head.opcode() == WS_DISCONNECT){
_controlQueue.pop(); _controlQueue.pop();
_status = WS_DISCONNECTED; _status = WS_DISCONNECTED;
l.unlock();
_client->close(true); _client->close(true);
return; return;
} }
@ -537,13 +538,15 @@ void AsyncWebSocketClient::_onPoll()
{ {
Serial.printf("AsyncWebSocketClient::_onPoll this=0x%llx task=0x%llx %s\r\n", uint64_t(this), uint64_t(xTaskGetCurrentTaskHandle()), pcTaskGetTaskName(xTaskGetCurrentTaskHandle())); Serial.printf("AsyncWebSocketClient::_onPoll this=0x%llx task=0x%llx %s\r\n", uint64_t(this), uint64_t(xTaskGetCurrentTaskHandle()), pcTaskGetTaskName(xTaskGetCurrentTaskHandle()));
if(_client->canSend() && [this](){ AsyncWebLockGuard l(_lock, "AsyncWebSocketClient::_onPoll(1)"); return !_controlQueue.empty() || !_messageQueue.empty(); }()) AsyncWebLockGuard l(_lock, "AsyncWebSocketClient::_onPoll");
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, "AsyncWebSocketClient::_onPoll(1)"); 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);
} }
} }
@ -552,27 +555,21 @@ void AsyncWebSocketClient::_runQueue()
{ {
Serial.printf("AsyncWebSocketClient::_runQueue this=0x%llx task=0x%llx %s\r\n", uint64_t(this), uint64_t(xTaskGetCurrentTaskHandle()), pcTaskGetTaskName(xTaskGetCurrentTaskHandle())); Serial.printf("AsyncWebSocketClient::_runQueue this=0x%llx task=0x%llx %s\r\n", uint64_t(this), uint64_t(xTaskGetCurrentTaskHandle()), pcTaskGetTaskName(xTaskGetCurrentTaskHandle()));
AsyncWebLockGuard l(_lock, "AsyncWebSocketClient::_runQueue()");
while (!_messageQueue.empty() && _messageQueue.front().get().finished())
_messageQueue.pop();
if (!_controlQueue.empty() && (_messageQueue.empty() || _messageQueue.front().get().betweenFrames()) && webSocketSendFrameWindow(_client) > (size_t)(_controlQueue.front().len() - 1))
{ {
AsyncWebLockGuard l(_lock, "AsyncWebSocketClient::_runQueue()"); //l.unlock();
_controlQueue.front().send(_client);
while (!_messageQueue.empty() && _messageQueue.front().get().finished()) }
{ else if (!_messageQueue.empty() && _messageQueue.front().get().betweenFrames() && webSocketSendFrameWindow(_client))
_messageQueue.pop(); {
} //l.unlock();
_messageQueue.front().get().send(_client);
if (!_controlQueue.empty() && (_messageQueue.empty() || _messageQueue.front().get().betweenFrames()) && webSocketSendFrameWindow(_client) > (size_t)(_controlQueue.front().len() - 1))
{
l.unlock();
_controlQueue.front().send(_client);
}
else if (!_messageQueue.empty() && _messageQueue.front().get().betweenFrames() && webSocketSendFrameWindow(_client))
{
l.unlock();
_messageQueue.front().get().send(_client);
}
} }
Serial.printf("AsyncWebSocketClient::_runQueue this=0x%llx task=0x%llx %s\r\n", uint64_t(this), uint64_t(xTaskGetCurrentTaskHandle()), pcTaskGetTaskName(xTaskGetCurrentTaskHandle()));
} }
bool AsyncWebSocketClient::queueIsFull() const bool AsyncWebSocketClient::queueIsFull() const

View File

@ -11,49 +11,49 @@
class AsyncWebLock class AsyncWebLock
{ {
private: private:
SemaphoreHandle_t _lock; SemaphoreHandle_t _lock;
mutable TaskHandle_t _lockedBy{}; mutable TaskHandle_t _lockedBy{};
mutable const char *_lastLockerName; mutable const char *_lastLockerName;
public: public:
const char * const lockName; const char * const lockName;
AsyncWebLock(const char *_lockName) : AsyncWebLock(const char *_lockName) :
lockName{_lockName} lockName{_lockName}
{ {
_lock = xSemaphoreCreateBinary(); _lock = xSemaphoreCreateBinary();
_lockedBy = NULL; _lockedBy = NULL;
xSemaphoreGive(_lock); xSemaphoreGive(_lock);
}
~AsyncWebLock() {
vSemaphoreDelete(_lock);
}
bool lock(const char *lockerName) const {
const auto currentTask = xTaskGetCurrentTaskHandle();
if (_lockedBy != currentTask) {
while (true)
{
Serial.printf("AsyncWebLock::lock this=0x%llx name=%s locker=%s task=0x%llx %s\r\n", uint64_t(this), lockName, lockerName, uint64_t(currentTask), pcTaskGetTaskName(currentTask));
if (xSemaphoreTake(_lock, 200 / portTICK_PERIOD_MS))
break;
else
Serial.printf("AsyncWebLock::lock FAILED this=0x%llx name=%s locker=%s task=0x%llx %s lastLockedBy=%s\r\n", uint64_t(this), lockName, lockerName, uint64_t(currentTask), pcTaskGetTaskName(xTaskGetCurrentTaskHandle()), _lastLockerName);
}
_lockedBy = currentTask;
_lastLockerName = lockerName;
return true;
} }
return false;
}
void unlock(const char *lockerName) const { ~AsyncWebLock() {
Serial.printf("AsyncWebLock::unlock this=0x%llx name=%s locker=%s task=0x%llx %s\r\n", uint64_t(this), lockName, lockerName, uint64_t(xTaskGetCurrentTaskHandle()), pcTaskGetTaskName(xTaskGetCurrentTaskHandle())); vSemaphoreDelete(_lock);
_lockedBy = NULL; }
_lastLockerName = NULL;
xSemaphoreGive(_lock); bool lock(const char *lockerName) const {
} const auto currentTask = xTaskGetCurrentTaskHandle();
if (_lockedBy != currentTask) {
while (true)
{
Serial.printf("AsyncWebLock::lock this=0x%llx name=%s locker=%s task=0x%llx %s\r\n", uint64_t(this), lockName, lockerName, uint64_t(currentTask), pcTaskGetTaskName(currentTask));
if (xSemaphoreTake(_lock, 200 / portTICK_PERIOD_MS))
break;
else
Serial.printf("AsyncWebLock::lock FAILED this=0x%llx name=%s locker=%s task=0x%llx %s lastLockedBy=%s\r\n", uint64_t(this), lockName, lockerName, uint64_t(currentTask), pcTaskGetTaskName(xTaskGetCurrentTaskHandle()), _lastLockerName);
}
_lockedBy = currentTask;
_lastLockerName = lockerName;
return true;
}
return false;
}
void unlock(const char *lockerName) const {
Serial.printf("AsyncWebLock::unlock this=0x%llx name=%s locker=%s task=0x%llx %s\r\n", uint64_t(this), lockName, lockerName, uint64_t(xTaskGetCurrentTaskHandle()), pcTaskGetTaskName(xTaskGetCurrentTaskHandle()));
_lockedBy = NULL;
_lastLockerName = NULL;
xSemaphoreGive(_lock);
}
}; };
#else #else