<commit_before>
#include <nanosoft/socket.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <string.h>

#include <stdio.h>

namespace nanosoft
{
	socket::socket(): sock(0)
	{
	}
	
	socket::~socket()
	{
		close();
	}
	
	bool socket::connect(const char *host, const char *port)
	{
		struct addrinfo hints, *addr;
		
		// закрыть сокет если открыт
		close();
		
		// first, load up address structs with getaddrinfo():
		memset(&hints, 0, sizeof hints);
		hints.ai_family = AF_UNSPEC;
		hints.ai_socktype = SOCK_STREAM;
		
		if ( getaddrinfo(host, port, &hints, &addr) == 0 )
		{
			int s = ::socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
			
			if ( s > 0 )
			{
				if ( ::connect(s, addr->ai_addr, addr->ai_addrlen) == 0 )
				{
					sock = s;
					return 1;
				}
				else
				{
					fprintf(stderr, "connect() fault\n");
				}
				
				::close(s);
			}
			else
			{
				fprintf(stderr, "socket() fault\n");
			}
			
			freeaddrinfo(addr);
		}
		else
		{
			fprintf(stderr, "getaddrinfo() fault\n");
		}<commit_msg>вывод удобочитаемого сообщения об ошибке getaddrinfo()<commit_after>
#include <nanosoft/socket.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <string.h>

#include <stdio.h>

namespace nanosoft
{
	socket::socket(): sock(0)
	{
	}
	
	socket::~socket()
	{
		close();
	}
	
	bool socket::connect(const char *host, const char *port)
	{
		struct addrinfo hints, *addr;
		
		// закрыть сокет если открыт
		close();
		
		// first, load up address structs with getaddrinfo():
		memset(&hints, 0, sizeof hints);
		hints.ai_family = AF_UNSPEC;
		hints.ai_socktype = SOCK_STREAM;
		
		int r = getaddrinfo(host, port, &hints, &addr);
		if ( r == 0 )
		{
			int s = ::socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
			
			if ( s > 0 )
			{
				if ( ::connect(s, addr->ai_addr, addr->ai_addrlen) == 0 )
				{
					sock = s;
					return 1;
				}
				else
				{
					fprintf(stderr, "connect() fault\n");
				}
				
				::close(s);
			}
			else
			{
				fprintf(stderr, "socket() fault\n");
			}
			
			freeaddrinfo(addr);
		}
		else
		{
			fprintf(stderr, "getaddrinfo() fault: %s\n", gai_strerror(r));
		}
{'fraction_non_alphanumeric': 0.16673847479534684, 'fraction_numerical': 0.005170185264971995, 'mean_word_length': 2.909090909090909, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, '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': '3564030', 'n_tokens_mistral': 1116, 'n_tokens_neox': 933, 'n_words': 196}