Convert resursive call to iterations, reduce stack usage (#120)

This commit is contained in:
Zhenyu Wu 2017-01-22 05:47:21 -05:00 committed by Me No Dev
parent 1d66bbfc77
commit 213387b88f
1 changed files with 11 additions and 1 deletions

View File

@ -96,6 +96,8 @@ AsyncWebServerRequest::~AsyncWebServerRequest(){
}
void AsyncWebServerRequest::_onData(void *buf, size_t len){
while (true) {
if(_parseState < PARSE_REQ_BODY){
// Find new line in buf
char *str = (char*)buf;
@ -112,7 +114,12 @@ void AsyncWebServerRequest::_onData(void *buf, size_t len){
_temp.concat(str);
_temp.trim();
_parseLine();
if (++i < len) _onData(str+i, len-i); // Still have more buffer to process
if (++i < len) {
// Still have more buffer to process
buf = str+i;
len-= i;
continue;
}
}
} else if(_parseState == PARSE_REQ_BODY){
if(_isMultipart){
@ -153,6 +160,9 @@ void AsyncWebServerRequest::_onData(void *buf, size_t len){
else send(501);
}
}
break;
}
}
void AsyncWebServerRequest::_onPoll(){