diff options
author | eidheim <eidheim@gmail.com> | 2020-01-18 20:48:59 +0300 |
---|---|---|
committer | eidheim <eidheim@gmail.com> | 2020-01-18 20:48:59 +0300 |
commit | 839596d77dbc860816358ef90338926620a1dbd7 (patch) | |
tree | 4ee3c48d576a54ea2d45b2bb866a58405c2fdb00 | |
parent | 40463fb4c5e188392a9865f9339eb1e8c67ef4ac (diff) |
Improved moves of streambuf data to other streambufs
-rw-r--r-- | client_ws.hpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/client_ws.hpp b/client_ws.hpp index 1c82571..d2389ab 100644 --- a/client_ws.hpp +++ b/client_ws.hpp @@ -566,9 +566,12 @@ namespace SimpleWeb { if(num_additional_bytes > 0) { // Extract bytes that are not extra bytes in buffer (only happen when several messages are sent in upgrade response) next_in_message = connection->in_message; connection->in_message = std::shared_ptr<InMessage>(new InMessage(next_in_message->fin_rsv_opcode, next_in_message->length)); - std::ostream ostream(&connection->in_message->streambuf); - for(std::size_t c = 0; c < next_in_message->length; ++c) - ostream.put(next_in_message->get()); + + // Move leftover next_in_message to connection->in_message + auto &source = next_in_message->streambuf; + auto &target = connection->in_message->streambuf; + target.commit(asio::buffer_copy(target.prepare(next_in_message->length), source.data(), next_in_message->length)); + source.consume(next_in_message->length); } else next_in_message = std::shared_ptr<InMessage>(new InMessage()); @@ -617,8 +620,11 @@ namespace SimpleWeb { } else { connection->fragmented_in_message->length += connection->in_message->length; - std::ostream ostream(&connection->fragmented_in_message->streambuf); - ostream << connection->in_message->rdbuf(); + // Move connection->in_message to connection->fragmented_in_message + auto &source = connection->in_message->streambuf; + auto &target = connection->fragmented_in_message->streambuf; + target.commit(asio::buffer_copy(target.prepare(source.size()), source.data())); + source.consume(source.size()); } // Next message @@ -629,8 +635,11 @@ namespace SimpleWeb { if(this->on_message) { if(connection->fragmented_in_message) { connection->fragmented_in_message->length += connection->in_message->length; - std::ostream ostream(&connection->fragmented_in_message->streambuf); - ostream << connection->in_message->rdbuf(); + // Move connection->in_message to connection->fragmented_in_message + auto &source = connection->in_message->streambuf; + auto &target = connection->fragmented_in_message->streambuf; + target.commit(asio::buffer_copy(target.prepare(source.size()), source.data())); + source.consume(source.size()); this->on_message(connection, connection->fragmented_in_message); } |