<commit_before>/* This code is subject to the terms of the Mozilla Public License, v.2.0. http://mozilla.org/MPL/2.0/. */
#include "udt_socket_set.h"

#include "udt/udt.h"
#include <iostream>

namespace
{
	int _epollReadFlag = EPOLLOpt::UDT_EPOLL_IN ^ EPOLLOpt::UDT_EPOLL_ERR;
	int _epollWriteFlag = EPOLLOpt::UDT_EPOLL_OUT ^ EPOLLOpt::UDT_EPOLL_ERR;
}

udt_socket_set::udt_socket_set(int flags)
	: _pollFlags(flags & WRITES? _epollWriteFlag : _epollReadFlag)
{
	_pollSet = UDT::epoll_create();
	if (_pollSet < 0)
		fatalError("couldn't get udt epoll to work: " + std::string(UDT::getlasterror().getErrorMessage()));
}

udt_socket_set::~udt_socket_set()
{
	release();
}

void udt_socket_set::release()
{
	if (_pollSet >= 0)
	{
		UDT::epoll_release(_pollSet);
		_pollSet = -1;
	}
}

bool udt_socket_set::good() const
{
	return _lastError.empty();
}

std::set<int> udt_socket_set::wait() const
{
	std::set<int> reads;
	std::set<int> writeReady;
	int waiters;
	if ((waiters = UDT::epoll_wait(_pollSet, &reads, &writeReady, 5000)) < 0)
	{
		std::cout << "epoll_wait did an error! :( " << waiters << std::endl;
		return reads;
	}

	if (_pollFlags == _epollWriteFlag)<commit_msg>Don't be so noisy...<commit_after>/* This code is subject to the terms of the Mozilla Public License, v.2.0. http://mozilla.org/MPL/2.0/. */
#include "udt_socket_set.h"

#include "udt/udt.h"
#include <iostream>

namespace
{
	int _epollReadFlag = EPOLLOpt::UDT_EPOLL_IN ^ EPOLLOpt::UDT_EPOLL_ERR;
	int _epollWriteFlag = EPOLLOpt::UDT_EPOLL_OUT ^ EPOLLOpt::UDT_EPOLL_ERR;
}

udt_socket_set::udt_socket_set(int flags)
	: _pollFlags(flags & WRITES? _epollWriteFlag : _epollReadFlag)
{
	_pollSet = UDT::epoll_create();
	if (_pollSet < 0)
		fatalError("couldn't get udt epoll to work: " + std::string(UDT::getlasterror().getErrorMessage()));
}

udt_socket_set::~udt_socket_set()
{
	release();
}

void udt_socket_set::release()
{
	if (_pollSet >= 0)
	{
		UDT::epoll_release(_pollSet);
		_pollSet = -1;
	}
}

bool udt_socket_set::good() const
{
	return _lastError.empty();
}

std::set<int> udt_socket_set::wait() const
{
	std::set<int> reads;
	std::set<int> writeReady;
	int waiters;
	if ((waiters = UDT::epoll_wait(_pollSet, &reads, &writeReady, 5000)) < 0)
	{
		//std::cout << "epoll_wait did an error! :( " << waiters << std::endl;
		return reads;
	}

	if (_pollFlags == _epollWriteFlag)
{'fraction_non_alphanumeric': 0.16050955414012738, 'fraction_numerical': 0.01019108280254777, 'mean_word_length': 5.350404312668464, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 13, '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': '3208488', 'n_tokens_mistral': 1027, 'n_tokens_neox': 985, 'n_words': 184}