<commit_before>﻿using System;
using System.Net.Sockets;

namespace Codestellation.Statsd.Channels
{
    /// <summary>
    /// A UDP channel to send data to a statsd server. This is a recommended channel.
    /// </summary>
    public class UdpChannel : IChannel, IDisposable
    {
        private readonly UdpChannelSettings _settings;
        private readonly UdpClient _udpClient;

        /// <summary>
        /// Creates a new instance of <see cref="UdpChannel"/> class
        /// </summary>
        /// <param name="settings">Udp channel settings</param>
        public UdpChannel(UdpChannelSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            settings.Validate();
            _settings = settings;

            _udpClient = new UdpClient();
            TryConnect();
        }

        /// <summary>
        /// Creates a new instance of <see cref="UdpChannel"/> class
        /// </summary>
        /// <param name="hostname">Statsd server host. Must be either valid ip address or dns name</param>
        /// <param name="port">Port a statsd server listens to</param>
        public UdpChannel(string hostname, int port)
            : this(new UdpChannelSettings { Host = hostname, Port = port })
        {
        }

        /// <inheritdoc />
        public void Send(byte[] buffer, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (count == 0)
            {
                return;
            }
            if (!_udpClient.Client.Connected)
            {
                TryConnect();<commit_msg>UdpChannel does not connect eagerly (close #8)<commit_after>﻿using System;
using System.Net.Sockets;

namespace Codestellation.Statsd.Channels
{
    /// <summary>
    /// A UDP channel to send data to a statsd server. This is a recommended channel.
    /// </summary>
    public class UdpChannel : IChannel, IDisposable
    {
        private readonly UdpChannelSettings _settings;
        private readonly UdpClient _udpClient;

        /// <summary>
        /// Creates a new instance of <see cref="UdpChannel"/> class
        /// </summary>
        /// <param name="settings">Udp channel settings</param>
        public UdpChannel(UdpChannelSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            settings.Validate();
            _settings = settings;

            _udpClient = new UdpClient();
        }

        /// <summary>
        /// Creates a new instance of <see cref="UdpChannel"/> class
        /// </summary>
        /// <param name="hostname">Statsd server host. Must be either valid ip address or dns name</param>
        /// <param name="port">Port a statsd server listens to</param>
        public UdpChannel(string hostname, int port)
            : this(new UdpChannelSettings { Host = hostname, Port = port })
        {
        }

        /// <inheritdoc />
        public void Send(byte[] buffer, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (count == 0)
            {
                return;
            }
            if (!_udpClient.Client.Connected)
            {
                TryConnect();
{'fraction_non_alphanumeric': 0.10668196157155148, 'fraction_numerical': 0.0008603383997705764, 'mean_word_length': 1.634441087613293, 'pattern_counts': {'":': 0, '<': 33, '<?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': '799577', 'n_tokens_mistral': 906, 'n_tokens_neox': 879, 'n_words': 258}