<commit_before>/*
 * ============================================================================
 *       Filename:  slave.hxx
 *    Description:  Slave side implementation for flihabi network
 *        Version:  1.0
 *        Created:  04/26/2015 02:40:40 AM
 *       Revision:  none
 *       Compiler:  gcc
 *         Author:  <NAME>, <EMAIL>
 *   Organization:  Flihabi
 * ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <iostream>
#include <string>

#include "utils.hh"
#include "network.hh"
#include "slave.hh"
#include "listener.hh"

// PUBLIC METHODS

Slave::Slave()
{
    std::string ip = getServerAddress();
    connectToServer(ip, CONNECTION_PORT);
}

std::string Slave::getBytecode()
{
    int nbRecv;
    char buf[MAX_BYTECODE_LEN];
    std::cout << "Slave: Waiting for bytecode..." << std::endl;
    if ((nbRecv = recv(sockfd_, buf, MAX_BYTECODE_LEN-1, 0)) == -1)
    {
        perror("Slave: failed to recv bytecode");
        return "";
    }
    buf[nbRecv] = '\0';
    std::cout << "Slave: received: " << std::string(buf) << std::endl;

    return std::string(buf);
}


int Slave::send_bytecode(std::string bytecode)
{
    if (send(sockfd_, bytecode.c_str(), bytecode.size(), 0) == -1)
    {
        perror("Client thread: failed sending bytecode");
        return -1;
    }
    return 0;
}

// PRIVATE METHODS

std::string Slave::getServerAddress()<commit_msg>Changing slave receive msg<commit_after>/*
 * ============================================================================
 *       Filename:  slave.hxx
 *    Description:  Slave side implementation for flihabi network
 *        Version:  1.0
 *        Created:  04/26/2015 02:40:40 AM
 *       Revision:  none
 *       Compiler:  gcc
 *         Author:  <NAME>, <EMAIL>
 *   Organization:  Flihabi
 * ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <iostream>
#include <string>

#include "utils.hh"
#include "network.hh"
#include "slave.hh"
#include "listener.hh"

// PUBLIC METHODS

Slave::Slave()
{
    std::string ip = getServerAddress();
    connectToServer(ip, CONNECTION_PORT);
}

std::string Slave::getBytecode()
{
    int nbRecv;
    char buf[MAX_BYTECODE_LEN];
    std::cout << "Slave: Waiting for bytecode..." << std::endl;
    if ((nbRecv = recv(sockfd_, buf, MAX_BYTECODE_LEN-1, 0)) == -1)
    {
        perror("Slave: failed to recv bytecode");
        return "";
    }
    buf[nbRecv] = '\0';
    std::cout << "Slave: received " << nbRecv << " bytes: " << std::string(buf) << std::endl;

    return std::string(buf);
}


int Slave::send_bytecode(std::string bytecode)
{
    if (send(sockfd_, bytecode.c_str(), bytecode.size(), 0) == -1)
    {
        perror("Client thread: failed sending bytecode");
        return -1;
    }
    return 0;
}

// PRIVATE METHODS

std::string Slave::getServerAddress()
{'fraction_non_alphanumeric': 0.24288310115081768, 'fraction_numerical': 0.014536644457904301, 'mean_word_length': 3.512295081967213, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 31, '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': '859062', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1113, 'n_words': 246}