<commit_before>#pragma once
#include "stdafx.h"
#include "udp.h"
#include "../error/error.h"

namespace augs {
	namespace network {

		udp::udp() : sock(INVALID_SOCKET) {}

		udp::~udp() {
			close();
		}

		bool udp::open() {
			auto res = err(((sock = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, 0, WSA_FLAG_OVERLAPPED)) != INVALID_SOCKET)) != 0;
			SetFileCompletionNotificationModes((HANDLE)sock, 0);
			return res;
		}

		bool udp::bind(unsigned short port = 0, char* ipv4) {
			addr = ip(port, ipv4);
			return err(::bind(sock, (struct sockaddr*)&addr.addr, sizeof(addr)) == 0) != 0;
		}
		

		int udp::send(overlapped* request) {
			return err((WSASendTo(sock, (LPWSABUF)&request->associated_buffer, 1,
				&request->result, 
				request->flags, 
				(SOCKADDR*)&request->associated_address.addr, 
				request->associated_address.size, &request->overlap, 0) == 0) ? 2 : WSAGetLastError() == WSA_IO_PENDING);
		}
		
		void udp::set_blocking(bool) {
			DWORD nonBlocking = 1;
			err(ioctlsocket(sock,
				FIONBIO,
				&nonBlocking) == 0);
		}
		//int udp::send(const ip& to, const wsabuf* bufs, int bufcnt, overlapped* request) {
		//	return err((WSASendTo(sock, (LPWSABUF)bufs, bufcnt, &request->result, request->flags, (SOCKADDR*)&to.addr, to.size, &request->overlap, 0) == 0) ? 2 : WSAGetLastError() == WSA_IO_PENDING );<commit_msg>corrected bug<commit_after>#pragma once
#include "stdafx.h"
#include "udp.h"
#include "../error/error.h"

namespace augs {
	namespace network {

		udp::udp() : sock(INVALID_SOCKET) {}

		udp::~udp() {
			close();
		}

		bool udp::open() {
			auto res = err(((sock = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, 0, WSA_FLAG_OVERLAPPED)) != INVALID_SOCKET)) != 0;
			SetFileCompletionNotificationModes((HANDLE)sock, 0);
			return res;
		}

		bool udp::bind(unsigned short port = 0, char* ipv4) {
			addr = ip(port, ipv4);
			return err(::bind(sock, (struct sockaddr*)&addr.addr, sizeof(addr)) == 0) != 0;
		}
		

		int udp::send(overlapped* request) {
			return err((WSASendTo(sock, (LPWSABUF)&request->associated_buffer, 1,
				&request->result, 
				request->flags, 
				(SOCKADDR*)&request->associated_address.addr, 
				request->associated_address.size, &request->overlap, 0) == 0) ? 2 : WSAGetLastError() == WSA_IO_PENDING);
		}
		
		void udp::set_blocking(bool flag) {
			DWORD nonBlocking = flag ? 0 : 1;
			err(ioctlsocket(sock,
				FIONBIO,
				&nonBlocking) == NO_ERROR);
		}
		//int udp::send(const ip& to, const wsabuf* bufs, int bufcnt, overlapped* request) {
		//	return err((WSASendTo(sock, (LPWSABUF)bufs, bufcnt, &request->result, request->flags, (SOCKADDR*)&to.addr, to.size, &request->overlap, 0) == 0) ? 2 : WSAGetLastError() == WSA_IO_PENDING );
{'fraction_non_alphanumeric': 0.1723756906077348, 'fraction_numerical': 0.012523020257826888, 'mean_word_length': 4.294346978557505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '2456331', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1046, 'n_words': 206}