<commit_before>
// Server.cpp

// Interfaces to the cServer class encapsulating the entire "server"

#include "Globals.h"
#include "Server.h"
#include "Connection.h"





cServer::cServer(void)
{
}





int cServer::Init(short a_ListenPort, short a_ConnectPort)
{
	m_ConnectPort = a_ConnectPort;
	
	#ifdef _WIN32
		WSAData wsa;
		int res = WSAStartup(0x0202, &wsa);
		if (res != 0)
		{
			printf("Cannot initialize WinSock: %d\n", res);
			return res;
		}
	#endif  // _WIN32
	
	puts("Generating protocol encryption keypair...");
	m_PrivateKey.Generate();
	m_PublicKeyDER = m_PrivateKey.GetPubKeyDER();

	m_ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (m_ListenSocket < 0)
	{
		#ifdef _WIN32
			int err = WSAGetLastError();
		#else
			int err = errno;
		#endif
		printf("Failed to create listener socket: %d\n", err);
		return err;
	}
	sockaddr_in local;
	memset(&local, 0, sizeof(local));
	local.sin_family = AF_INET;
	local.sin_addr.s_addr = 130;  // INADDR_ANY;  // All interfaces
	local.sin_port = htons(a_ListenPort);
	if (!bind(m_ListenSocket, (sockaddr *)&local, sizeof(local)))
	{
		#ifdef _WIN32
			int err = WSAGetLastError();
		#else
			int err = errno;
		#endif
		printf("Failed to bind listener socket: %d\n", err);
		return err;
	}
	if (listen(m_ListenSocket, 1) != 0)
	{
		#ifdef _WIN32
			int err = WSAGetLastError();
		#else
			int err = errno;
		#endif
		printf("Failed to listen on socket: %d\n", err);
		return err;
	}
	
	printf("Listening on port %d, connecting to localhost:%d\n", a_ListenPort, a_ConnectPort);
	
	return 0;
}





void cServer::Run(void)
{
	puts("Server running.");
	while (true)
	{
		sockaddr_in Addr;
		memset(&Addr, 0, sizeof(Addr));
		socklen_t AddrSize = sizeof(Addr);
		SOCKET client = accept(m_ListenSocket, (sockaddr *)&Addr, &AddrSize);
		if (client == INVALID_SOCKET)
		{
			printf("accept returned an error: %d; bailing out.\n", SocketError);
			return;
		}
		puts("Client connected, proxying...");
		cConnection Connection(client, *this);
		Connection.Run();
		puts("Client disconnected. Ready for another connection.");
	}
}


<commit_msg>Fixed Server.cpp<commit_after>
// Server.cpp

// Interfaces to the cServer class encapsulating the entire "server"

#include "Globals.h"
#include "Server.h"
#include "Connection.h"





cServer::cServer(void)
{
}





int cServer::Init(short a_ListenPort, short a_ConnectPort)
{
	m_ConnectPort = a_ConnectPort;
	
	#ifdef _WIN32
		WSAData wsa;
		int res = WSAStartup(0x0202, &wsa);
		if (res != 0)
		{
			printf("Cannot initialize WinSock: %d\n", res);
			return res;
		}
	#endif  // _WIN32
	
	LOG("Generating protocol encryption keypair...");
	m_PrivateKey.Generate();
	m_PublicKeyDER = m_PrivateKey.GetPubKeyDER();

	m_ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (m_ListenSocket < 0)
	{
		#ifdef _WIN32
			int err = WSAGetLastError();
		#else
			int err = errno;
		#endif
		printf("Failed to create listener socket: %d\n", err);
		return err;
	}
	sockaddr_in local;
	memset(&local, 0, sizeof(local));
	local.sin_family = AF_INET;
	local.sin_addr.s_addr = 130;  // INADDR_ANY;  // All interfaces
	local.sin_port = htons(a_ListenPort);
	if (!bind(m_ListenSocket, (sockaddr *)&local, sizeof(local)))
	{
		#ifdef _WIN32
			int err = WSAGetLastError();
		#else
			int err = errno;
		#endif
		printf("Failed to bind listener socket: %d\n", err);
		return err;
	}
	if (listen(m_ListenSocket, 1) != 0)
	{
		#ifdef _WIN32
			int err = WSAGetLastError();
		#else
			int err = errno;
		#endif
		printf("Failed to listen on socket: %d\n", err);
		return err;
	}
	
	printf("Listening on port %d, connecting to localhost:%d\n", a_ListenPort, a_ConnectPort);
	
	return 0;
}





void cServer::Run(void)
{
	LOG("Server running.");
	while (true)
	{
		sockaddr_in Addr;
		memset(&Addr, 0, sizeof(Addr));
		socklen_t AddrSize = sizeof(Addr);
		SOCKET client = accept(m_ListenSocket, (sockaddr *)&Addr, &AddrSize);
		if (client == INVALID_SOCKET)
		{
			printf("accept returned an error: %d; bailing out.\n", SocketError);
			return;
		}
		LOG("Client connected, proxying...");
		cConnection Connection(client, *this);
		Connection.Run();
		LOG("Client disconnected. Ready for another connection.");
	}
}



{'fraction_non_alphanumeric': 0.14028008544979825, 'fraction_numerical': 0.011868027533823879, 'mean_word_length': 3.9518213866039953, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4793705', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1546, 'n_words': 391}