summaryrefslogtreecommitdiff
path: root/src/sender.cc
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@yahoo.com>2015-06-04 23:59:03 +0200
committerJoel Klinghed <the_jk@yahoo.com>2015-06-04 23:59:03 +0200
commit0b8e0ca6e1e8d9a0e36e2e3c960c84a289822675 (patch)
tree7922eb340c852a32fb5f0f4f3871955a592cf419 /src/sender.cc
parent149aca58939a4a4fa8df47ba81dd835932378f1e (diff)
Fix sender and sender_client communication
Diffstat (limited to 'src/sender.cc')
-rw-r--r--src/sender.cc9
1 files changed, 5 insertions, 4 deletions
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<size_t>(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<size_t>(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();