<commit_before>/*
 * Copyright (C) 2015 <NAME>
 * All rights reserved.
 */
#include "external_io.h"
#include "common.h"
namespace strat
{
  void post_pipe_buffer(ipc::Pipe* p) noexcept
  {
    External_IO* io = (External_IO*) p->user_data;
    io->post(*p->buf);
  }
  void post_error_from_buffer(ipc::Pipe* p) noexcept
  {
    External_IO* io = (External_IO*) p->user_data;
    io->post_error(*p->buf);
  }

  Child_Process::Child_Process(ipc::Spawn_Options& opt) noexcept
  {
    uv_loop_init(&loop_);

    process_ = ipc::create_process(&loop_, opt);

    process_->io.in.user_data = this;
    process_->io.in.action_cb = post_pipe_buffer;
    uv_read_start((uv_stream_t*) &process_->io.in, alloc, ipc::collect_lines);

    process_->err.user_data = this;
    process_->err.action_cb = post_error_from_buffer;
    uv_read_start((uv_stream_t*) &process_->err, alloc, ipc::collect_lines);

    // Start the boll rollin'!
    // *process_->io.out.buf = vec_from_string("PpM");
    ipc::write_buffer(&process_->io.out);
  }
  Child_Process::~Child_Process() noexcept
  {
    ipc::delete_process(process_);

    uv_run(&loop_, UV_RUN_DEFAULT);
    uv_loop_close(&loop_);
  }
  void Child_Process::write(std::vector<char> const& buf) noexcept
  {
    step();
    if(!process_->running) return;
    *process_->io.out.buf = buf;
    ipc::write_buffer(&process_->io.out);
  }
  void Child_Process::step() noexcept
  {
    uv_run(&loop_, UV_RUN_NOWAIT);
  }

  void post_net_buffer(net::Pipe* pipe)
  {
    Net_IO* io = (Net_IO*) pipe->user_data;
    io->post(*pipe->out.buf);
  }

  Net_IO::Net_IO(std::string const& bind_ip,
                 uint16_t const bind_port,
                 std::string const& write_ip,
                 uint16_t const write_port) noexcept
  {
    // Initialize the loop
    uv_loop_init(&loop_);
    // Initialize the network pipe.
    net::init_pipe(pipe_, &loop_, bind_ip, bind_port);
    pipe_.read_cb = post_net_buffer;<commit_msg>The void* user_data of the net::Pipe is now properly set in Net_IO.<commit_after>/*
 * Copyright (C) 2015 <NAME>
 * All rights reserved.
 */
#include "external_io.h"
#include "common.h"
namespace strat
{
  void post_pipe_buffer(ipc::Pipe* p) noexcept
  {
    External_IO* io = (External_IO*) p->user_data;
    io->post(*p->buf);
  }
  void post_error_from_buffer(ipc::Pipe* p) noexcept
  {
    External_IO* io = (External_IO*) p->user_data;
    io->post_error(*p->buf);
  }

  Child_Process::Child_Process(ipc::Spawn_Options& opt) noexcept
  {
    uv_loop_init(&loop_);

    process_ = ipc::create_process(&loop_, opt);

    process_->io.in.user_data = this;
    process_->io.in.action_cb = post_pipe_buffer;
    uv_read_start((uv_stream_t*) &process_->io.in, alloc, ipc::collect_lines);

    process_->err.user_data = this;
    process_->err.action_cb = post_error_from_buffer;
    uv_read_start((uv_stream_t*) &process_->err, alloc, ipc::collect_lines);

    // Start the boll rollin'!
    // *process_->io.out.buf = vec_from_string("PpM");
    ipc::write_buffer(&process_->io.out);
  }
  Child_Process::~Child_Process() noexcept
  {
    ipc::delete_process(process_);

    uv_run(&loop_, UV_RUN_DEFAULT);
    uv_loop_close(&loop_);
  }
  void Child_Process::write(std::vector<char> const& buf) noexcept
  {
    step();
    if(!process_->running) return;
    *process_->io.out.buf = buf;
    ipc::write_buffer(&process_->io.out);
  }
  void Child_Process::step() noexcept
  {
    uv_run(&loop_, UV_RUN_NOWAIT);
  }

  void post_net_buffer(net::Pipe* pipe)
  {
    Net_IO* io = (Net_IO*) pipe->user_data;
    io->post(*pipe->out.buf);
  }

  Net_IO::Net_IO(std::string const& bind_ip,
                 uint16_t const bind_port,
                 std::string const& write_ip,
                 uint16_t const write_port) noexcept
  {
    // Initialize the loop
    uv_loop_init(&loop_);
    // Initialize the network pipe.
    net::init_pipe(pipe_, &loop_, bind_ip, bind_port);
    pipe_.user_data = this;
    pipe_.read_cb = post_net_buffer;
{'fraction_non_alphanumeric': 0.147823911955978, 'fraction_numerical': 0.00400200100050025, 'mean_word_length': 3.5494880546075085, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 47, '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': '3791001', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1448, 'n_words': 250}