Skip to content

Commit 553e46f

Browse files
ci(pre-commit): Apply automatic fixes
1 parent 43e2e28 commit 553e46f

File tree

4 files changed

+66
-56
lines changed

4 files changed

+66
-56
lines changed

src/ESPAsyncWebServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ class AsyncWebServerResponse {
14011401
* @brief write next portion of response data to send buffs
14021402
* this method (re)fills tcp send buffers, it could be called either at will
14031403
* or from a tcp_recv/tcp_poll callbacks from AsyncTCP
1404-
*
1404+
*
14051405
* @param request - used to access client object
14061406
* @param len - size of acknowledged data from the remote side (TCP window update, not TCP ack!)
14071407
* @param time - time passed between last sent and received packet

src/WebRequest.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,61 +33,61 @@ AsyncWebServerRequest::AsyncWebServerRequest(AsyncWebServer *s, AsyncClient *c)
3333
[](void *r, AsyncClient *c, int8_t error) {
3434
(void)c;
3535
// async_ws_log_e("AsyncWebServerRequest::_onError");
36-
static_cast<AsyncWebServerRequest*>(r)->_onError(error);
36+
static_cast<AsyncWebServerRequest *>(r)->_onError(error);
3737
},
3838
this
3939
);
4040
c->onAck(
4141
[](void *r, AsyncClient *c, size_t len, uint32_t time) {
4242
(void)c;
4343
// async_ws_log_e("AsyncWebServerRequest::_onAck");
44-
static_cast<AsyncWebServerRequest*>(r)->_onAck(len, time);
44+
static_cast<AsyncWebServerRequest *>(r)->_onAck(len, time);
4545
},
4646
this
4747
);
4848
c->onDisconnect(
4949
[](void *r, AsyncClient *c) {
5050
// async_ws_log_e("AsyncWebServerRequest::_onDisconnect");
51-
static_cast<AsyncWebServerRequest*>(r)->_onDisconnect();
51+
static_cast<AsyncWebServerRequest *>(r)->_onDisconnect();
5252
},
5353
this
5454
);
5555
c->onTimeout(
5656
[](void *r, AsyncClient *c, uint32_t time) {
5757
(void)c;
5858
// async_ws_log_e("AsyncWebServerRequest::_onTimeout");
59-
static_cast<AsyncWebServerRequest*>(r)->_onTimeout(time);
59+
static_cast<AsyncWebServerRequest *>(r)->_onTimeout(time);
6060
},
6161
this
6262
);
6363
c->onData(
6464
[](void *r, AsyncClient *c, void *buf, size_t len) {
6565
(void)c;
6666
// async_ws_log_e("AsyncWebServerRequest::_onData");
67-
static_cast<AsyncWebServerRequest*>(r)->_onData(buf, len);
67+
static_cast<AsyncWebServerRequest *>(r)->_onData(buf, len);
6868
},
6969
this
7070
);
7171
c->onPoll(
7272
[](void *r, AsyncClient *c) {
7373
(void)c;
7474
// async_ws_log_e("AsyncWebServerRequest::_onPoll");
75-
static_cast<AsyncWebServerRequest*>(r)->_onPoll();
75+
static_cast<AsyncWebServerRequest *>(r)->_onPoll();
7676
},
7777
this
7878
);
7979
}
8080

8181
AsyncWebServerRequest::~AsyncWebServerRequest() {
82-
if (_client){
82+
if (_client) {
8383
// usually it is _client's disconnect triggers object destruct, but for completeness we define behavior
8484
// if for some reason *this will be desturcted while client is still connected
8585
_client->onDisconnect(nullptr);
8686
delete _client;
8787
_client = nullptr;
8888
}
8989

90-
if (_response){
90+
if (_response) {
9191
delete _response;
9292
_response = nullptr;
9393
}
@@ -224,13 +224,15 @@ void AsyncWebServerRequest::_onPoll() {
224224

225225
void AsyncWebServerRequest::_onAck(size_t len, uint32_t time) {
226226
// os_printf("a:%u:%u\n", len, time);
227-
if (!_response) return;
227+
if (!_response) {
228+
return;
229+
}
228230

229231
if (!_response->_finished()) {
230232
_response->_ack(this, len, time);
231233
// recheck if response has just completed, close connection
232234
if (_response->_finished()) {
233-
_client->close(); // this will trigger _onDisconnect() and object destruction
235+
_client->close(); // this will trigger _onDisconnect() and object destruction
234236
}
235237
}
236238
}

src/WebResponseImpl.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class AsyncBasicResponse : public AsyncWebServerResponse {
3535
AsyncBasicResponse(int code, const String &contentType, const String &content = emptyString)
3636
: AsyncBasicResponse(code, contentType.c_str(), content.c_str()) {}
3737
void _respond(AsyncWebServerRequest *request) override final;
38-
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time) override final { return write_send_buffs(request, len, time); };
38+
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time) override final {
39+
return write_send_buffs(request, len, time);
40+
};
3941
bool _sourceValid() const override final {
4042
return true;
4143
}
@@ -45,14 +47,13 @@ class AsyncBasicResponse : public AsyncWebServerResponse {
4547
* @brief write next portion of response data to send buffs
4648
* this method (re)fills tcp send buffers, it could be called either at will
4749
* or from a tcp_recv/tcp_poll callbacks from AsyncTCP
48-
*
50+
*
4951
* @param request - used to access client object
5052
* @param len - size of acknowledged data from the remote side (TCP window update, not TCP ack!)
5153
* @param time - time passed between last sent and received packet
5254
* @return size_t amount of response data placed to TCP send buffs for delivery (defined by sdkconfig value CONFIG_LWIP_TCP_SND_BUF_DEFAULT)
5355
*/
5456
size_t write_send_buffs(AsyncWebServerRequest *request, size_t len, uint32_t time);
55-
5657
};
5758

5859
class AsyncAbstractResponse : public AsyncWebServerResponse {
@@ -73,7 +74,7 @@ class AsyncAbstractResponse : public AsyncWebServerResponse {
7374
// so by gaining performance in one place, we'll lose it in another.
7475
std::vector<uint8_t> _cache;
7576
// intermediate buffer to copy outbound data to, also it will keep pending data between _send calls
76-
std::unique_ptr< std::array<uint8_t, ASYNC_RESPONCE_BUFF_SIZE> > _send_buffer;
77+
std::unique_ptr<std::array<uint8_t, ASYNC_RESPONCE_BUFF_SIZE> > _send_buffer;
7778
// buffer data size specifiers
7879
size_t _send_buffer_offset{0}, _send_buffer_len{0};
7980
size_t _readDataFromCacheOrContent(uint8_t *data, const size_t len);
@@ -85,7 +86,7 @@ class AsyncAbstractResponse : public AsyncWebServerResponse {
8586
* @brief write next portion of response data to send buffs
8687
* this method (re)fills tcp send buffers, it could be called either at will
8788
* or from a tcp_recv/tcp_poll callbacks from AsyncTCP
88-
*
89+
*
8990
* @param request - used to access client object
9091
* @param len - size of acknowledged data from the remote side (TCP window update, not TCP ack!)
9192
* @param time - time passed between last sent and received packet
@@ -97,7 +98,9 @@ class AsyncAbstractResponse : public AsyncWebServerResponse {
9798
AsyncAbstractResponse(AwsTemplateProcessor callback = nullptr);
9899
virtual ~AsyncAbstractResponse() {}
99100
void _respond(AsyncWebServerRequest *request) override final;
100-
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time) override final { return write_send_buffs(request, len, time); };
101+
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time) override final {
102+
return write_send_buffs(request, len, time);
103+
};
101104
virtual bool _sourceValid() const {
102105
return false;
103106
}

src/WebResponses.cpp

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ size_t AsyncBasicResponse::write_send_buffs(AsyncWebServerRequest *request, size
286286
size_t const pcb_written = request->client()->add(_assembled_headers.c_str() + _writtenHeadersLength, _assembled_headers.length() - _writtenHeadersLength);
287287
_writtenLength += pcb_written;
288288
_writtenHeadersLength += pcb_written;
289-
if (_writtenHeadersLength < _assembled_headers.length()){
289+
if (_writtenHeadersLength < _assembled_headers.length()) {
290290
// we were not able to fit all headers in current buff, send this part here and return later for the rest
291-
if (!request->client()->send()){
291+
if (!request->client()->send()) {
292292
// something is wrong, what should we do here?
293293
request->client()->close();
294294
return 0;
@@ -303,10 +303,10 @@ size_t AsyncBasicResponse::write_send_buffs(AsyncWebServerRequest *request, size
303303

304304
if (_state == RESPONSE_CONTENT) {
305305
size_t const pcb_written = request->client()->write(_content.c_str() + _sentLength, _content.length() - _sentLength);
306-
_writtenLength += pcb_written; // total written data (hdrs + body)
307-
_sentLength += pcb_written; // body written data
308-
payloadlen += pcb_written; // data writtent in current buff
309-
if (_sentLength >= _content.length()){
306+
_writtenLength += pcb_written; // total written data (hdrs + body)
307+
_sentLength += pcb_written; // body written data
308+
payloadlen += pcb_written; // data writtent in current buff
309+
if (_sentLength >= _content.length()) {
310310
// we've just sent all the (remainder) data in current buff, complete the response
311311
_state = RESPONSE_END;
312312
}
@@ -322,7 +322,7 @@ size_t AsyncBasicResponse::write_send_buffs(AsyncWebServerRequest *request, size
322322

323323
/*
324324
* Abstract Response
325-
*
325+
*
326326
*/
327327
AsyncAbstractResponse::AsyncAbstractResponse(AwsTemplateProcessor callback) : _callback(callback) {
328328
// In case of template processing, we're unable to determine real response size
@@ -363,7 +363,7 @@ size_t AsyncAbstractResponse::write_send_buffs(AsyncWebServerRequest *request, s
363363
_in_flight -= std::min(len, _in_flight);
364364
}
365365

366-
if (_chunked || !_sendContentLength || (_sentLength > CONFIG_LWIP_TCP_WND_DEFAULT) ) {
366+
if (_chunked || !_sendContentLength || (_sentLength > CONFIG_LWIP_TCP_WND_DEFAULT)) {
367367
if (!_in_flight_credit || (ASYNC_RESPONCE_BUFF_SIZE > request->client()->space())) {
368368
// async_ws_log_d("defer user call in_flight:%u, tcpwin:%u", _in_flight, request->client()->space());
369369
// take the credit back since we are ignoring this ack and rely on other inflight data acks
@@ -386,13 +386,13 @@ size_t AsyncAbstractResponse::write_send_buffs(AsyncWebServerRequest *request, s
386386
size_t const pcb_written = request->client()->add(_assembled_headers.c_str() + _writtenHeadersLength, _assembled_headers.length() - _writtenHeadersLength);
387387
_writtenLength += pcb_written;
388388
_writtenHeadersLength += pcb_written;
389-
if (_writtenHeadersLength < _assembled_headers.length()){
390-
// we were not able to fit all headers in current buff, send this part here and return later for the rest
391-
#if ASYNCWEBSERVER_USE_CHUNK_INFLIGHT
389+
if (_writtenHeadersLength < _assembled_headers.length()) {
390+
// we were not able to fit all headers in current buff, send this part here and return later for the rest
391+
#if ASYNCWEBSERVER_USE_CHUNK_INFLIGHT
392392
_in_flight += pcb_written;
393393
--_in_flight_credit; // take a credit
394-
#endif
395-
if (!request->client()->send()){
394+
#endif
395+
if (!request->client()->send()) {
396396
// something is wrong, what should we do here?
397397
request->client()->close();
398398
return 0;
@@ -408,82 +408,87 @@ size_t AsyncAbstractResponse::write_send_buffs(AsyncWebServerRequest *request, s
408408
// send content body
409409
if (_state == RESPONSE_CONTENT) {
410410
do {
411-
if (_send_buffer_len && _send_buffer){
411+
if (_send_buffer_len && _send_buffer) {
412412
// data is pending in buffer from a previous call or previous iteration
413-
size_t const added_len = request->client()->add(reinterpret_cast<char*>(_send_buffer->data() + _send_buffer_offset), _send_buffer_len - _send_buffer_offset);
414-
if (added_len != _send_buffer_len - _send_buffer_offset){
413+
size_t const added_len =
414+
request->client()->add(reinterpret_cast<char *>(_send_buffer->data() + _send_buffer_offset), _send_buffer_len - _send_buffer_offset);
415+
if (added_len != _send_buffer_len - _send_buffer_offset) {
415416
// we were not able to add entire buffer's content to tcp buffs, leave it for later
416417
// (this should not happen normally unless connection's TCP window suddenly changed from remote or mem pressure)
417418
_send_buffer_offset += added_len;
418419
break;
419-
} else
420-
_send_buffer_len = _send_buffer_offset = 0; // consider buffer empty
420+
} else {
421+
_send_buffer_len = _send_buffer_offset = 0; // consider buffer empty
422+
}
421423
payloadlen += added_len;
422424
}
423425

424426
auto tcp_win = request->client()->space();
425-
if (tcp_win == 0 || _state == RESPONSE_END)
427+
if (tcp_win == 0 || _state == RESPONSE_END) {
426428
break; // no room left or no more data
429+
}
427430

428431
if ((_chunked || !_sendContentLength) && (tcp_win < CONFIG_LWIP_TCP_MSS / 2)) {
429432
// available window size is not enough to send a new chunk sized half of tcp mss, let's wait for better chance and reduce pressure to AsyncTCP's event Q
430433
break;
431434
}
432435

433-
if (!_send_buffer){
436+
if (!_send_buffer) {
434437
auto p = new (std::nothrow) std::array<uint8_t, ASYNC_RESPONCE_BUFF_SIZE>;
435-
if (p){
438+
if (p) {
436439
_send_buffer.reset(p);
437440
_send_buffer_len = _send_buffer_offset = 0;
438-
} else
439-
break; // OOM
441+
} else {
442+
break; // OOM
443+
}
440444
}
441445

442446
if (_chunked) {
443447
// HTTP 1.1 allows leading zeros in chunk length. Or spaces may be added.
444448
// See https://datatracker.ietf.org/doc/html/rfc9112#section-7.1
445-
size_t const readLen = _fillBufferAndProcessTemplates(_send_buffer->data() + 6, std::min(_send_buffer->size(), tcp_win) - 8); // reserve 8 bytes for chunk size data
449+
size_t const readLen =
450+
_fillBufferAndProcessTemplates(_send_buffer->data() + 6, std::min(_send_buffer->size(), tcp_win) - 8); // reserve 8 bytes for chunk size data
446451
if (readLen != RESPONSE_TRY_AGAIN) {
447-
sprintf(reinterpret_cast<char*>(_send_buffer->data()), "%04x\r\n", readLen); // print chunk size in buffer
452+
sprintf(reinterpret_cast<char *>(_send_buffer->data()), "%04x\r\n", readLen); // print chunk size in buffer
448453
_send_buffer->at(readLen + 6) = '\r';
449454
_send_buffer->at(readLen + 7) = '\n';
450-
_send_buffer_len += readLen + 8; // set buffers's size to match added data
451-
_sentLength += readLen; // data is not sent yet, but we won't get a chance to count this later properly for chunked data
452-
if (!readLen){
455+
_send_buffer_len += readLen + 8; // set buffers's size to match added data
456+
_sentLength += readLen; // data is not sent yet, but we won't get a chance to count this later properly for chunked data
457+
if (!readLen) {
453458
// last chunk?
454459
_state = RESPONSE_END;
455460
}
456461
}
457462
} else {
458463
size_t const readLen = _fillBufferAndProcessTemplates(_send_buffer->data(), std::min(_send_buffer->size(), tcp_win));
459-
if (readLen == 0){
464+
if (readLen == 0) {
460465
// no more data to send
461466
_state = RESPONSE_END;
462467
} else if (readLen != RESPONSE_TRY_AGAIN) {
463-
_send_buffer_len += readLen; // set buffers's size to match added data
464-
_sentLength += readLen; // data is not sent yet, but we need it to uderstand that it would be last block
465-
if (_sendContentLength && (_sentLength == _contentLength)){
468+
_send_buffer_len += readLen; // set buffers's size to match added data
469+
_sentLength += readLen; // data is not sent yet, but we need it to uderstand that it would be last block
470+
if (_sendContentLength && (_sentLength == _contentLength)) {
466471
// it was last piece of content
467472
_state = RESPONSE_END;
468473
}
469474
}
470475
}
471-
} while(_send_buffer_len); // go on till we have something in buffer pending to send
476+
} while (_send_buffer_len); // go on till we have something in buffer pending to send
472477

473478
// execute sending whatever we have in sock buffs now
474479
request->client()->send();
475480
_writtenLength += payloadlen;
476-
#if ASYNCWEBSERVER_USE_CHUNK_INFLIGHT
481+
#if ASYNCWEBSERVER_USE_CHUNK_INFLIGHT
477482
_in_flight += payloadlen;
478483
--_in_flight_credit; // take a credit
479-
#endif
480-
if (_send_buffer_len == 0){
484+
#endif
485+
if (_send_buffer_len == 0) {
481486
// buffer empty, we can release mem, otherwise need to keep it till next run (should not happen under normal conditions)
482487
_send_buffer.reset();
483488
}
484489
return payloadlen;
485-
} // (_state == RESPONSE_CONTENT)
486-
490+
} // (_state == RESPONSE_CONTENT)
491+
487492
// implicit check
488493
if (_state == RESPONSE_WAIT_ACK) {
489494
// we do not need to wait for any acks actually if we won't send any more data,
@@ -517,7 +522,7 @@ size_t AsyncAbstractResponse::_fillBufferAndProcessTemplates(uint8_t *data, size
517522
// Now we've read 'len' bytes, either from cache or from file
518523
// Search for template placeholders
519524
uint8_t *pTemplateStart = data;
520-
while ((pTemplateStart < &data[len]) && (pTemplateStart = (uint8_t *)memchr(pTemplateStart, TEMPLATE_PLACEHOLDER, &data[len - 1] - pTemplateStart + 1)) ) {
525+
while ((pTemplateStart < &data[len]) && (pTemplateStart = (uint8_t *)memchr(pTemplateStart, TEMPLATE_PLACEHOLDER, &data[len - 1] - pTemplateStart + 1))) {
521526
// data[0] ... data[len - 1]
522527
uint8_t *pTemplateEnd =
523528
(pTemplateStart < &data[len - 1]) ? (uint8_t *)memchr(pTemplateStart + 1, TEMPLATE_PLACEHOLDER, &data[len - 1] - pTemplateStart) : nullptr;

0 commit comments

Comments
 (0)