Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/AsyncWebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ class AsyncWebSocketClient {
//data packets
void message(AsyncWebSocketMessage *message){ _queueMessage(message); }
bool queueIsFull();
size_t queueLength() { //added by ewowi
return _messageQueue.length();
}
Comment on lines +212 to +214
Copy link

@mathieucarbou mathieucarbou Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a great idea for these reasons:

  1. Traversal is O(N), not O(1) like with std::list on c++ >= 11
  2. No mutex protection to block concurrent access

The internal structure (LinkedList) should be changed IMO because it is not efficient.

In our community maintained fork (https://github.com/mathieucarbou/ESPAsyncWebServer), which is far more evolved than this fork, we have implemented it like this:

size_t AsyncWebSocketClient::queueLen() const {
#ifdef ESP32
  std::lock_guard<std::mutex> lock(_lock);
#endif

  return _messageQueue.size();
}

_messageQueue being a std::list


size_t printf(const char *format, ...) __attribute__ ((format (printf, 2, 3)));
#ifndef ESP32
Expand Down