<commit_before>﻿using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using EventStore.Common.Log;

namespace EventStore.Core.Tests.Helpers
{
    public static class PortsHelper
    {
        private static readonly ILogger Log = LogManager.GetLogger("PortsHelper");

        public const int PortStart = 50000;
        public const int PortCount = 200;

        private static readonly EventStore.Common.Concurrent.ConcurrentQueue<int> AvailablePorts = 
            new EventStore.Common.Concurrent.ConcurrentQueue<int>();

        public static void InitPorts(IPAddress ip)
        {
            var sw = Stopwatch.StartNew();

            int p;
            while (AvailablePorts.TryDequeue(out p))
            {
            }

            Log.Trace("PortsHelper: starting to examine ports at [0].", ip);

            int succ = 0;
            for (int port = PortStart; port < PortStart + PortCount; ++port)
            {
                try
                {
                    var listener = new TcpListener(ip, port);
                    listener.Start();
                    listener.Stop();
                }
                catch (Exception exc)
                {
                    Log.TraceException(exc, "PortsHelper: port {0} unavailable for TcpListener. Error: {1}.", exc.Message);
                    continue;<commit_msg>Fixed: port added to message.<commit_after>﻿using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using EventStore.Common.Log;

namespace EventStore.Core.Tests.Helpers
{
    public static class PortsHelper
    {
        private static readonly ILogger Log = LogManager.GetLogger("PortsHelper");

        public const int PortStart = 50000;
        public const int PortCount = 200;

        private static readonly EventStore.Common.Concurrent.ConcurrentQueue<int> AvailablePorts = 
            new EventStore.Common.Concurrent.ConcurrentQueue<int>();

        public static void InitPorts(IPAddress ip)
        {
            var sw = Stopwatch.StartNew();

            int p;
            while (AvailablePorts.TryDequeue(out p))
            {
            }

            Log.Trace("PortsHelper: starting to examine ports at [0].", ip);

            int succ = 0;
            for (int port = PortStart; port < PortStart + PortCount; ++port)
            {
                try
                {
                    var listener = new TcpListener(ip, port);
                    listener.Start();
                    listener.Stop();
                }
                catch (Exception exc)
                {
                    Log.TraceException(exc, "PortsHelper: port {0} unavailable for TcpListener. Error: {1}.", port, exc.Message);
                    continue;
{'fraction_non_alphanumeric': 0.08837689133425035, 'fraction_numerical': 0.008253094910591471, 'mean_word_length': 1.8270165208940718, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '2494255', 'n_tokens_mistral': 772, 'n_tokens_neox': 726, 'n_words': 202}