From 9c6a608f21184bfee9732c5faafc88dc3e92a2ed Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 30 Jul 2017 13:30:35 +0200 Subject: SocketServer::Connection::send no longer consumes the buffer, to reduce memory consumption and copying when sending the same message to several connections. Instead, use SocketServer::SendStream::consume to actually consume the buffer if needed. --- tests/io_test.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/io_test.cpp b/tests/io_test.cpp index 24aa787..446ecd3 100644 --- a/tests/io_test.cpp +++ b/tests/io_test.cpp @@ -47,21 +47,14 @@ int main() { auto &echo_thrice = server.endpoint["^/echo_thrice/?$"]; echo_thrice.on_message = [](shared_ptr connection, shared_ptr message) { - auto message_str = message->string(); + auto send_stream = make_shared(); + *send_stream << message->string(); - auto send_stream1 = make_shared(); - *send_stream1 << message_str; - connection->send(send_stream1, [connection, message_str](const SimpleWeb::error_code &ec) { - if(!ec) { - auto send_stream3 = make_shared(); - *send_stream3 << message_str; - connection->send(send_stream3); //Sent after send_stream1 is sent, and most likely after send_stream2 - } + connection->send(send_stream, [connection, send_stream](const SimpleWeb::error_code &ec) { + if(!ec) + connection->send(send_stream); }); - //Do not reuse send_stream1 here as it most likely is not sent yet - auto send_stream2 = make_shared(); - *send_stream2 << message_str; - connection->send(send_stream2); //Most likely queued, and sent after send_stream1 + connection->send(send_stream); }; thread server_thread([&server]() { -- cgit v1.2.3