Skip to content

Commit

Permalink
Improving buffering code
Browse files Browse the repository at this point in the history
  • Loading branch information
trikko committed May 22, 2024
1 parent 961a0c4 commit cebabe0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions source/serverino/communicator.d
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,18 @@ package class Communicator
}
else
{
auto leftover = sendBuffer.array[sent..$].dup;
sendBuffer.clear();
auto notsent = sendBuffer.length() - sent;

if (leftover.length > 0)
sendBuffer.append(leftover);
if (notsent > 0)
{
import std.algorithm : copy;
copy(sendBuffer.array[sent..$], sendBuffer.array[0..notsent]);
sendBuffer.length = notsent;
}
else sendBuffer.clear();
}

// Refill buffer is not so full
if (sendBuffer.length < DEFAULT_BUFFER_SIZE)
{
if (!file.eof)
Expand Down
2 changes: 1 addition & 1 deletion tests/test-02/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void test()
char[] data;

data.reserve = 1024*1024*10;
buffer.length = 4096;
buffer.length = 128;

while(true)
{
Expand Down

0 comments on commit cebabe0

Please sign in to comment.