<commit_before>/*
 *	author: <NAME> <<EMAIL>>
 *
 *	Use of this source code is governed by the MIT license that can be
 *	found in the LICENSE file.
 */

#include "tcp_client.h"
#include "utils.h"

void recv_message(muggle_socket_peer_t *peer, muggle_bytes_buffer_t *bytes_buf)
{
	int read_bytes = 4096;
	while (1)
	{
		void *p = muggle_bytes_buffer_writer_fc(bytes_buf, read_bytes);
		if (p == NULL)
		{
			MUGGLE_LOG_ERROR("bytes buffer full");
			exit(EXIT_FAILURE);
		}

		int n = muggle_socket_peer_recv(peer, p, read_bytes, 0);
		muggle_bytes_buffer_writer_move(bytes_buf, n);

		if (n < read_bytes)
		{
			break;
		}
	}
}

bool parse_message_uncontiguous(muggle_socket_peer_t *peer, muggle_bytes_buffer_t *bytes_buf, int readable)
{
	struct pkg msg;
	if (!muggle_bytes_buffer_fetch(bytes_buf, sizeof(struct pkg_header), &msg.header))
	{
		return false;
	}<commit_msg>fix bug in net_trans, pass negative number into muggle_bytes_buffer_writer_move is wrong<commit_after>/*
 *	author: <NAME> <<EMAIL>>
 *
 *	Use of this source code is governed by the MIT license that can be
 *	found in the LICENSE file.
 */

#include "tcp_client.h"
#include "utils.h"

void recv_message(muggle_socket_peer_t *peer, muggle_bytes_buffer_t *bytes_buf)
{
	int read_bytes = 4096;
	while (1)
	{
		void *p = muggle_bytes_buffer_writer_fc(bytes_buf, read_bytes);
		if (p == NULL)
		{
			MUGGLE_LOG_ERROR("bytes buffer full");
			exit(EXIT_FAILURE);
		}

		int n = muggle_socket_peer_recv(peer, p, read_bytes, 0);
		if (n > 0)
		{
			muggle_bytes_buffer_writer_move(bytes_buf, n);
		}

		if (n < read_bytes)
		{
			break;
		}
	}
}

bool parse_message_uncontiguous(muggle_socket_peer_t *peer, muggle_bytes_buffer_t *bytes_buf, int readable)
{
	struct pkg msg;
	if (!muggle_bytes_buffer_fetch(bytes_buf, sizeof(struct pkg_header), &msg.header))
	{
		return false;
	}
{'fraction_non_alphanumeric': 0.11056910569105691, 'fraction_numerical': 0.007046070460704607, 'mean_word_length': 4.697530864197531, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, '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': '4646810', 'n_tokens_mistral': 789, 'n_tokens_neox': 725, 'n_words': 167}