From 0b8e0ca6e1e8d9a0e36e2e3c960c84a289822675 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Thu, 4 Jun 2015 23:59:03 +0200 Subject: Fix sender and sender_client communication --- src/sender.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/sender.cc') diff --git a/src/sender.cc b/src/sender.cc index c5b84c4..b9b6a36 100644 --- a/src/sender.cc +++ b/src/sender.cc @@ -40,7 +40,7 @@ void queue_message(const std::string& channel, const std::string& message); class Client { public: Client(int sock) - : sock_(sock), have_channel_(false), size_(0) { + : sock_(sock), fill_(0), have_channel_(false), size_(0) { } ~Client() { @@ -71,7 +71,7 @@ public: if (size_ == 0) { auto const avail = std::min(fill - pos, static_cast(4)); - memcpy(buf_ + fill_, buf, avail); + memcpy(buf_ + fill_, buf + pos, avail); fill_ += avail; pos += avail; if (fill_ == 4) { @@ -89,13 +89,14 @@ public: pos += avail; if (channel_.size() == size_) { have_channel_ = true; + size_ = 0; } } } else { if (size_ == 0) { auto const avail = std::min(fill - pos, static_cast(4)); - memcpy(buf_ + fill_, buf, avail); + memcpy(buf_ + fill_, buf + pos, avail); fill_ += avail; pos += avail; if (fill_ == 4) { @@ -109,7 +110,7 @@ public: } else { auto const avail = std::min(fill - pos, size_ - message_.size()); - channel_.append(buf + pos, buf + pos + avail); + message_.append(buf + pos, buf + pos + avail); pos += avail; if (message_.size() == size_) { send_message(); -- cgit v1.2.3-70-g09d2