Skip to content

Commit e030dd0

Browse files
committed
work around arduino-esp32 bug espressif/arduino-esp32#828
thanks to @Uksa007 for pointing that out.
1 parent eb67766 commit e030dd0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/AudioFileSourceHTTPStream.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ bool AudioFileSourceHTTPStream::open(const char *url)
4141
http.setReuse(true);
4242
int code = http.GET();
4343
if (code != HTTP_CODE_OK) {
44+
http.getStream().flush(); // work around https://github.com/espressif/arduino-esp32/issues/828
4445
http.end();
4546
cb.st(STATUS_HTTPFAIL, PSTR("Can't open HTTP request"));
4647
return false;
@@ -53,6 +54,7 @@ bool AudioFileSourceHTTPStream::open(const char *url)
5354

5455
AudioFileSourceHTTPStream::~AudioFileSourceHTTPStream()
5556
{
57+
http.getStream().flush(); // work around https://github.com/espressif/arduino-esp32/issues/828
5658
http.end();
5759
}
5860

@@ -79,6 +81,7 @@ uint32_t AudioFileSourceHTTPStream::readInternal(void *data, uint32_t len, bool
7981
retry:
8082
if (!http.connected()) {
8183
cb.st(STATUS_DISCONNECTED, PSTR("Stream disconnected"));
84+
http.getStream().flush(); // work around https://github.com/espressif/arduino-esp32/issues/828
8285
http.end();
8386
for (int i = 0; i < reconnectTries; i++) {
8487
char buff[32];
@@ -110,6 +113,7 @@ uint32_t AudioFileSourceHTTPStream::readInternal(void *data, uint32_t len, bool
110113
size_t avail = stream->available();
111114
if (!nonBlock && !avail) {
112115
cb.st(STATUS_NODATA, PSTR("No stream data available"));
116+
http.getStream().flush(); // work around https://github.com/espressif/arduino-esp32/issues/828
113117
http.end();
114118
goto retry;
115119
}
@@ -130,6 +134,7 @@ bool AudioFileSourceHTTPStream::seek(int32_t pos, int dir)
130134

131135
bool AudioFileSourceHTTPStream::close()
132136
{
137+
http.getStream().flush(); // work around https://github.com/espressif/arduino-esp32/issues/828
133138
http.end();
134139
return true;
135140
}

src/AudioFileSourceICYStream.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ bool AudioFileSourceICYStream::open(const char *url)
4444
http.setReuse(true);
4545
int code = http.GET();
4646
if (code != HTTP_CODE_OK) {
47+
http.getStream().flush(); // work around https://github.com/espressif/arduino-esp32/issues/828
4748
http.end();
4849
cb.st(STATUS_HTTPFAIL, PSTR("Can't open HTTP request"));
4950
return false;
@@ -63,6 +64,7 @@ bool AudioFileSourceICYStream::open(const char *url)
6364

6465
AudioFileSourceICYStream::~AudioFileSourceICYStream()
6566
{
67+
http.getStream().flush(); // work around https://github.com/espressif/arduino-esp32/issues/828
6668
http.end();
6769
}
6870

@@ -123,6 +125,7 @@ uint32_t AudioFileSourceICYStream::readInternal(void *data, uint32_t len, bool n
123125
retry:
124126
if (!http.connected()) {
125127
cb.st(STATUS_DISCONNECTED, PSTR("Stream disconnected"));
128+
http.getStream().flush(); // work around https://github.com/espressif/arduino-esp32/issues/828
126129
http.end();
127130
for (int i = 0; i < reconnectTries; i++) {
128131
char buff[32];
@@ -154,6 +157,7 @@ uint32_t AudioFileSourceICYStream::readInternal(void *data, uint32_t len, bool n
154157
size_t avail = stream->available();
155158
if (!nonBlock && !avail) {
156159
cb.st(STATUS_NODATA, PSTR("No stream data available"));
160+
http.getStream().flush(); // work around https://github.com/espressif/arduino-esp32/issues/828
157161
http.end();
158162
goto retry;
159163
}

0 commit comments

Comments
 (0)