Reformat code

This commit is contained in:
badaix 2020-02-25 22:14:19 +01:00
parent 2efe44517a
commit 0c25a7a42d
3 changed files with 7 additions and 20 deletions

View file

@ -93,7 +93,7 @@ void ControlSessionTcp::stop()
void ControlSessionTcp::sendAsync(const std::string& message)
{
strand_.post([ this, self = shared_from_this(), message ]() {
messages_.emplace_back(message);
messages_.emplace_back(message + "\r\n");
if (messages_.size() > 1)
{
LOG(DEBUG) << "TCP session outstanding async_writes: " << messages_.size() << "\n";
@ -105,20 +105,7 @@ void ControlSessionTcp::sendAsync(const std::string& message)
void ControlSessionTcp::send_next()
{
// We cannot simply do boost::asio::buffer(message + "\r\n"), because 'message + "\r\n"' becomes invalid
// after leaving this method, leading to a 'Bad address' error.
// Instead, we need to mutate the string before passing it to boost::asio::buffer.
//
// From the boost reference:
//
// A buffer object does not have any ownership of the memory it refers to. It is the responsibility of
// the application to ensure the memory region remains valid until it is no longer required for an I/O
// operation. When the memory is no longer available, the buffer is said to have been invalidated.
// https://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/reference/buffer.html#boost_asio.reference.buffer.buffer_invalidation
string& message = messages_.front();
message += "\r\n";
boost::asio::async_write(socket_, boost::asio::buffer(message),
boost::asio::async_write(socket_, boost::asio::buffer(messages_.front()),
boost::asio::bind_executor(strand_, [ this, self = shared_from_this() ](std::error_code ec, std::size_t length) {
messages_.pop_front();
if (ec)

View file

@ -68,7 +68,7 @@ protected:
std::unique_ptr<TageEntry> entry_;
std::string buf_;
json metadata_;
// set whenever metadata_ has changed
/// set whenever metadata_ has changed
bool metadata_dirty_;
#endif
@ -77,7 +77,7 @@ protected:
int parse(std::string line);
void createParser();
void push();
void setMetaData(const std::string&, const std::string&);
void setMetaData(const string& key, const string& newValue);
#endif
void setParamsAndPipePathFromPort();