<commit_before>#include <Reader.hpp>

Reader::Reader(int socket_descriptor, int buffer_size) : killThread(false){

	this->socket_descriptor = socket_descriptor;
	this->buffer_size = buffer_size;

	pthread_mutex_init(&newValue,0);
	pthread_cond_init(&available, 0);
	pthread_t thread1;
	value.resize(1);
	pthread_create(&thread1, 0, run, (void *) this);
}

void * Reader::run(void *param) {

	Reader *mt = ((Reader *) param);
	while(!mt->killThread) {

		if(mt->process()) {
			pthread_mutex_lock(&mt->newValue);
			pthread_cond_signal(&mt->available);
			pthread_mutex_unlock(&mt->newValue);
		}

		if(mt->killThread) {
			break;
		}

		usleep(100);
	}

	return NULL;
}

bool Reader::process() {
	//(*value) = next value from the socket
	// return true if the value is valid
	value[0] = "new";
	return true;
}

string Reader::readCommand() {
	pthread_mutex_lock(&newValue);
	pthread_cond_wait(&available, &newValue);<commit_msg>Added logic for reading from the socket.<commit_after>#include <Reader.hpp>

Reader::Reader(int socket_descriptor, int buffer_size) : killThread(false){

	this->socket_descriptor = socket_descriptor;
	this->buffer_size = buffer_size;

	pthread_mutex_init(&newValue,0);
	pthread_cond_init(&available, 0);
	pthread_t thread1;
	value.resize(1);
	pthread_create(&thread1, 0, run, (void *) this);
}

void * Reader::run(void *param) {

	Reader *mt = ((Reader *) param);
	while(!mt->killThread) {

		if(mt->process()) {
			pthread_mutex_lock(&mt->newValue);
			pthread_cond_signal(&mt->available);
			pthread_mutex_unlock(&mt->newValue);
		}

		if(mt->killThread) {
			break;
		}

		usleep(100);
	}

	return NULL;
}

bool Reader::process() {
	//(*value) = next value from the socket
	// return true if the value is valid
	char buffer[buffer_size];
	int numBytes = recv(this->socket_descriptor, buffer, sizeof(buffer), 0);
	if (buffer > 0) {
		//If we got something in the buffer, everything's fine.
		value[0] = buffer;
		return true;
	} else {
		//Otherwise, the socket got closed on us.
		return false;
	}
}

string Reader::readCommand() {
	pthread_mutex_lock(&newValue);
	pthread_cond_wait(&available, &newValue);
{'fraction_non_alphanumeric': 0.15067852129153017, 'fraction_numerical': 0.010294805802526907, 'mean_word_length': 4.938888888888889, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '712238', 'n_tokens_mistral': 810, 'n_tokens_neox': 746, 'n_words': 161}