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

Commit 0d96aac

Browse files
committed
SSE: Make SSE_MAX_QUEUED_MESSAGES configurable and renamed public _write => write
1 parent dba25ab commit 0d96aac

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/AsyncEventSource.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void AsyncEventSourceClient::close(){
236236
_client->close();
237237
}
238238

239-
void AsyncEventSourceClient::_write(const char * message, size_t len){
239+
void AsyncEventSourceClient::write(const char * message, size_t len){
240240
_queueMessage(new AsyncEventSourceMessage(message, len));
241241
}
242242

@@ -344,7 +344,7 @@ void AsyncEventSource::send(
344344
AsyncWebLockGuard l(_client_queue_lock);
345345
for(const auto &c: _clients){
346346
if(c->connected()) {
347-
c->_write(ev.c_str(), ev.length());
347+
c->write(ev.c_str(), ev.length());
348348
}
349349
}
350350
}

src/AsyncEventSource.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@
2323
#include <Arduino.h>
2424
#ifdef ESP32
2525
#include <AsyncTCP.h>
26+
#ifndef SSE_MAX_QUEUED_MESSAGES
2627
#define SSE_MAX_QUEUED_MESSAGES 32
28+
#endif
2729
#else
2830
#include <ESPAsyncTCP.h>
31+
#ifndef SSE_MAX_QUEUED_MESSAGES
2932
#define SSE_MAX_QUEUED_MESSAGES 8
3033
#endif
34+
#endif
35+
3136
#include <ESPAsyncWebServer.h>
3237

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

5459
class AsyncEventSourceMessage {
5560
private:
56-
uint8_t * _data;
61+
uint8_t * _data;
5762
size_t _len;
5863
size_t _sent;
5964
//size_t _ack;
60-
size_t _acked;
65+
size_t _acked;
6166
public:
6267
AsyncEventSourceMessage(const char * data, size_t len);
6368
~AsyncEventSourceMessage();
@@ -85,15 +90,15 @@ class AsyncEventSourceClient {
8590

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

93-
void _write(const char * message, size_t len);
9499
//system callbacks (do not call)
95100
void _onAck(size_t len, uint32_t time);
96-
void _onPoll();
101+
void _onPoll();
97102
void _onTimeout(uint32_t time);
98103
void _onDisconnect();
99104
};
@@ -106,7 +111,7 @@ class AsyncEventSource: public AsyncWebHandler {
106111
// since simultaneous access from different tasks is possible
107112
AsyncWebLock _client_queue_lock;
108113
ArEventHandlerFunction _connectcb;
109-
ArAuthorizeConnectHandler _authorizeConnectHandler;
114+
ArAuthorizeConnectHandler _authorizeConnectHandler;
110115
public:
111116
AsyncEventSource(const String& url);
112117
~AsyncEventSource();
@@ -116,7 +121,8 @@ class AsyncEventSource: public AsyncWebHandler {
116121
void onConnect(ArEventHandlerFunction cb);
117122
void authorizeConnect(ArAuthorizeConnectHandler cb);
118123
void send(const char *message, const char *event=NULL, uint32_t id=0, uint32_t reconnect=0);
119-
size_t count() const; //number clients connected
124+
// number of clients connected
125+
size_t count() const;
120126
size_t avgPacketsWaiting() const;
121127

122128
//system callbacks (do not call)

0 commit comments

Comments
 (0)