mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 00:11:07 -06:00
server: Moved buffer formatting into bufferstrategy
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -38,6 +38,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
|
||||
*/
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 (;;) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user