<commit_before>#include "c24/communication/stream.h"

#include <chrono>
#include <string>
#include <thread>
#include <glog/logging.h>

namespace c24 {
namespace communication {

Stream::Stream(std::unique_ptr<StreamBackendInterface> stream_backend)
    : stream_backend_(std::move(stream_backend)) {}

bool Stream::Connected() {
  status_ = Status();
  if (stream_backend_ == nullptr) {
    return false;
  }
  return stream_backend_->Connected();
}

bool Stream::MessageAvailable() {
  CheckConnectionAndReconnect();
  status_ = Status();
  CHECK_NE(stream_backend_, nullptr);
  return stream_backend_->MessageAvailable();
}

std::string Stream::GetMessage() {
  CheckConnectionAndReconnect();
  status_ = Status();
  CHECK_NE(stream_backend_, nullptr);
  std::string msg = stream_backend_->GetMessage();
  LOG(INFO) << "Received: \"" << msg << "\"";
  return msg;
}

bool Stream::SendMessage(const std::string& msg, bool newline) {
  CheckConnectionAndReconnect();
  status_ = Status();
  CHECK_NE(stream_backend_, nullptr);
  // Put two spaces after Sending so it is lined up with messages after
  // Received.
  LOG(INFO) << "Sending:  \"" << msg << "\"";
  const std::string& msg_to_send = newline ? msg + '\n' : msg;
  return stream_backend_->SendMessage(msg_to_send);
}

Status Stream::LastStatus() const {
  if (!status_.Ok()) return status_;
  CHECK_NE(stream_backend_, nullptr);
  return stream_backend_->LastStatus();
}

bool Stream::GetMessageWithCheck(const char* expected) {
  std::string msg_ok = GetMessage();
  if (msg_ok != expected) {
    status_ = stream_backend_->LastStatus();
    if (msg_ok.length() >= 11 && msg_ok.substr(0, 5) == "ERROR") {
      int error_code = std::atoi(msg_ok.substr(6, 3).c_str());
      status_.SetServerError(error_code, msg_ok.substr(11));
    }
    LOG(ERROR) << "Expected \"" << expected << "\" but received \"" << msg_ok
               << "\"";<commit_msg>Change CHECK_NE to CHECK to fix the compilation.<commit_after>#include "c24/communication/stream.h"

#include <chrono>
#include <string>
#include <thread>
#include <glog/logging.h>

namespace c24 {
namespace communication {

Stream::Stream(std::unique_ptr<StreamBackendInterface> stream_backend)
    : stream_backend_(std::move(stream_backend)) {}

bool Stream::Connected() {
  status_ = Status();
  if (stream_backend_ == nullptr) {
    return false;
  }
  return stream_backend_->Connected();
}

bool Stream::MessageAvailable() {
  CheckConnectionAndReconnect();
  status_ = Status();
  CHECK(stream_backend_ != nullptr);
  return stream_backend_->MessageAvailable();
}

std::string Stream::GetMessage() {
  CheckConnectionAndReconnect();
  status_ = Status();
  CHECK(stream_backend_ != nullptr);
  std::string msg = stream_backend_->GetMessage();
  LOG(INFO) << "Received: \"" << msg << "\"";
  return msg;
}

bool Stream::SendMessage(const std::string& msg, bool newline) {
  CheckConnectionAndReconnect();
  status_ = Status();
  CHECK(stream_backend_ != nullptr);
  // Put two spaces after Sending so it is lined up with messages after
  // Received.
  LOG(INFO) << "Sending:  \"" << msg << "\"";
  const std::string& msg_to_send = newline ? msg + '\n' : msg;
  return stream_backend_->SendMessage(msg_to_send);
}

Status Stream::LastStatus() const {
  if (!status_.Ok()) return status_;
  CHECK(stream_backend_ != nullptr);
  return stream_backend_->LastStatus();
}

bool Stream::GetMessageWithCheck(const char* expected) {
  std::string msg_ok = GetMessage();
  if (msg_ok != expected) {
    status_ = stream_backend_->LastStatus();
    if (msg_ok.length() >= 11 && msg_ok.substr(0, 5) == "ERROR") {
      int error_code = std::atoi(msg_ok.substr(6, 3).c_str());
      status_.SetServerError(error_code, msg_ok.substr(11));
    }
    LOG(ERROR) << "Expected \"" << expected << "\" but received \"" << msg_ok
               << "\"";
{'fraction_non_alphanumeric': 0.15926214601195116, 'fraction_numerical': 0.006235385814497272, 'mean_word_length': 4.65345080763583, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1754393', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1217, 'n_words': 267}