@@ -102,7 +102,6 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
102
102
void sendDataWs (AsyncWebSocketClient * client)
103
103
{
104
104
if (!ws.count ()) return ;
105
- AsyncWebSocketMessageBuffer * buffer;
106
105
107
106
if (!requestJSONBufferLock (12 )) {
108
107
if (client) {
@@ -129,7 +128,7 @@ void sendDataWs(AsyncWebSocketClient * client)
129
128
return ;
130
129
}
131
130
#endif
132
- buffer = ws. makeBuffer (len); // will not allocate correct memory sometimes on ESP8266
131
+ AsyncWebSocketSharedBuffer buffer (len); // will not allocate correct memory sometimes on ESP8266
133
132
#ifdef ESP8266
134
133
size_t heap2 = ESP.getFreeHeap ();
135
134
DEBUG_PRINT (F (" heap " )); DEBUG_PRINTLN (ESP.getFreeHeap ());
@@ -141,23 +140,18 @@ void sendDataWs(AsyncWebSocketClient * client)
141
140
DEBUG_PRINTLN (F (" WS buffer allocation failed." ));
142
141
ws.closeAll (1013 ); // code 1013 = temporary overload, try again later
143
142
ws.cleanupClients (0 ); // disconnect all clients to release memory
144
- ws._cleanBuffers ();
145
143
return ; // out of memory
146
144
}
147
-
148
- buffer->lock ();
149
- serializeJson (*pDoc, (char *)buffer->get (), len);
145
+ serializeJson (*pDoc, (char *)buffer.data (), len);
150
146
151
147
DEBUG_PRINT (F (" Sending WS data " ));
152
148
if (client) {
153
- client->text (buffer);
149
+ client->text (std::move ( buffer) );
154
150
DEBUG_PRINTLN (F (" to a single client." ));
155
151
} else {
156
152
ws.textAll (buffer);
157
153
DEBUG_PRINTLN (F (" to multiple clients." ));
158
154
}
159
- buffer->unlock ();
160
- ws._cleanBuffers ();
161
155
162
156
releaseJSONBufferLock ();
163
157
}
@@ -187,11 +181,10 @@ bool sendLiveLedsWs(uint32_t wsClient)
187
181
#endif
188
182
size_t bufSize = pos + (used/n)*3 ;
189
183
190
- AsyncWebSocketMessageBuffer * wsBuf = ws. makeBuffer (bufSize);
184
+ AsyncWebSocketSharedBuffer wsBuf (bufSize);
191
185
if (!wsBuf) return false ; // out of memory
192
- uint8_t * buffer = wsBuf-> get ( );
186
+ uint8_t * buffer = reinterpret_cast < uint8_t *>(wsBuf. data () );
193
187
if (!buffer) return false ; // out of memory
194
- wsBuf->lock (); // protect buffer from being cleaned by another WS instance
195
188
buffer[0 ] = ' L' ;
196
189
buffer[1 ] = 1 ; // version
197
190
@@ -218,9 +211,7 @@ bool sendLiveLedsWs(uint32_t wsClient)
218
211
buffer[pos++] = scale8 (qadd8 (w, b), strip.getBrightness ()); // B
219
212
}
220
213
221
- wsc->binary (wsBuf);
222
- wsBuf->unlock (); // un-protect buffer
223
- ws._cleanBuffers ();
214
+ wsc->binary (std::move (wsBuf));
224
215
return true ;
225
216
}
226
217
0 commit comments