Skip to content

Commit

Permalink
cleanup: Extract common code to function
Browse files Browse the repository at this point in the history
BFW-4517
  • Loading branch information
vorner authored and dragomirecky committed Nov 23, 2023
1 parent 47e1983 commit 454e24f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/WUI/nhttp/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ void Server::Slot::release() {
conn = nullptr;
}

void Server::Slot::forward_progress() {
while (step()) {
}
}

void Server::ConnectionSlot::release() {
state = Idle();
release_partial();
Expand Down Expand Up @@ -162,8 +167,7 @@ void Server::inject_transfer(altcp_pcb *conn, pbuf *data, uint16_t data_offset,
dest->pbuf_processed = data_offset;
}

while (transfer_slot.step()) {
}
transfer_slot.forward_progress();
}

void Server::ConnectionSlot::step(string_view input, uint8_t *output, size_t out_size) {
Expand Down Expand Up @@ -461,8 +465,7 @@ err_t Server::idle_conn_wrap(void *slot, altcp_pcb *conn) {
// still need a last-resort "resurrect" for such case, which we do
// here.
TransferSlot *ts = static_cast<TransferSlot *>(slot);
while (ts->step()) {
}
ts->forward_progress();

if (ts->pbuf_queue_size > 0) {
// We want to prevent the connection from timing out just because
Expand Down Expand Up @@ -577,8 +580,7 @@ err_t Server::received_wrap(void *raw_slot, struct altcp_pcb *conn, pbuf *data,
* Any freeing of the pbuf happens in there (or maybe even later on in
* case of async processing), as does the altcp_recved
*/
while (slot->step()) {
}
slot->forward_progress();

return ERR_OK;
} else {
Expand Down Expand Up @@ -630,8 +632,7 @@ void Server::step() {
}
}

while (transfer_slot.step()) {
}
transfer_slot.forward_progress();
}

bool Server::is_active_slot(void *slot) {
Expand Down Expand Up @@ -886,8 +887,7 @@ bool Server::TransferSlot::take_pbuf(pbuf *data) {
if (pbuf_queue_size >= PbufQueueMax) {
// Try to make room for the incoming pbuf in the queue.
// (Further attempts will be done in the step just after this, to submit this pbuf)
while (step()) {
}
forward_progress();
}

if (pbuf_queue_size >= PbufQueueMax) {
Expand Down Expand Up @@ -958,8 +958,7 @@ void Server::TransferSlot::segment_written(void *arg) {
assert(arg != nullptr);
TransferSlot *slot = static_cast<TransferSlot *>(arg);
assert(slot->get_slot_type() == SlotType::TransferSlot);
while (slot->step()) {
}
slot->forward_progress();
}

void Server::TransferSlot::send_segment_written(void *arg) {
Expand Down
2 changes: 2 additions & 0 deletions lib/WUI/nhttp/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ class Server {

virtual void release();
virtual bool step() = 0;
// Call step as long as you can, to make all forward progress as possible.
void forward_progress();
virtual bool want_read() const = 0;
virtual bool want_write() const = 0;
virtual bool take_pbuf(pbuf *data) = 0;
Expand Down

0 comments on commit 454e24f

Please sign in to comment.