diff options
author | Justin Berger <j.david.berger@gmail.com> | 2017-07-20 02:23:34 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-08-31 19:35:04 (GMT) |
commit | 7ef28843618519c222806a0df82ed8f87ad2ca0c (patch) | |
tree | 723cabf43743d04b7ed34edac2cef223eaba2ac0 /Source | |
parent | dc7a18d82eb0013a2afbdea9ba5fec131fc3179f (diff) | |
download | CMake-7ef28843618519c222806a0df82ed8f87ad2ca0c.zip CMake-7ef28843618519c222806a0df82ed8f87ad2ca0c.tar.gz CMake-7ef28843618519c222806a0df82ed8f87ad2ca0c.tar.bz2 |
server: Moved buffer formatting into bufferstrategy
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmConnection.cxx | 6 | ||||
-rw-r--r-- | Source/cmConnection.h | 11 | ||||
-rw-r--r-- | Source/cmServer.cxx | 3 | ||||
-rw-r--r-- | Source/cmServerConnection.cxx | 7 | ||||
-rw-r--r-- | Source/cmServerConnection.h | 1 |
5 files changed, 25 insertions, 3 deletions
diff --git a/Source/cmConnection.cxx b/Source/cmConnection.cxx index 6cf8e5b..89013dc 100644 --- a/Source/cmConnection.cxx +++ b/Source/cmConnection.cxx @@ -67,9 +67,13 @@ bool cmEventBasedConnection::IsOpen() const return this->WriteStream != nullptr; } -void cmEventBasedConnection::WriteData(const std::string& data) +void cmEventBasedConnection::WriteData(const std::string& _data) { + auto data = _data; assert(this->WriteStream); + if (BufferStrategy) { + data = BufferStrategy->BufferOutMessage(data); + } auto ds = data.size(); diff --git a/Source/cmConnection.h b/Source/cmConnection.h index b1b51fe..ddb7744 100644 --- a/Source/cmConnection.h +++ b/Source/cmConnection.h @@ -39,6 +39,17 @@ public: virtual std::string BufferMessage(std::string& rawBuffer) = 0; /*** + * Called to properly buffer an outgoing message. + * + * @param rawBuffer Message to format in the correct way + * + * @return Formatted message + */ + virtual std::string BufferOutMessage(const std::string& rawBuffer) const + { + return rawBuffer; + }; + /*** * Resets the internal state of the buffering */ virtual void clear(); diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index 14e1fd1..6a63797 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -282,8 +282,7 @@ void cmServer::WriteJsonObject(cmConnection* connection, } } - connection->WriteData(std::string("\n") + kSTART_MAGIC + std::string("\n") + - result + kEND_MAGIC + std::string("\n")); + connection->WriteData(result); } cmServerProtocol* cmServer::FindMatchingProtocol( diff --git a/Source/cmServerConnection.cxx b/Source/cmServerConnection.cxx index dd14932..e686403 100644 --- a/Source/cmServerConnection.cxx +++ b/Source/cmServerConnection.cxx @@ -153,6 +153,13 @@ void cmConnectionBufferStrategy::clear() { } +std::string cmServerBufferStrategy::BufferOutMessage( + const std::string& rawBuffer) const +{ + return std::string("\n") + kSTART_MAGIC + std::string("\n") + rawBuffer + + kEND_MAGIC + std::string("\n"); +} + std::string cmServerBufferStrategy::BufferMessage(std::string& RawReadBuffer) { for (;;) { diff --git a/Source/cmServerConnection.h b/Source/cmServerConnection.h index 7b0c9b6..4ca908d 100644 --- a/Source/cmServerConnection.h +++ b/Source/cmServerConnection.h @@ -25,6 +25,7 @@ class cmServerBufferStrategy : public cmConnectionBufferStrategy { public: std::string BufferMessage(std::string& rawBuffer) override; + std::string BufferOutMessage(const std::string& rawBuffer) const override; private: std::string RequestBuffer; |