Skip to content

Commit 4ee121f

Browse files
committed
Allow access to makeBuffer() to avoid a buffer copy and improve memory consumption
1 parent 6889de0 commit 4ee121f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/WebSerial.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,29 @@ class WebSerialClass : public Print {
114114
// The buffer is not enabled by default.
115115
void setBuffer(size_t initialCapacity);
116116

117+
#ifdef WSL_HIGH_PERF
118+
#ifdef ASYNCWEBSERVER_FORK_mathieucarbou
119+
// Expose the internal WebSocket makeBuffer to even improve memory consumption on client-side
120+
// 1. make a AsyncWebSocketMessageBuffer
121+
// 2. put the data inside
122+
// 3. send the buffer
123+
// This method avoids a buffer copy when creating the WebSocket message
124+
AsyncWebSocketMessageBuffer* makeBuffer(size_t size = 0) {
125+
if (!_ws)
126+
return nullptr;
127+
return _ws->makeBuffer(size);
128+
}
129+
130+
void send(AsyncWebSocketMessageBuffer* buffer) {
131+
if (!_ws || !buffer)
132+
return;
133+
_ws->cleanupClients(WSL_MAX_WS_CLIENTS);
134+
if (_ws->count())
135+
_ws->textAll(buffer);
136+
}
137+
#endif
138+
#endif
139+
117140
private:
118141
// Server
119142
AsyncWebServer *_server;

0 commit comments

Comments
 (0)