Skip to content

Commit

Permalink
Fix network flushes
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed May 29, 2024
1 parent 27c35be commit b88ec44
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 15 deletions.
3 changes: 2 additions & 1 deletion tasmota/tasmota_support/support_device_groups.ino
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ void DeviceGroupsStart()

void DeviceGroupsStop()
{
#ifdef ESP8266
device_groups_udp.flush();
#ifdef ESP32
#else
device_groups_udp.clear(); // New with core3. Does what flush() did in core2;
#endif
device_groups_up = false;
Expand Down
8 changes: 3 additions & 5 deletions tasmota/tasmota_support/support_udp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ bool UdpDisconnect(void)
{
if (udp_connected) {
// flush any outgoing packet
PortUdp.flush(); // Does nothing in core3
#ifdef ESP32
PortUdp.clear(); // New with core3. Does what flush() did in core2;
#endif
#ifdef ESP8266
PortUdp.flush();
UdpCtx.disconnect();
#else
PortUdp.clear(); // New with core3. Does what flush() did in core2;
#endif
#ifdef USE_DEVICE_GROUPS
// stop
Expand Down Expand Up @@ -133,7 +132,6 @@ void PollUdp(void)

int32_t len = PortUdp.read(packet_buffer, UDP_BUFFER_SIZE -1);
packet_buffer[len] = 0;
// PortUdp.flush();
PortUdp.clear(); // New with core3. Does what flush() did in core2;
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: Packet (%d/%d)"), len, pack_len);
#endif // ESP32
Expand Down
6 changes: 5 additions & 1 deletion tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,11 @@ void WSSend(int code, int ctype, const String& content)
**********************************************************************************************/

void WSContentBegin(int code, int ctype) {
#ifdef ESP8266
Webserver->client().flush();
#else
Webserver->client().clear(); // New with core3. Does what flush() did in core2;
#endif
WSHeaderSend();
Webserver->setContentLength(CONTENT_LENGTH_UNKNOWN);
WSSend(code, ctype, ""); // Signal start of chunked content
Expand Down Expand Up @@ -3085,7 +3089,7 @@ void HandlePreflightRequest(void)
// return a simple status page as text/plain code 200
static void WSReturnSimpleString(const char *msg) {
if (nullptr == msg) { msg = ""; }
Webserver->client().flush();
Webserver->client().clear(); // New with core3. Does what flush() did in core2;
WSHeaderSend();
Webserver->send(200, "text/plain", msg);
}
Expand Down
1 change: 0 additions & 1 deletion tasmota/tasmota_xdrv_driver/xdrv_04_light_artnet.ino
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ void ArtNetLoop(void)
uint8_t packet_buffer[WS2812_ARTNET_UDP_BUFFER_SIZE]; // buffer to hold incoming UDP/SSDP packet

packet_len = ArtNetUdp->read(packet_buffer, WS2812_ARTNET_UDP_BUFFER_SIZE);
// ArtNetUdp->flush(); // Finish reading the current packet
ArtNetUdp->clear(); // New with core3. Does what flush() did in core2;
#endif
// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: Packet %*_H (%d)"), 32, packet_buffer, packet_len);
Expand Down
10 changes: 8 additions & 2 deletions tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1386,8 +1386,9 @@ int32_t udp_call(char *url, uint32_t port, char *sbuf) {
udp.beginPacket(adr, port);
udp.write((const uint8_t*)sbuf, strlen(sbuf));
udp.endPacket();
#ifdef ESP8266
udp.flush();
#ifdef ESP32
#else
udp.clear(); // New with core3. Does what flush() did in core2;
#endif
udp.stop();
Expand All @@ -1408,8 +1409,9 @@ void Restart_globvars(void) {
void Script_Stop_UDP(void) {
if (!glob_script_mem.udp_flags.udp_used) return;
if (glob_script_mem.udp_flags.udp_connected) {
#ifdef ESP8266
glob_script_mem.Script_PortUdp.flush();
#ifdef ESP32
#else
glob_script_mem.Script_PortUdp.clear(); // New with core3. Does what flush() did in core2;
#endif
glob_script_mem.Script_PortUdp.stop();
Expand Down Expand Up @@ -6392,7 +6394,11 @@ void tmod_directModeOutput(uint32_t pin);
fvar = -1;
if (glob_script_mem.tcp_server) {
if (glob_script_mem.tcp_client.connected()) {
#ifdef ESP8266
glob_script_mem.tcp_client.flush();
#else
glob_script_mem.tcp_client.clear();
#endif
fvar = 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ extern "C" {
if (argc >= 2 && be_isint(vm, 1) && be_isstring(vm, 2)) {
int32_t httpcode = be_toint(vm, 1);
const char * mimetype = be_tostring(vm, 2);
Webserver->client().flush();
Webserver->client().clear(); // New with core3. Does what flush() did in core2;
WSHeaderSend();
Webserver->setContentLength(CONTENT_LENGTH_UNKNOWN);
Webserver->send(httpcode, mimetype, "");
Expand Down
4 changes: 4 additions & 0 deletions tasmota/tasmota_xdrv_driver/xdrv_63_modbus_bridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ void ModbusBridgeHandle(void)
client.write(modbusBridge.buffer + 2, 4); // Don't send CRC
nrOfBytes += 4;
}
#ifdef ESP8266
client.flush();
#else
client.clear(); // New with core3. Does what flush() did in core2;
#endif
AddLog(LOG_LEVEL_DEBUG, PSTR("MBS: MBRTCP from Modbus deviceAddress %d, writing %d bytes to client"), modbusBridge.buffer[0], nrOfBytes);
}
}
Expand Down
6 changes: 3 additions & 3 deletions tasmota/tasmota_xdrv_driver/xdrv_81_esp32_webcam.ino
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ void HandleImageBasic(void) {
}

if (_jpg_buf_len) {
Webserver->client().flush();
Webserver->client().clear(); // New with core3. Does what flush() did in core2;
WSHeaderSend();
Webserver->sendHeader(F("Content-disposition"), F("inline; filename=snapshot.jpg"));
Webserver->send_P(200, "image/jpeg", (char *)_jpg_buf, _jpg_buf_len);
Expand Down Expand Up @@ -925,7 +925,7 @@ void HandleWebcamMjpegTask(void) {
WcStats.clientfail++;
}
if (1 == Wc.stream_active) {
Wc.client.flush();
Wc.client.clear(); // New with core3. Does what flush() did in core2;
Wc.client.setTimeout(3);
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Start stream"));
Wc.client.print("HTTP/1.1 200 OK\r\n"
Expand Down Expand Up @@ -990,7 +990,7 @@ void HandleWebcamMjpegTask(void) {
}
if (0 == Wc.stream_active) {
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Stream exit"));
Wc.client.flush();
Wc.client.clear(); // New with core3. Does what flush() did in core2;
Wc.client.stop();
}
}
Expand Down
2 changes: 1 addition & 1 deletion tasmota/tasmota_xdrv_driver/xdrv_81_esp32_webcam_task.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ static void WCOperationTask(void *pvParameters){
WcStats.clientfail++;
}
if (1 == client->active) {
client->client.flush();
client->client.clear(); // New with core3. Does what flush() did in core2;
client->client.setTimeout(3);
#ifdef WEBCAM_DEV_DEBUG
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Start stream"));
Expand Down
4 changes: 4 additions & 0 deletions tasmota/tasmota_xsns_sensor/xsns_53_sml.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,11 @@ void sml_shift_in(uint32_t meters, uint32_t shard) {
memmove(&mp->sbuff[0], &mp->sbuff[6], mp->sbsiz - 6);
SML_Decode(meters);
if (mp->client) {
#ifdef ESP8266
mp->client->flush();
#else
mp->client->clear(); // New with core3. Does what flush() did in core2;
#endif
}
//Hexdump(mp->sbuff + 6, 10);
}
Expand Down

0 comments on commit b88ec44

Please sign in to comment.