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
diff options
context:
space:
mode:
authormbroshi <michael.broshi@mathworks.com>2019-03-20 21:57:13 +0300
committermbroshi <michael.broshi@mathworks.com>2019-03-20 21:57:13 +0300
commit24962ff97c674b48decde2821b7cbe0fdba631b8 (patch)
tree09bb762e80c2d2cd7447f7ce2ce1437e49490385
parent8dbcc8e1ab0ddad3318646d323184c119e3b8f1d (diff)
Reserve capacity in write buffer to workaround Issue 114
-rw-r--r--client_ws.hpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/client_ws.hpp b/client_ws.hpp
index cfd0fd3..948b3d4 100644
--- a/client_ws.hpp
+++ b/client_ws.hpp
@@ -77,6 +77,9 @@ namespace SimpleWeb {
public:
OutMessage() noexcept : std::iostream(&streambuf) {}
+ OutMessage(std::size_t capacity) noexcept : std::iostream(&streambuf) {
+ streambuf.prepare(capacity);
+ }
/// Returns the size of the buffer
std::size_t size() const noexcept {
@@ -230,10 +233,10 @@ namespace SimpleWeb {
for(std::size_t c = 0; c < 4; c++)
mask[c] = static_cast<unsigned char>(dist(rd));
- auto out_header_and_message = std::make_shared<OutMessage>();
-
std::size_t length = out_message->size();
+ auto out_header_and_message = std::make_shared<OutMessage>(length + 12); // at most 12 header bytes added
+
out_header_and_message->put(static_cast<char>(fin_rsv_opcode));
// Masked (first length byte>=128)
if(length >= 126) {