Skip to content

Commit

Permalink
Make write2client iterative istead of recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
beardhatcode committed Jun 4, 2022
1 parent 74b8466 commit ca1bcdd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/RFC/SocketServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,14 @@ void SocketServer::write2Client(AsyncClient *client, const char *buf,
size_t size_buf) {
if (client == nullptr) return;
size_t space_left = client->space();
client->add(buf, size_buf > space_left ? space_left : size_buf);
client->send();
if (size_buf <= space_left) return;
write2Client(client, buf + space_left, size_buf - space_left);
// Send upto limit
do {
size_t send_size = size_buf > space_left ? space_left : size_buf;
client->add(buf, send_size);
client->send();
buf += send_size;
size_buf -= send_size;
} while (size_buf > 0);
}

void SocketServer::printf2Client(AsyncClient *client, const char *format, ...) {
Expand Down

0 comments on commit ca1bcdd

Please sign in to comment.