Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marian-nmt/Simple-WebSocket-Server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authoreidheim <eidheim@gmail.com>2017-07-30 14:30:35 +0300
committereidheim <eidheim@gmail.com>2017-07-30 14:34:14 +0300
commit9c6a608f21184bfee9732c5faafc88dc3e92a2ed (patch)
treeacb3341434ec55ebdbfcaad7d813e3240c8a83b0 /tests
parent5a0c95ad536a0a466e9a2bd68261d66e35438992 (diff)
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/io_test.cpp19
1 files changed, 6 insertions, 13 deletions
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<WsServer::Connection> connection, shared_ptr<WsServer::Message> message) {
- auto message_str = message->string();
+ auto send_stream = make_shared<WsServer::SendStream>();
+ *send_stream << message->string();
- auto send_stream1 = make_shared<WsServer::SendStream>();
- *send_stream1 << message_str;
- connection->send(send_stream1, [connection, message_str](const SimpleWeb::error_code &ec) {
- if(!ec) {
- auto send_stream3 = make_shared<WsServer::SendStream>();
- *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<WsServer::SendStream>();
- *send_stream2 << message_str;
- connection->send(send_stream2); //Most likely queued, and sent after send_stream1
+ connection->send(send_stream);
};
thread server_thread([&server]() {