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:
authoreidheim <eidheim@gmail.com>2020-01-18 20:22:28 +0300
committereidheim <eidheim@gmail.com>2020-01-18 20:22:28 +0300
commit40463fb4c5e188392a9865f9339eb1e8c67ef4ac (patch)
tree57a54867c645c1654c2364f433594eb5ad0765de
parent74fb8e9ac23e070f094142cc563508d7cbebe589 (diff)
Simplified string() functions, and streambuf is no longer consumed when InMessage::string() is called
-rw-r--r--client_ws.hpp21
-rw-r--r--server_ws.hpp21
2 files changed, 6 insertions, 36 deletions
diff --git a/client_ws.hpp b/client_ws.hpp
index 2d97717..1c82571 100644
--- a/client_ws.hpp
+++ b/client_ws.hpp
@@ -30,24 +30,9 @@ namespace SimpleWeb {
return length;
}
- /// Convenience function to return std::string. The stream buffer is consumed.
- /// Successive calls will return the same string.
- const std::string &string() noexcept {
- if(cached_string)
- return *cached_string;
-
- cached_string = std::unique_ptr<std::string>(new std::string());
-
- try {
- auto size = streambuf.size();
- cached_string->resize(size);
- read(&(*cached_string)[0], static_cast<std::streamsize>(size));
- return *cached_string;
- }
- catch(...) {
- cached_string->clear();
- return *cached_string;
- }
+ /// Convenience function to return std::string.
+ std::string string() noexcept {
+ return std::string(asio::buffers_begin(streambuf.data()), asio::buffers_end(streambuf.data()));
}
private:
diff --git a/server_ws.hpp b/server_ws.hpp
index 8ec029f..dcce130 100644
--- a/server_ws.hpp
+++ b/server_ws.hpp
@@ -43,24 +43,9 @@ namespace SimpleWeb {
return length;
}
- /// Convenience function to return std::string. The stream buffer is consumed.
- /// Successive calls will return the same string.
- const std::string &string() noexcept {
- if(cached_string)
- return *cached_string;
-
- cached_string = std::unique_ptr<std::string>(new std::string());
-
- try {
- auto size = streambuf.size();
- cached_string->resize(size);
- read(&(*cached_string)[0], static_cast<std::streamsize>(size));
- return *cached_string;
- }
- catch(...) {
- cached_string->clear();
- return *cached_string;
- }
+ /// Convenience function to return std::string.
+ std::string string() noexcept {
+ return std::string(asio::buffers_begin(streambuf.data()), asio::buffers_end(streambuf.data()));
}
private: