<commit_before>﻿// Original Work Copyright (c) <NAME> 2014-2016
// This file is subject to the GPL v2 License
// For additional details, see the LICENSE file

using System.Threading.Tasks;

namespace EOLib.Net.Communication
{
	public class PacketSendService : IPacketSendService
	{
		private readonly INetworkClientProvider _networkClientProvider;
		private readonly IPacketQueueProvider _packetQueueProvider;

		public PacketSendService(INetworkClientProvider networkClientProvider,
			IPacketQueueProvider packetQueueProvider)
		{
			_networkClientProvider = networkClientProvider;
			_packetQueueProvider = packetQueueProvider;
		}

		public void SendPacket(IPacket packet)
		{
			var bytes = Client.Send(packet);
			if (bytes == 0 || bytes != packet.Length)
				throw new NoDataSentException();
		}

		public async Task SendPacketAsync(IPacket packet)
		{
			var bytes = await Client.SendAsync(packet);
			if (bytes == 0 || bytes != packet.Length)
				throw new NoDataSentException();
		}

		public async Task<IPacket> SendRawPacketAndWaitAsync(IPacket packet)
		{
			var bytes = await Client.SendRawPacketAsync(packet);
			if (bytes == 0 || bytes != packet.Length)
				throw new NoDataSentException();

			var responsePacket = await _packetQueueProvider.PacketQueue.WaitForPacketAndDequeue();
			if (responsePacket is EmptyPacket)
				throw new EmptyPacketReceivedException();

			return responsePacket;
		}

		public async Task<IPacket> SendEncodedPacketAndWaitAsync(IPacket packet)
		{
			var bytes = await Client.SendAsync(packet);
			if (bytes == 0 || bytes != packet.Length)
				throw new NoDataSentException();<commit_msg>Remove check for bytes sent<commit_after>﻿// Original Work Copyright (c) <NAME> 2014-2016
// This file is subject to the GPL v2 License
// For additional details, see the LICENSE file

using System.Threading.Tasks;

namespace EOLib.Net.Communication
{
	public class PacketSendService : IPacketSendService
	{
		private readonly INetworkClientProvider _networkClientProvider;
		private readonly IPacketQueueProvider _packetQueueProvider;

		public PacketSendService(INetworkClientProvider networkClientProvider,
			IPacketQueueProvider packetQueueProvider)
		{
			_networkClientProvider = networkClientProvider;
			_packetQueueProvider = packetQueueProvider;
		}

		public void SendPacket(IPacket packet)
		{
			var bytes = Client.Send(packet);
			if (bytes == 0)
				throw new NoDataSentException();
		}

		public async Task SendPacketAsync(IPacket packet)
		{
			var bytes = await Client.SendAsync(packet);
			if (bytes == 0)
				throw new NoDataSentException();
		}

		public async Task<IPacket> SendRawPacketAndWaitAsync(IPacket packet)
		{
			var bytes = await Client.SendRawPacketAsync(packet);
			if (bytes == 0)
				throw new NoDataSentException();

			var responsePacket = await _packetQueueProvider.PacketQueue.WaitForPacketAndDequeue();
			if (responsePacket is EmptyPacket)
				throw new EmptyPacketReceivedException();

			return responsePacket;
		}

		public async Task<IPacket> SendEncodedPacketAndWaitAsync(IPacket packet)
		{
			var bytes = await Client.SendAsync(packet);
			if (bytes == 0)
				throw new NoDataSentException();
{'fraction_non_alphanumeric': 0.07808564231738035, 'fraction_numerical': 0.00818639798488665, 'mean_word_length': 4.724324324324324, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4430708', 'n_tokens_mistral': 1029, 'n_tokens_neox': 860, 'n_words': 249}