10000 Add methods to determine Average Queue length (#509) · Rzyq-git/ESPAsyncWebServer@0101954 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0101954

Browse files
Phil Bowlesme-no-dev
authored andcommitted
Add methods to determine Average Queue length (me-no-dev#509)
* Add methods to determine Average Queue length
1 parent 4a34b46 commit 0101954

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/AsyncEventSource.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,26 @@ void AsyncEventSource::close(){
288288
}
289289
}
290290

291-
void AsyncEventSource::send(const char *message, const char *event, uint32_t id, uint32_t reconnect){
291+
// pmb fix
292+
size_t AsyncEventSource::avgPacketsWaiting() const {
292293
if(_clients.isEmpty())
293-
return;
294+
return 0;
295+
296+
size_t aql=0;
297+
uint32_t nConnectedClients=0;
298+
299+
for(const auto &c: _clients){
300+
if(c->connected()) {
301+
aql+=c->packetsWaiting();
302+
++nConnectedClients;
303+
}
304+
}
305+
// return aql / nConnectedClients;
306+
return ((aql) + (nConnectedClients/2))/(nConnectedClients); // round up
307+
}
308+
309+
void AsyncEventSource::send(const char *message, const char *event, uint32_t id, uint32_t reconnect){
310+
294311

295312
String ev = generateEventMessage(message, event, id, reconnect);
296313
for(const auto &c: _clients){

src/AsyncEventSource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class AsyncEventSourceClient {
6969
void send(const char *message, const char *event=NULL, uint32_t id=0, uint32_t reconnect=0);
7070
bool connected() const { return (_client != NULL) && _client->connected(); }
7171
uint32_t lastId() const { return _lastId; }
72+
size_t packetsWaiting() const { return _messageQueue.length(); }
7273

7374
//system callbacks (do not call)
7475
void _onAck(size_t len, uint32_t time);
@@ -91,6 +92,7 @@ class AsyncEventSource: public AsyncWebHandler {
9192
void onConnect(ArEventHandlerFunction cb);
9293
void send(const char *message, const char *event=NULL, uint32_t id=0, uint32_t reconnect=0);
9394
size_t count() const; //number clinets connected
95+
size_t avgPacketsWaiting() const;
9496

9597
//system callbacks (do not call)
9698
void _addClient(AsyncEventSourceClient * client);

0 commit comments

Comments
 (0)
0