Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

Commit

Permalink
SSE: Make SSE_MAX_QUEUED_MESSAGES configurable and renamed public _wr…
Browse files Browse the repository at this point in the history
…ite => write
  • Loading branch information
mathieucarbou committed Jan 25, 2024
1 parent dba25ab commit 0d96aac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/AsyncEventSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void AsyncEventSourceClient::close(){
_client->close();
}

void AsyncEventSourceClient::_write(const char * message, size_t len){
void AsyncEventSourceClient::write(const char * message, size_t len){
_queueMessage(new AsyncEventSourceMessage(message, len));
}

Expand Down Expand Up @@ -344,7 +344,7 @@ void AsyncEventSource::send(
AsyncWebLockGuard l(_client_queue_lock);
for(const auto &c: _clients){
if(c->connected()) {
c->_write(ev.c_str(), ev.length());
c->write(ev.c_str(), ev.length());
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions src/AsyncEventSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
#include <Arduino.h>
#ifdef ESP32
#include <AsyncTCP.h>
#ifndef SSE_MAX_QUEUED_MESSAGES
#define SSE_MAX_QUEUED_MESSAGES 32
#endif
#else
#include <ESPAsyncTCP.h>
#ifndef SSE_MAX_QUEUED_MESSAGES
#define SSE_MAX_QUEUED_MESSAGES 8
#endif
#endif

#include <ESPAsyncWebServer.h>

#include "AsyncWebSynchronization.h"
Expand All @@ -53,11 +58,11 @@ typedef std::function<bool(AsyncWebServerRequest *request)> ArAuthorizeConnectHa

class AsyncEventSourceMessage {
private:
uint8_t * _data;
uint8_t * _data;
size_t _len;
size_t _sent;
//size_t _ack;
size_t _acked;
size_t _acked;
public:
AsyncEventSourceMessage(const char * data, size_t len);
~AsyncEventSourceMessage();
Expand Down Expand Up @@ -85,15 +90,15 @@ class AsyncEventSourceClient {

AsyncClient* client(){ return _client; }
void close();
void write(const char * message, size_t len);
void send(const char *message, const char *event=NULL, uint32_t id=0, uint32_t reconnect=0);
bool connected() const { return (_client != NULL) && _client->connected(); }
uint32_t lastId() const { return _lastId; }
size_t packetsWaiting() const;

void _write(const char * message, size_t len);
//system callbacks (do not call)
void _onAck(size_t len, uint32_t time);
void _onPoll();
void _onPoll();
void _onTimeout(uint32_t time);
void _onDisconnect();
};
Expand All @@ -106,7 +111,7 @@ class AsyncEventSource: public AsyncWebHandler {
// since simultaneous access from different tasks is possible
AsyncWebLock _client_queue_lock;
ArEventHandlerFunction _connectcb;
ArAuthorizeConnectHandler _authorizeConnectHandler;
ArAuthorizeConnectHandler _authorizeConnectHandler;
public:
AsyncEventSource(const String& url);
~AsyncEventSource();
Expand All @@ -116,7 +121,8 @@ class AsyncEventSource: public AsyncWebHandler {
void onConnect(ArEventHandlerFunction cb);
void authorizeConnect(ArAuthorizeConnectHandler cb);
void send(const char *message, const char *event=NULL, uint32_t id=0, uint32_t reconnect=0);
size_t count() const; //number clients connected
// number of clients connected
size_t count() const;
size_t avgPacketsWaiting() const;

//system callbacks (do not call)
Expand Down

0 comments on commit 0d96aac

Please sign in to comment.