<commit_before>/*
 * Aerospike Client - C# Library
 *
 * Copyright 2013 by Aerospike, Inc. All rights reserved.
 *
 * Availability of this source code to partners and customers includes
 * redistribution rights covered by individual contract. Please check your
 * contract for exact rights and responsibilities.
 */
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace Aerospike.Client
{
	/// <summary>
	/// Asynchronous socket channel connection wrapper.
	/// </summary>
	public sealed class AsyncConnection
	{
		private readonly Socket socket;
		private readonly SocketAsyncEventArgs args;
		private readonly double maxSocketIdleMillis;
		private DateTime timestamp;

		public AsyncConnection(IPEndPoint address, AsyncCluster cluster, AsyncCommand command, EventHandler<SocketAsyncEventArgs> handler)
		{
			this.maxSocketIdleMillis = (double)(cluster.maxSocketIdle * 1000);

			try
			{
				socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
				socket.NoDelay = true;
				socket.Blocking = false;

				args = new SocketAsyncEventArgs();
				args.Completed += handler;
				args.RemoteEndPoint = address;
				args.UserToken = command;
				timestamp = DateTime.UtcNow;
			}
			catch (Exception e)
			{
				throw new AerospikeException.Connection(e);
			}
		}

		public SocketAsyncEventArgs SetCommand(AsyncCommand command)
		{
			args.UserToken = command;
			return args;
		}

		public bool ConnectAsync()
		{
			return socket.ConnectAsync(args);
		}

		public bool SendAsync(SocketAsyncEventArgs args)
		{
			return socket.SendAsync(args);
		}

		public bool ReceiveAsync(SocketAsyncEventArgs args)
		{<commit_msg>Set send/receive buffer sizes to zero.<commit_after>/*
 * Aerospike Client - C# Library
 *
 * Copyright 2013 by Aerospike, Inc. All rights reserved.
 *
 * Availability of this source code to partners and customers includes
 * redistribution rights covered by individual contract. Please check your
 * contract for exact rights and responsibilities.
 */
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace Aerospike.Client
{
	/// <summary>
	/// Asynchronous socket channel connection wrapper.
	/// </summary>
	public sealed class AsyncConnection
	{
		private readonly Socket socket;
		private readonly SocketAsyncEventArgs args;
		private readonly double maxSocketIdleMillis;
		private DateTime timestamp;

		public AsyncConnection(IPEndPoint address, AsyncCluster cluster, AsyncCommand command, EventHandler<SocketAsyncEventArgs> handler)
		{
			this.maxSocketIdleMillis = (double)(cluster.maxSocketIdle * 1000);

			try
			{
				socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
				socket.NoDelay = true;

				// Docs say Blocking flag is ignored for async operations.
				// socket.Blocking = false;

				// Avoid internal TCP send/receive buffers.
				// Use application buffers directly.
				socket.SendBufferSize = 0;
				socket.ReceiveBufferSize = 0;

				args = new SocketAsyncEventArgs();
				args.Completed += handler;
				args.RemoteEndPoint = address;
				args.UserToken = command;
				timestamp = DateTime.UtcNow;
			}
			catch (Exception e)
			{
				throw new AerospikeException.Connection(e);
			}
		}

		public SocketAsyncEventArgs SetCommand(AsyncCommand command)
		{
			args.UserToken = command;
			return args;
		}

		public bool ConnectAsync()
		{
			return socket.ConnectAsync(args);
		}

		public bool SendAsync(SocketAsyncEventArgs args)
		{
			return socket.SendAsync(args);
		}

		public bool ReceiveAsync(SocketAsyncEventArgs args)
		{
{'fraction_non_alphanumeric': 0.08179054987565626, 'fraction_numerical': 0.004973749654600719, 'mean_word_length': 3.8525469168900806, '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': '4541084', 'n_tokens_mistral': 1181, 'n_tokens_neox': 986, 'n_words': 299}