<commit_before>/*
** Author(s):
**  - <NAME> <<EMAIL>>
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2010, 2012 Aldebaran Robotics
*/


#include <vector>
#include <iostream>
#include <sstream>

#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <boost/program_options.hpp>

namespace po = boost::program_options;

#include <qi/application.hpp>
#include <qimessaging/transportsocket.hpp>

#include <qimessaging/servicedirectory.hpp>
#include <qimessaging/gateway.hpp>

#include <qiperf/dataperfsuite.hpp>

static int gLoopCount = 500;
static const int gThreadCount = 1;
qi::DataPerfSuite* out;

void TSIOnMessageReady(const qi::Message &QI_UNUSED(msg))
{
}

class TSIReply
{
public:
  void onTransportServerNewConnection(qi::TransportSocketPtr socket)
  {
    socket->messageReady.connect(boost::bind<void>(&TSIReply::onMessageReady, this, _1, socket));
    socket->startReading();
  }

  void onMessageReady(const qi::Message &msg, qi::TransportSocketPtr socket)
  {
    qi::Message ret(qi::Message::Type_Reply, msg.address());
    socket->send(ret);
  }
};

int thd_client(qi::TransportSocketPtr socket, const std::string& addr)
{
  if (!socket)
  {
    socket = qi::makeTransportSocket("tcp");

    socket->messageReady.connect(boost::bind<void>(&TSIOnMessageReady, _1));

    socket->connect(addr);
  }

  qi::DataPerf dp;
  qi::Buffer buf;
  char buf2[512];
  buf.write(buf2, 512);

  dp.start("ahah", gLoopCount, 512);
  for (int j = 0; j < gLoopCount; ++j)
  {
    qi::Message msg;
    msg.setBuffer(buf);
    msg.setType(qi::Message::Type_Call);
    msg.setObject(qi::Message::GenericObject_Main);
    msg.setFunction(1);

    if (!(socket->send(msg)))
      return 1;
  }
  dp.stop();
  *out << dp;

  return 0;
}

int main_client(bool shared, unsigned int threadCount, const std::string& addr)
{
  qi::TransportSocketPtr socket;

  boost::thread thd[threadCount < 100 ? threadCount : 100];

  if (shared)
  {
    socket = qi::makeTransportSocket("tcp");
    socket->connect(addr);
    socket->messageReady.connect(boost::bind<void>(&TSIOnMessageReady, _1));
  }

  for (unsigned int i = 0; i < threadCount; ++i)
  {
    thd[i] = boost::thread(boost::bind(&thd_client, socket, addr));
  }

  for (unsigned int i = 0; i < threadCount; ++i)
  {
    thd[i].join();
  }

  return 0;
}

int main_server(const std::string& addr)
{<commit_msg>perf_transport_socket: Fix non-const array initializer error on windows<commit_after>/*
** Author(s):
**  - <NAME> <<EMAIL>>
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2010, 2012 Aldebaran Robotics
*/


#include <vector>
#include <iostream>
#include <sstream>

#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <boost/program_options.hpp>

namespace po = boost::program_options;

#include <qi/application.hpp>
#include <qimessaging/transportsocket.hpp>

#include <qimessaging/servicedirectory.hpp>
#include <qimessaging/gateway.hpp>

#include <qiperf/dataperfsuite.hpp>

static int gLoopCount = 500;
static const int gThreadCount = 1;
qi::DataPerfSuite* out;

void TSIOnMessageReady(const qi::Message &QI_UNUSED(msg))
{
}

class TSIReply
{
public:
  void onTransportServerNewConnection(qi::TransportSocketPtr socket)
  {
    socket->messageReady.connect(boost::bind<void>(&TSIReply::onMessageReady, this, _1, socket));
    socket->startReading();
  }

  void onMessageReady(const qi::Message &msg, qi::TransportSocketPtr socket)
  {
    qi::Message ret(qi::Message::Type_Reply, msg.address());
    socket->send(ret);
  }
};

int thd_client(qi::TransportSocketPtr socket, const std::string& addr)
{
  if (!socket)
  {
    socket = qi::makeTransportSocket("tcp");

    socket->messageReady.connect(boost::bind<void>(&TSIOnMessageReady, _1));

    socket->connect(addr);
  }

  qi::DataPerf dp;
  qi::Buffer buf;
  char buf2[512];
  buf.write(buf2, 512);

  dp.start("ahah", gLoopCount, 512);
  for (int j = 0; j < gLoopCount; ++j)
  {
    qi::Message msg;
    msg.setBuffer(buf);
    msg.setType(qi::Message::Type_Call);
    msg.setObject(qi::Message::GenericObject_Main);
    msg.setFunction(1);

    if (!(socket->send(msg)))
      return 1;
  }
  dp.stop();
  *out << dp;

  return 0;
}

int main_client(bool shared, unsigned int threadCount, const std::string& addr)
{
  qi::TransportSocketPtr socket;

  boost::thread* thd = new boost::thread[threadCount < 100 ? threadCount : 100];

  if (shared)
  {
    socket = qi::makeTransportSocket("tcp");
    socket->connect(addr);
    socket->messageReady.connect(boost::bind<void>(&TSIOnMessageReady, _1));
  }

  for (unsigned int i = 0; i < threadCount; ++i)
  {
    thd[i] = boost::thread(boost::bind(&thd_client, socket, addr));
  }

  for (unsigned int i = 0; i < threadCount; ++i)
  {
    thd[i].join();
  }

  delete[] thd;
  return 0;
}

int main_server(const std::string& addr)
{
{'fraction_non_alphanumeric': 0.16309102270360343, 'fraction_numerical': 0.016246615288481567, 'mean_word_length': 4.55787037037037, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 59, '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': '4377461', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1708, 'n_words': 349}