Skip to content

Commit 1dbce42

Browse files
committed
Fix client rx timeout
- The client RX timeout is always set to 0 (disabled) in the _send() function
1 parent 615cff7 commit 1dbce42

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/ESPAsyncWebServer.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
#define ASYNCWEBSERVER_USE_CHUNK_INFLIGHT 1
4545
#endif
4646

47+
#ifndef ASYNCWEBSERVER_RX_TIMEOUT
48+
#define ASYNCWEBSERVER_RX_TIMEOUT 3 // Seconds for timeout
49+
#endif
50+
4751
class AsyncWebServer;
4852
class AsyncWebServerRequest;
4953
class AsyncWebServerResponse;
@@ -88,7 +92,7 @@ class FileOpenMode {
8892

8993
// if this value is returned when asked for data, packet will not be sent and you will be asked for data again
9094
#define RESPONSE_TRY_AGAIN 0xFFFFFFFF
91-
#define RESPONSE_STREAM_BUFFER_SIZE 1460
95+
#define RESPONSE_STREAM_BUFFER_SIZE CONFIG_TCP_MSS
9296

9397
typedef uint8_t WebRequestMethodComposite;
9498
typedef std::function<void(void)> ArDisconnectHandler;
@@ -250,6 +254,7 @@ class AsyncWebServerRequest {
250254
String _itemValue;
251255
uint8_t *_itemBuffer;
252256
size_t _itemBufferIndex;
257+
uint32_t _rx_timeout;
253258
bool _itemIsFile;
254259

255260
void _onPoll();

src/WebRequest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ AsyncWebServerRequest::AsyncWebServerRequest(AsyncWebServer *s, AsyncClient *c)
2525
: _client(c), _server(s), _handler(NULL), _response(NULL), _onDisconnectfn(NULL), _temp(), _parseState(PARSE_REQ_START), _version(0), _method(HTTP_ANY),
2626
_url(), _host(), _contentType(), _boundary(), _authorization(), _reqconntype(RCT_HTTP), _authMethod(AsyncAuthType::AUTH_NONE), _isMultipart(false),
2727
_isPlainPost(false), _expectingContinue(false), _contentLength(0), _parsedLength(0), _multiParseState(0), _boundaryPosition(0), _itemStartIndex(0),
28-
_itemSize(0), _itemName(), _itemFilename(), _itemType(), _itemValue(), _itemBuffer(0), _itemBufferIndex(0), _itemIsFile(false), _tempObject(NULL) {
28+
_itemSize(0), _itemName(), _itemFilename(), _itemType(), _itemValue(), _itemBuffer(0), _itemBufferIndex(0), _itemIsFile(false), _tempObject(NULL), _rx_timeout(ASYNCWEBSERVER_RX_TIMEOUT) {
2929
c->onError(
3030
[](void *r, AsyncClient *c, int8_t error) {
3131
(void)c;
@@ -720,7 +720,6 @@ void AsyncWebServerRequest::_send() {
720720
}
721721

722722
// here, we either have a response give nfrom user or one of the two above
723-
_client->setRxTimeout(0);
724723
_response->_respond(this);
725724
_sent = true;
726725
}
@@ -730,6 +729,7 @@ AsyncWebServerRequestPtr AsyncWebServerRequest::pause() {
730729
if (_paused) {
731730
return _this;
732731
}
732+
_rx_timeout = client()->getRxTimeout(); // backup client rx timeout
733733
client()->setRxTimeout(0);
734734
// this shared ptr will hold the request pointer until it gets destroyed following a disconnect.
735735
// this is just used as a holder providing weak observers, so the deleter is a no-op.
@@ -937,6 +937,7 @@ void AsyncWebServerRequest::send(AsyncWebServerResponse *response) {
937937
// if request was paused, we need to send the response now
938938
if (_paused) {
939939
_paused = false;
940+
_client->setRxTimeout(_rx_timeout); // restore rx timeout
940941
_send();
941942
}
942943
}

src/WebServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ AsyncWebServer::AsyncWebServer(uint16_t port) : _server(port) {
4343
if (c == NULL) {
4444
return;
4545
}
46-
c->setRxTimeout(3);
46+
c->setRxTimeout(ASYNCWEBSERVER_RX_TIMEOUT);
4747
AsyncWebServerRequest *r = new AsyncWebServerRequest((AsyncWebServer *)s, c);
4848
if (r == NULL) {
4949
c->abort();

0 commit comments

Comments
 (0)