Browse Source

server: Moved buffer formatting into bufferstrategy

pull/314/head
Justin Berger 8 years ago
committed by Brad King
parent
commit
7ef2884361
  1. 6
      Source/cmConnection.cxx
  2. 11
      Source/cmConnection.h
  3. 3
      Source/cmServer.cxx
  4. 7
      Source/cmServerConnection.cxx
  5. 1
      Source/cmServerConnection.h

6
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();

11
Source/cmConnection.h

@ -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
*/

3
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(

7
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 (;;) {

1
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;

Loading…
Cancel
Save