Decompiled source of Aeron Client v1.49.0

BepInEx/core/Aeron.Client/netstandard2.0/Adaptive.Aeron.dll

Decompiled 2 months ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using Adaptive.Aeron.Command;
using Adaptive.Aeron.Exceptions;
using Adaptive.Aeron.LogBuffer;
using Adaptive.Aeron.Status;
using Adaptive.Agrona;
using Adaptive.Agrona.Collections;
using Adaptive.Agrona.Concurrent;
using Adaptive.Agrona.Concurrent.Broadcast;
using Adaptive.Agrona.Concurrent.Errors;
using Adaptive.Agrona.Concurrent.RingBuffer;
using Adaptive.Agrona.Concurrent.Status;
using Adaptive.Agrona.Util;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("Adaptive.Aeron.Tests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("Adaptive Financial Consulting Ltd.")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright Adaptive Financial Consulting Ltd.")]
[assembly: AssemblyDescription("Efficient reliable UDP unicast, UDP multicast, and IPC transport protocol.")]
[assembly: AssemblyFileVersion("1.49.0.0")]
[assembly: AssemblyInformationalVersion("1.49.0+9179232fd342a742df7b8c88046b0306e4a0fc2e")]
[assembly: AssemblyProduct("Aeron Client")]
[assembly: AssemblyTitle("Adaptive.Aeron")]
[assembly: AssemblyVersion("1.49.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
}
namespace Adaptive.Aeron
{
	public class Aeron : IDisposable
	{
		public static class Configuration
		{
			private class DefaultErrorHandler : IErrorHandler
			{
				public void OnError(Exception throwable)
				{
					lock (Console.Error)
					{
						Console.Error.WriteLine(throwable);
					}
					if (throwable is DriverTimeoutException)
					{
						Console.Error.WriteLine();
						Console.Error.WriteLine("***");
						Console.Error.WriteLine("*** Media Driver timeout - is it running? exiting client...");
						Console.Error.WriteLine("***");
						Environment.Exit(-1);
					}
				}
			}

			public static readonly int IDLE_SLEEP_DEFAULT_MS = 16;

			public static readonly int AWAITING_IDLE_SLEEP_MS = 1;

			public static readonly string IDLE_SLEEP_DURATION_PROP_NAME = "aeron.client.idle.sleep.duration";

			public static readonly long IDLE_SLEEP_DEFAULT_NS = NanoUtil.FromMilliseconds((long)IDLE_SLEEP_DEFAULT_MS);

			public static readonly long KeepaliveIntervalNs = NanoUtil.FromMilliseconds(500L);

			public const string RESOURCE_LINGER_DURATION_PROP_NAME = "aeron.client.resource.linger.duration";

			public static readonly long RESOURCE_LINGER_DURATION_DEFAULT_NS = NanoUtil.FromSeconds(3L);

			public const string CLOSE_LINGER_DURATION_PROP_NAME = "aeron.client.close.linger.duration";

			public const long CLOSE_LINGER_DURATION_DEFAULT_NS = 0L;

			public const string PRE_TOUCH_MAPPED_MEMORY_PROP_NAME = "aeron.pre.touch.mapped.memory";

			public const bool PRE_TOUCH_MAPPED_MEMORY_DEFAULT = false;

			public static readonly string CLIENT_NAME_PROP_NAME = "aeron.client.name";

			public static readonly IErrorHandler DEFAULT_ERROR_HANDLER = (IErrorHandler)(object)new DefaultErrorHandler();

			public const int MAX_CLIENT_NAME_LENGTH = 100;

			public static long IdleSleepDurationNs()
			{
				return Config.GetDurationInNanos(IDLE_SLEEP_DURATION_PROP_NAME, IDLE_SLEEP_DEFAULT_NS);
			}

			public static long ResourceLingerDurationNs()
			{
				return Config.GetDurationInNanos("aeron.client.resource.linger.duration", RESOURCE_LINGER_DURATION_DEFAULT_NS);
			}

			public static long CloseLingerDurationNs()
			{
				return Config.GetDurationInNanos("aeron.client.close.linger.duration", 0L);
			}

			public static bool PreTouchMappedMemory()
			{
				string property = Config.GetProperty("aeron.pre.touch.mapped.memory");
				if (property != null)
				{
					return bool.Parse(property);
				}
				return false;
			}

			public static string ClientName()
			{
				return Config.GetProperty(CLIENT_NAME_PROP_NAME, "");
			}
		}

		public class Context : IDisposable
		{
			private class ErrorHandlerWrapper : IErrorHandler, IDisposable
			{
				private readonly LoggingErrorHandler _loggingErrorHandler;

				private readonly IErrorHandler _userErrorHandler;

				public ErrorHandlerWrapper(LoggingErrorHandler loggingErrorHandler, IErrorHandler userErrorHandler)
				{
					_loggingErrorHandler = loggingErrorHandler;
					_userErrorHandler = userErrorHandler;
					throw new NotImplementedException();
				}

				public void OnError(Exception exception)
				{
					_loggingErrorHandler.OnError(exception);
					_userErrorHandler.OnError(exception);
				}

				public void Dispose()
				{
					_loggingErrorHandler.Dispose();
					if (_userErrorHandler is IDisposable disposable)
					{
						CloseHelper.QuietDispose(disposable);
					}
				}
			}

			private long _clientId;

			private string clientName = Configuration.ClientName();

			private bool _useConductorAgentInvoker;

			private bool _preTouchMappedMemory = Configuration.PreTouchMappedMemory();

			private AgentInvoker _driverAgentInvoker;

			private ILock _clientLock;

			private IEpochClock _epochClock;

			private INanoClock _nanoClock;

			private IIdleStrategy _idleStrategy;

			private IIdleStrategy _awaitingIdleStrategy;

			private CopyBroadcastReceiver _toClientBuffer;

			private IRingBuffer _toDriverBuffer;

			private DriverProxy _driverProxy;

			private ILogBuffersFactory _logBuffersFactory;

			private IErrorHandler _errorHandler;

			private IErrorHandler _subscriberErrorHandler;

			private AvailableImageHandler _availableImageHandler;

			private UnavailableImageHandler _unavailableImageHandler;

			private AvailableCounterHandler _availableCounterHandler;

			private UnavailableCounterHandler _unavailableCounterHandler;

			private IPublicationErrorFrameHandler publicationErrorFrameHandler = new NoOpPublicationErrorFrameHandler();

			private Action _closeHandler;

			private long _keepAliveIntervalNs = Configuration.KeepaliveIntervalNs;

			private long _interServiceTimeoutNs;

			private long idleSleepDurationNs = Configuration.IdleSleepDurationNs();

			private long _resourceLingerDurationNs = Configuration.ResourceLingerDurationNs();

			private long _closeLingerDurationNs = Configuration.CloseLingerDurationNs();

			private int filePageSize;

			private int _isConcluded;

			private long _driverTimeoutMs = 10000L;

			private string _aeronDirectoryName = GetAeronDirectoryName();

			private DirectoryInfo _aeronDirectory;

			private FileInfo _cncFile;

			private bool enableExperimentalFeatures = Config.GetBoolean("aeron.enable.experimental.features");

			private MappedByteBuffer _cncByteBuffer;

			private UnsafeBuffer _cncMetaDataBuffer;

			private UnsafeBuffer _countersMetaDataBuffer;

			private UnsafeBuffer _countersValuesBuffer;

			private IThreadFactory _threadFactory = (IThreadFactory)new DefaultThreadFactory();

			public const string AERON_DIR_PROP_NAME = "aeron.dir";

			public static readonly string AERON_DIR_PROP_DEFAULT;

			public const string ENABLE_EXPERIMENTAL_FEATURES_PROP_NAME = "aeron.enable.experimental.features";

			public const string FALLBACK_LOGGER_PROP_NAME = "aeron.fallback.logger";

			public const string IPC_MEDIA = "ipc";

			public const string UDP_MEDIA = "udp";

			public const string IPC_CHANNEL = "aeron:ipc";

			public const string UDP_CHANNEL = "aeron:udp";

			public const string SPY_PREFIX = "aeron-spy:";

			public const string ENDPOINT_PARAM_NAME = "endpoint";

			public const string INTERFACE_PARAM_NAME = "interface";

			public const string DEBUG_TIMEOUT_PROP_NAME = "aeron.debug.timeout";

			public const string PRINT_CONFIGURATION_ON_START_PROP_NAME = "aeron.print.configuration";

			public const long DRIVER_TIMEOUT_MS = 10000L;

			public const int NULL_SESSION_ID = -1;

			public const string INITIAL_TERM_ID_PARAM_NAME = "init-term-id";

			public const string TERM_ID_PARAM_NAME = "term-id";

			public const string TERM_OFFSET_PARAM_NAME = "term-offset";

			public const string TERM_LENGTH_PARAM_NAME = "term-length";

			public const string MTU_LENGTH_PARAM_NAME = "mtu";

			public const string TTL_PARAM_NAME = "ttl";

			public const string MDC_CONTROL_PARAM_NAME = "control";

			public const string MDC_CONTROL_MODE_PARAM_NAME = "control-mode";

			public const string MTU_LENGTH_URI_PARAM_NAME = "mtu";

			public const string MDC_CONTROL_MODE = "control-mode";

			public const string MDC_CONTROL_MODE_MANUAL = "manual";

			public const string MDC_CONTROL_MODE_DYNAMIC = "dynamic";

			public const string CONTROL_MODE_RESPONSE = "response";

			public const string SESSION_ID_PARAM_NAME = "session-id";

			public const string LINGER_PARAM_NAME = "linger";

			public const string RELIABLE_STREAM_PARAM_NAME = "reliable";

			public const string TAGS_PARAM_NAME = "tags";

			public const string TAG_PREFIX = "tag:";

			public const string SPARSE_PARAM_NAME = "sparse";

			public const string ALIAS_PARAM_NAME = "alias";

			public const string EOS_PARAM_NAME = "eos";

			public const string TETHER_PARAM_NAME = "tether";

			public const string GROUP_PARAM_NAME = "group";

			public const string REJOIN_PARAM_NAME = "rejoin";

			public const string CONGESTION_CONTROL_PARAM_NAME = "cc";

			public const string FLOW_CONTROL_PARAM_NAME = "fc";

			public const string GROUP_TAG_PARAM_NAME = "gtag";

			public const string SPIES_SIMULATE_CONNECTION_PARAM_NAME = "ssc";

			public const string SOCKET_SNDBUF_PARAM_NAME = "so-sndbuf";

			public const string SOCKET_RCVBUF_PARAM_NAME = "so-rcvbuf";

			public const string RECEIVER_WINDOW_LENGTH_PARAM_NAME = "rcv-wnd";

			public const string MEDIA_RCV_TIMESTAMP_OFFSET_PARAM_NAME = "media-rcv-ts-offset";

			public const string CHANNEL_RECEIVE_TIMESTAMP_OFFSET_PARAM_NAME = "channel-rcv-ts-offset";

			public const string CHANNEL_SEND_TIMESTAMP_OFFSET_PARAM_NAME = "channel-snd-ts-offset";

			public const string RESERVED_OFFSET = "reserved";

			public const string RESPONSE_ENDPOINT_PARAM_NAME = "response-endpoint";

			public const string RESPONSE_CORRELATION_ID_PARAM_NAME = "response-correlation-id";

			public const string PROTOTYPE_CORRELATION_ID = "prototype";

			public const string NAK_DELAY_PARAM_NAME = "nak-delay";

			public const string UNTETHERED_WINDOW_LIMIT_TIMEOUT_PARAM_NAME = "untethered-window-limit-timeout";

			public const string UNTETHERED_LINGER_TIMEOUT_PARAM_NAME = "untethered-linger-timeout";

			public const string UNTETHERED_RESTING_TIMEOUT_PARAM_NAME = "untethered-resting-timeout";

			public const string MAX_RESEND_PARAM_NAME = "max-resend";

			public const string STREAM_ID_PARAM_NAME = "stream-id";

			public const string PUBLICATION_WINDOW_LENGTH_PARAM_NAME = "pub-wnd";

			private static readonly ConcurrentDictionary<string, bool> DebugFieldsSeen;

			public bool IsConcluded => 1 == _isConcluded;

			static Context()
			{
				DebugFieldsSeen = new ConcurrentDictionary<string, bool>();
				string text = null;
				if (Environment.OSVersion.Platform == PlatformID.Unix && Directory.Exists("/dev/shm"))
				{
					text = "/dev/shm/aeron";
				}
				if (text == null)
				{
					text = Path.Combine(Path.GetTempPath(), "aeron");
				}
				AERON_DIR_PROP_DEFAULT = text + "-" + Environment.UserName;
			}

			public static bool ShouldPrintConfigurationOnStart()
			{
				return "true".Equals(Config.GetProperty("aeron.print.configuration"));
			}

			public static TextWriter FallbackLogger()
			{
				return Config.GetProperty("aeron.fallback.logger", "stderr") switch
				{
					"stdout" => Console.Out, 
					"noop" => new StreamWriter(Stream.Null), 
					_ => Console.Error, 
				};
			}

			public static string GetAeronDirectoryName()
			{
				return Config.GetProperty("aeron.dir", AERON_DIR_PROP_DEFAULT);
			}

			public Context ConcludeAeronDirectory()
			{
				if (_aeronDirectory == null)
				{
					_aeronDirectory = new DirectoryInfo(_aeronDirectoryName);
				}
				return this;
			}

			public Context Clone()
			{
				return (Context)MemberwiseClone();
			}

			public Context Conclude()
			{
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Expected O, but got Unknown
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0136: Expected O, but got Unknown
				//IL_0144: Unknown result type (might be due to invalid IL or missing references)
				//IL_014e: Expected O, but got Unknown
				//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d3: Expected O, but got Unknown
				//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0201: Expected O, but got Unknown
				//IL_0201: Expected O, but got Unknown
				//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0206: Expected O, but got Unknown
				if (Interlocked.Exchange(ref _isConcluded, 1) != 0)
				{
					throw new ConcurrentConcludeException();
				}
				ConcludeAeronDirectory();
				_cncFile = new FileInfo(Path.Combine(_aeronDirectory.FullName, "cnc.dat"));
				if (_clientLock == null)
				{
					_clientLock = (ILock)new ReentrantLock();
				}
				else if (_clientLock is NoOpLock && !_useConductorAgentInvoker)
				{
					throw new ConfigurationException("Must use Aeron.Context.UseConductorAgentInvoker(true) when Aeron.Context.ClientLock(...) is using a NoOpLock");
				}
				if (_driverAgentInvoker != null && !_useConductorAgentInvoker)
				{
					throw new ConfigurationException("Must use Aeron.Context.useConductorAgentInvoker(true) when Aeron.Context.driverAgentInvoker() is set");
				}
				if (clientName.Length > 100)
				{
					throw new ConfigurationException("clientName length must <= " + 100);
				}
				if (_epochClock == null)
				{
					_epochClock = (IEpochClock)(object)SystemEpochClock.INSTANCE;
				}
				if (_nanoClock == null)
				{
					_nanoClock = (INanoClock)(object)SystemNanoClock.INSTANCE;
				}
				if (idleSleepDurationNs < 0 || idleSleepDurationNs > 1000000000)
				{
					throw new ConfigurationException("Invalid idle sleep duration: " + idleSleepDurationNs + "ns");
				}
				if (_idleStrategy == null)
				{
					_idleStrategy = (IIdleStrategy)new SleepingIdleStrategy((int)TimeUnit.NANOSECONDS.ToMillis(idleSleepDurationNs));
				}
				if (_awaitingIdleStrategy == null)
				{
					_awaitingIdleStrategy = (IIdleStrategy)new SleepingIdleStrategy(Configuration.AWAITING_IDLE_SLEEP_MS);
				}
				ConnectToDriver();
				filePageSize = DriverFilePageSize((IDirectBuffer)(object)_cncMetaDataBuffer);
				_interServiceTimeoutNs = CncFileDescriptor.ClientLivenessTimeoutNs((IDirectBuffer)(object)_cncMetaDataBuffer);
				if (_interServiceTimeoutNs <= _keepAliveIntervalNs)
				{
					throw new ConfigurationException("interServiceTimeoutNs=" + _interServiceTimeoutNs + " <= keepAliveIntervalNs=" + _keepAliveIntervalNs);
				}
				if (_toDriverBuffer == null)
				{
					_toDriverBuffer = (IRingBuffer)new ManyToOneRingBuffer((IAtomicBuffer)(object)CncFileDescriptor.CreateToDriverBuffer(_cncByteBuffer, (IDirectBuffer)(object)_cncMetaDataBuffer));
				}
				if (_toClientBuffer == null)
				{
					_toClientBuffer = new CopyBroadcastReceiver(new BroadcastReceiver((IAtomicBuffer)(object)CncFileDescriptor.CreateToClientsBuffer(_cncByteBuffer, (IDirectBuffer)(object)_cncMetaDataBuffer)), (IMutableDirectBuffer)new ExpandableArrayBuffer(4096));
				}
				if (CountersMetaDataBuffer() == null)
				{
					CountersMetaDataBuffer(CncFileDescriptor.CreateCountersMetaDataBuffer(_cncByteBuffer, (IDirectBuffer)(object)_cncMetaDataBuffer));
				}
				if (CountersValuesBuffer() == null)
				{
					CountersValuesBuffer(CncFileDescriptor.CreateCountersValuesBuffer(_cncByteBuffer, (IDirectBuffer)(object)_cncMetaDataBuffer));
				}
				if (_logBuffersFactory == null)
				{
					_logBuffersFactory = new MappedLogBuffersFactory();
				}
				if (_errorHandler == null)
				{
					_errorHandler = Configuration.DEFAULT_ERROR_HANDLER;
				}
				if (_subscriberErrorHandler == null)
				{
					_subscriberErrorHandler = _errorHandler;
				}
				if (_availableImageHandler == null)
				{
					_availableImageHandler = delegate
					{
					};
				}
				if (_unavailableImageHandler == null)
				{
					_unavailableImageHandler = delegate
					{
					};
				}
				if (_driverProxy == null)
				{
					_clientId = _toDriverBuffer.NextCorrelationId();
					_driverProxy = new DriverProxy(ToDriverBuffer(), _clientId);
				}
				return this;
			}

			public long ClientId()
			{
				return _clientId;
			}

			public Context ClientName(string clientName)
			{
				this.clientName = (string.IsNullOrEmpty(clientName) ? "" : clientName);
				return this;
			}

			public string ClientName()
			{
				return clientName;
			}

			public FileInfo CncFile()
			{
				return _cncFile;
			}

			public Context UseConductorAgentInvoker(bool useConductorAgentInvoker)
			{
				_useConductorAgentInvoker = useConductorAgentInvoker;
				return this;
			}

			public bool UseConductorAgentInvoker()
			{
				return _useConductorAgentInvoker;
			}

			public Context PreTouchMappedMemory(bool preTouchMappedMemory)
			{
				_preTouchMappedMemory = preTouchMappedMemory;
				return this;
			}

			public bool PreTouchMappedMemory()
			{
				return _preTouchMappedMemory;
			}

			public Context DriverAgentInvoker(AgentInvoker driverAgentInvoker)
			{
				_driverAgentInvoker = driverAgentInvoker;
				return this;
			}

			public AgentInvoker DriverAgentInvoker()
			{
				return _driverAgentInvoker;
			}

			public Context ClientLock(ILock @lock)
			{
				_clientLock = @lock;
				return this;
			}

			public ILock ClientLock()
			{
				return _clientLock;
			}

			public Context EpochClock(IEpochClock clock)
			{
				_epochClock = clock;
				return this;
			}

			public IEpochClock EpochClock()
			{
				return _epochClock;
			}

			public Context NanoClock(INanoClock clock)
			{
				_nanoClock = clock;
				return this;
			}

			public INanoClock NanoClock()
			{
				return _nanoClock;
			}

			public Context IdleStrategy(IIdleStrategy idleStrategy)
			{
				_idleStrategy = idleStrategy;
				return this;
			}

			public IIdleStrategy IdleStrategy()
			{
				return _idleStrategy;
			}

			public Context AwaitingIdleStrategy(IIdleStrategy idleStrategy)
			{
				_awaitingIdleStrategy = idleStrategy;
				return this;
			}

			public IIdleStrategy AwaitingIdleStrategy()
			{
				return _awaitingIdleStrategy;
			}

			internal Context ToClientBuffer(CopyBroadcastReceiver toClientBuffer)
			{
				_toClientBuffer = toClientBuffer;
				return this;
			}

			public CopyBroadcastReceiver ToClientBuffer()
			{
				return _toClientBuffer;
			}

			public IRingBuffer ToDriverBuffer()
			{
				return _toDriverBuffer;
			}

			internal Context DriverProxy(DriverProxy driverProxy)
			{
				_driverProxy = driverProxy;
				return this;
			}

			public DriverProxy DriverProxy()
			{
				return _driverProxy;
			}

			internal Context LogBuffersFactory(ILogBuffersFactory logBuffersFactory)
			{
				_logBuffersFactory = logBuffersFactory;
				return this;
			}

			internal ILogBuffersFactory LogBuffersFactory()
			{
				return _logBuffersFactory;
			}

			public Context ErrorHandler(IErrorHandler errorHandler)
			{
				_errorHandler = errorHandler;
				return this;
			}

			public IErrorHandler ErrorHandler()
			{
				return _errorHandler;
			}

			public Context SubscriberErrorHandler(IErrorHandler errorHandler)
			{
				_subscriberErrorHandler = errorHandler;
				return this;
			}

			public IErrorHandler SubscriberErrorHandler()
			{
				return _subscriberErrorHandler;
			}

			public Context AvailableImageHandler(AvailableImageHandler handler)
			{
				_availableImageHandler = handler;
				return this;
			}

			public AvailableImageHandler AvailableImageHandler()
			{
				return _availableImageHandler;
			}

			public Context UnavailableImageHandler(UnavailableImageHandler handler)
			{
				_unavailableImageHandler = handler;
				return this;
			}

			public UnavailableImageHandler UnavailableImageHandler()
			{
				return _unavailableImageHandler;
			}

			public Context AvailableCounterHandler(AvailableCounterHandler handler)
			{
				_availableCounterHandler = handler;
				return this;
			}

			public AvailableCounterHandler AvailableCounterHandler()
			{
				return _availableCounterHandler;
			}

			public Context UnavailableCounterHandler(UnavailableCounterHandler handler)
			{
				_unavailableCounterHandler = handler;
				return this;
			}

			public UnavailableCounterHandler UnavailableCounterHandler()
			{
				return _unavailableCounterHandler;
			}

			public Context CloseHandler(Action handler)
			{
				_closeHandler = handler;
				return this;
			}

			public Action CloseHandler()
			{
				return _closeHandler;
			}

			public UnsafeBuffer CountersMetaDataBuffer()
			{
				return _countersMetaDataBuffer;
			}

			public Context CountersMetaDataBuffer(UnsafeBuffer countersMetaDataBuffer)
			{
				_countersMetaDataBuffer = countersMetaDataBuffer;
				return this;
			}

			public UnsafeBuffer CountersValuesBuffer()
			{
				return _countersValuesBuffer;
			}

			public Context CountersValuesBuffer(UnsafeBuffer countersValuesBuffer)
			{
				_countersValuesBuffer = countersValuesBuffer;
				return this;
			}

			public Context KeepAliveIntervalNs(long value)
			{
				_keepAliveIntervalNs = value;
				return this;
			}

			public long KeepAliveIntervalNs()
			{
				return _keepAliveIntervalNs;
			}

			public Context DriverTimeoutMs(long driverTimeoutMs)
			{
				_driverTimeoutMs = driverTimeoutMs;
				return this;
			}

			public long DriverTimeoutMs()
			{
				return CheckDebugTimeout(_driverTimeoutMs, TimeUnit.MILLIS, "DriverTimeoutMs");
			}

			public bool EnableExperimentalFeatures()
			{
				return enableExperimentalFeatures;
			}

			public Context EnableExperimentalFeatures(bool enableExperimentalFeatures)
			{
				this.enableExperimentalFeatures = enableExperimentalFeatures;
				return this;
			}

			public static long CheckDebugTimeout(long timeout, TimeUnit timeUnit, string debugFieldName)
			{
				return CheckDebugTimeout(timeout, timeUnit, 1.0, debugFieldName);
			}

			public static long CheckDebugTimeout(long timeout, TimeUnit timeUnit, double factor, string debugFieldName)
			{
				string property = Config.GetProperty("aeron.debug.timeout");
				if (property == null || !Debugger.IsAttached)
				{
					return timeout;
				}
				try
				{
					long num = (long)(factor * (double)SystemUtil.ParseDuration("aeron.debug.timeout", property));
					long result = timeUnit.Convert(num, TimeUnit.NANOSECONDS);
					if (DebugFieldsSeen.TryAdd(debugFieldName, value: true))
					{
						Console.WriteLine("Using debug timeout [" + result + "] for " + debugFieldName + " replacing [" + timeout + "]");
					}
					return result;
				}
				catch (FormatException)
				{
					return timeout;
				}
			}

			internal Context InterServiceTimeoutNs(long interServiceTimeout)
			{
				_interServiceTimeoutNs = interServiceTimeout;
				return this;
			}

			public long InterServiceTimeoutNs()
			{
				return CheckDebugTimeout(_interServiceTimeoutNs, TimeUnit.NANOSECONDS, "InterServiceTimeoutNs");
			}

			public Context IdleSleepDurationNs(long idleSleepDurationNs)
			{
				this.idleSleepDurationNs = idleSleepDurationNs;
				return this;
			}

			public long IdleSleepDurationNs()
			{
				return idleSleepDurationNs;
			}

			public Context ResourceLingerDurationNs(long resourceLingerDurationNs)
			{
				_resourceLingerDurationNs = resourceLingerDurationNs;
				return this;
			}

			public long ResourceLingerDurationNs()
			{
				return _resourceLingerDurationNs;
			}

			public Context CloseLingerDurationNs(long closeLingerDurationNs)
			{
				_closeLingerDurationNs = closeLingerDurationNs;
				return this;
			}

			public long CloseLingerDurationNs()
			{
				return _closeLingerDurationNs;
			}

			public string AeronDirectoryName()
			{
				return _aeronDirectoryName;
			}

			public DirectoryInfo AeronDirectory()
			{
				return _aeronDirectory;
			}

			public Context AeronDirectoryName(string dirName)
			{
				_aeronDirectoryName = dirName;
				return this;
			}

			public Context ThreadFactory(IThreadFactory threadFactory)
			{
				_threadFactory = threadFactory;
				return this;
			}

			public IThreadFactory ThreadFactory()
			{
				return _threadFactory;
			}

			public Context PublicationErrorFrameHandler(IPublicationErrorFrameHandler publicationErrorFrameHandler)
			{
				this.publicationErrorFrameHandler = Objects.RequireNonNull<IPublicationErrorFrameHandler>(publicationErrorFrameHandler);
				return this;
			}

			public IPublicationErrorFrameHandler PublicationErrorFrameHandler()
			{
				return publicationErrorFrameHandler;
			}

			public int FilePageSize()
			{
				return filePageSize;
			}

			public void Dispose()
			{
				MappedByteBuffer cncByteBuffer = _cncByteBuffer;
				if (cncByteBuffer != null)
				{
					cncByteBuffer.Dispose();
				}
				_cncByteBuffer = null;
				UnsafeBuffer cncMetaDataBuffer = _cncMetaDataBuffer;
				if (cncMetaDataBuffer != null)
				{
					cncMetaDataBuffer.Dispose();
				}
				UnsafeBuffer countersMetaDataBuffer = _countersMetaDataBuffer;
				if (countersMetaDataBuffer != null)
				{
					countersMetaDataBuffer.Dispose();
				}
				UnsafeBuffer countersValuesBuffer = _countersValuesBuffer;
				if (countersValuesBuffer != null)
				{
					countersValuesBuffer.Dispose();
				}
				MappedByteBuffer cncByteBuffer2 = _cncByteBuffer;
				if (cncByteBuffer2 != null)
				{
					cncByteBuffer2.Dispose();
				}
			}

			public override string ToString()
			{
				return "Aeron.Context\n{\n    isConcluded=" + _isConcluded + "\n    aeronDirectory=" + AeronDirectory()?.ToString() + "\n    aeronDirectoryName='" + AeronDirectoryName() + "'\n    cncFile=" + CncFile()?.ToString() + "\n    countersMetaDataBuffer=" + ((object)CountersMetaDataBuffer())?.ToString() + "\n    countersValuesBuffer=" + ((object)CountersValuesBuffer())?.ToString() + "\n    driverTimeoutMs=" + DriverTimeoutMs() + "\n    clientId=" + _clientId + "\n    clientName=" + clientName + "\n    useConductorAgentInvoker=" + _useConductorAgentInvoker + "\n    preTouchMappedMemory=" + _preTouchMappedMemory + "\n    driverAgentInvoker=" + ((object)_driverAgentInvoker)?.ToString() + "\n    clientLock=" + ((object)_clientLock)?.ToString() + "\n    epochClock=" + ((object)_epochClock)?.ToString() + "\n    nanoClock=" + ((object)_nanoClock)?.ToString() + "\n    idleStrategy=" + ((object)_idleStrategy)?.ToString() + "\n    awaitingIdleStrategy=" + ((object)_awaitingIdleStrategy)?.ToString() + "\n    toClientBuffer=" + ((object)_toClientBuffer)?.ToString() + "\n    toDriverBuffer=" + ((object)_toDriverBuffer)?.ToString() + "\n    driverProxy=" + _driverProxy?.ToString() + "\n    cncByteBuffer=" + ((object)_cncByteBuffer)?.ToString() + "\n    cncMetaDataBuffer=" + ((object)_cncMetaDataBuffer)?.ToString() + "\n    logBuffersFactory=" + _logBuffersFactory?.ToString() + "\n    errorHandler=" + ((object)_errorHandler)?.ToString() + "\n    subscriberErrorHandler=" + ((object)_subscriberErrorHandler)?.ToString() + "\n    availableImageHandler=" + _availableImageHandler?.ToString() + "\n    unavailableImageHandler=" + _unavailableImageHandler?.ToString() + "\n    availableCounterHandler=" + _availableCounterHandler?.ToString() + "\n    unavailableCounterHandler=" + _unavailableCounterHandler?.ToString() + "\n    closeHandler=" + _closeHandler?.ToString() + "\n    keepAliveIntervalNs=" + _keepAliveIntervalNs + "\n    interServiceTimeoutNs=" + _interServiceTimeoutNs + "\n    resourceLingerDurationNs=" + _resourceLingerDurationNs + "\n    closeLingerDurationNs=" + _closeLingerDurationNs + "\n    threadFactory=" + ((object)_threadFactory)?.ToString() + "\n}";
			}

			private void ConnectToDriver()
			{
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0121: Expected O, but got Unknown
				IEpochClock epochClock = _epochClock;
				long num = epochClock.Time() + DriverTimeoutMs();
				FileInfo fileInfo = CncFile();
				while (_toDriverBuffer == null)
				{
					fileInfo.Refresh();
					_cncByteBuffer = WaitForFileMapping(fileInfo, epochClock, num);
					_cncMetaDataBuffer = CncFileDescriptor.CreateMetaDataBuffer(_cncByteBuffer);
					int intVolatile;
					while ((intVolatile = _cncMetaDataBuffer.GetIntVolatile(CncFileDescriptor.CncVersionOffset(0))) == 0)
					{
						if (epochClock.Time() > num)
						{
							throw new DriverTimeoutException("CnC file is created but not initialised: " + fileInfo.FullName);
						}
						Sleep(Configuration.AWAITING_IDLE_SLEEP_MS);
					}
					CncFileDescriptor.CheckVersion(intVolatile);
					if (SemanticVersion.Minor(intVolatile) < SemanticVersion.Minor(CncFileDescriptor.CNC_VERSION))
					{
						throw new AeronException("driverVersion=" + SemanticVersion.ToString(intVolatile) + " insufficient for clientVersion=" + SemanticVersion.ToString(CncFileDescriptor.CNC_VERSION));
					}
					if (!CncFileDescriptor.IsCncFileLengthSufficient((IDirectBuffer)(object)_cncMetaDataBuffer, _cncByteBuffer.Capacity))
					{
						MappedByteBuffer cncByteBuffer = _cncByteBuffer;
						if (cncByteBuffer != null)
						{
							cncByteBuffer.Dispose();
						}
						_cncByteBuffer = null;
						_cncMetaDataBuffer = null;
						Sleep(Configuration.AWAITING_IDLE_SLEEP_MS);
						continue;
					}
					ManyToOneRingBuffer val = new ManyToOneRingBuffer((IAtomicBuffer)(object)CncFileDescriptor.CreateToDriverBuffer(_cncByteBuffer, (IDirectBuffer)(object)_cncMetaDataBuffer));
					while (val.ConsumerHeartbeatTime() == 0L)
					{
						if (epochClock.Time() > num)
						{
							throw new DriverTimeoutException("no driver heartbeat detected.");
						}
						Sleep(Configuration.AWAITING_IDLE_SLEEP_MS);
					}
					long num2 = epochClock.Time();
					if (val.ConsumerHeartbeatTime() < num2 - DriverTimeoutMs())
					{
						if (num2 > num)
						{
							throw new DriverTimeoutException("no driver heartbeat detected.");
						}
						IoUtil.Unmap(_cncByteBuffer);
						_cncByteBuffer = null;
						_cncMetaDataBuffer = null;
						Sleep(100);
					}
					else
					{
						_toDriverBuffer = (IRingBuffer)(object)val;
					}
				}
			}

			private static MappedByteBuffer WaitForFileMapping(FileInfo cncFile, IEpochClock clock, long deadLineMs)
			{
				while (true)
				{
					if (!cncFile.Exists || cncFile.Length < CncFileDescriptor.META_DATA_LENGTH)
					{
						if (clock.Time() > deadLineMs)
						{
							break;
						}
						Sleep(Configuration.IDLE_SLEEP_DEFAULT_MS);
						cncFile.Refresh();
						continue;
					}
					try
					{
						FileAccess access = FileAccess.ReadWrite;
						FileShare share = FileShare.ReadWrite | FileShare.Delete;
						FileStream fileStream = cncFile.Open(FileMode.Open, access, share);
						if (fileStream.Length < CncFileDescriptor.META_DATA_LENGTH)
						{
							if (clock.Time() > deadLineMs)
							{
								throw new DriverTimeoutException("CnC file is created but not populated: " + cncFile.FullName);
							}
							fileStream.Dispose();
							Sleep(Configuration.IDLE_SLEEP_DEFAULT_MS);
							continue;
						}
						return IoUtil.MapExistingFile(fileStream);
					}
					catch (FileNotFoundException)
					{
					}
					catch (IOException)
					{
					}
					catch (Exception innerException)
					{
						throw new AeronException("cannot open CnC file", innerException);
					}
				}
				throw new DriverTimeoutException("CnC file not created: " + cncFile.FullName);
			}

			public void DeleteAeronDirectory()
			{
				IoUtil.Delete(_aeronDirectory, false);
			}

			public MappedByteBuffer MapExistingCncFile(Action<string> logProgress)
			{
				FileInfo fileInfo = new FileInfo(Path.Combine(_aeronDirectory.FullName, "cnc.dat"));
				if (fileInfo.Exists && fileInfo.Length > CncFileDescriptor.META_DATA_LENGTH)
				{
					logProgress?.Invoke("INFO: Aeron CnC file " + fileInfo?.ToString() + "exists");
					return IoUtil.MapExistingFile(fileInfo, "cnc.dat");
				}
				return null;
			}

			public static bool IsDriverActive(DirectoryInfo directory, long driverTimeoutMs, Action<string> logger)
			{
				FileInfo fileInfo = new FileInfo(Path.Combine(directory.FullName, "cnc.dat"));
				if (fileInfo.Exists && fileInfo.Length > CncFileDescriptor.META_DATA_LENGTH)
				{
					logger("INFO: Aeron CnC file " + fileInfo?.ToString() + " exists");
					MappedByteBuffer val = IoUtil.MapExistingFile(fileInfo, "CnC file");
					try
					{
						return IsDriverActive(driverTimeoutMs, logger, val);
					}
					finally
					{
						if (val != null)
						{
							val.Dispose();
						}
					}
				}
				return false;
			}

			public bool IsDriverActive(long driverTimeoutMs, Action<string> logger)
			{
				MappedByteBuffer val = MapExistingCncFile(logger);
				try
				{
					return IsDriverActive(driverTimeoutMs, logger, val);
				}
				finally
				{
					if (val != null)
					{
						val.Dispose();
					}
				}
			}

			public static bool IsDriverActive(long driverTimeoutMs, Action<string> logger, MappedByteBuffer cncByteBuffer)
			{
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				if (cncByteBuffer == null)
				{
					return false;
				}
				UnsafeBuffer val = CncFileDescriptor.CreateMetaDataBuffer(cncByteBuffer);
				long num = UnixTimeConverter.CurrentUnixTimeMillis();
				int intVolatile;
				while ((intVolatile = val.GetIntVolatile(CncFileDescriptor.CncVersionOffset(0))) == 0)
				{
					if (UnixTimeConverter.CurrentUnixTimeMillis() > num + driverTimeoutMs)
					{
						throw new DriverTimeoutException("CnC file is created but not initialised.");
					}
					Sleep(1);
				}
				CncFileDescriptor.CheckVersion(intVolatile);
				long num2 = new ManyToOneRingBuffer((IAtomicBuffer)(object)CncFileDescriptor.CreateToDriverBuffer(cncByteBuffer, (IDirectBuffer)(object)val)).ConsumerHeartbeatTime();
				long num3 = DateTime.Now.ToFileTimeUtc() - num2;
				logger("INFO: Aeron toDriver consumer heartbeat age is (ms):" + num3);
				return num3 <= driverTimeoutMs;
			}

			public static bool RequestDriverTermination(DirectoryInfo directory, IDirectBuffer tokenBuffer, int tokenOffset, int tokenLength)
			{
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Expected O, but got Unknown
				FileInfo fileInfo = new FileInfo(Path.Combine(directory.FullName, "cnc.dat"));
				if (fileInfo.Exists && fileInfo.Length > CncFileDescriptor.META_DATA_LENGTH)
				{
					MappedByteBuffer val = IoUtil.MapExistingFile(fileInfo, "CnC file");
					try
					{
						UnsafeBuffer val2 = CncFileDescriptor.CreateMetaDataBuffer(val);
						int intVolatile = val2.GetIntVolatile(CncFileDescriptor.CncVersionOffset(0));
						if (intVolatile > 0)
						{
							CncFileDescriptor.CheckVersion(intVolatile);
							ManyToOneRingBuffer val3 = new ManyToOneRingBuffer((IAtomicBuffer)(object)CncFileDescriptor.CreateToDriverBuffer(val, (IDirectBuffer)(object)val2));
							long clientId = val3.NextCorrelationId();
							return new DriverProxy((IRingBuffer)val3, clientId).TerminateDriver(tokenBuffer, tokenOffset, tokenLength);
						}
					}
					finally
					{
						if (val != null)
						{
							val.Dispose();
						}
					}
				}
				return false;
			}

			public int SaveErrorLog(StreamWriter writer)
			{
				MappedByteBuffer val = MapExistingCncFile(null);
				try
				{
					return SaveErrorLog(writer, val);
				}
				finally
				{
					if (val != null)
					{
						val.Dispose();
					}
				}
			}

			public int SaveErrorLog(StreamWriter writer, MappedByteBuffer cncByteBuffer)
			{
				if (cncByteBuffer == null)
				{
					return 0;
				}
				return PrintErrorLog(ErrorLogBuffer(cncByteBuffer), writer);
			}

			public static int PrintErrorLog(IAtomicBuffer errorBuffer, TextWriter @out)
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Expected O, but got Unknown
				int num = 0;
				if (ErrorLogReader.HasErrors(errorBuffer))
				{
					num = ErrorLogReader.Read(errorBuffer, new ErrorConsumer(ErrorConsumer));
					@out.WriteLine();
					@out.WriteLine("{0} distinct errors observed.", num);
				}
				else
				{
					@out.WriteLine();
					@out.WriteLine("0 distinct errors observed");
				}
				return num;
				void ErrorConsumer(int count, long firstTimestamp, long lastTimestamp, string encodedException)
				{
					DateTime dateTime = new DateTime(firstTimestamp);
					DateTime dateTime2 = new DateTime(lastTimestamp);
					@out.WriteLine();
					@out.WriteLine($"{count} observations from {dateTime} to {dateTime2} for:");
					@out.WriteLine(encodedException);
				}
			}

			private static IAtomicBuffer ErrorLogBuffer(MappedByteBuffer cncByteBuffer)
			{
				UnsafeBuffer val = CncFileDescriptor.CreateMetaDataBuffer(cncByteBuffer);
				CncFileDescriptor.CheckVersion(val.GetInt(CncFileDescriptor.CncVersionOffset(0)));
				return (IAtomicBuffer)(object)CncFileDescriptor.CreateErrorLogBuffer(cncByteBuffer, (IDirectBuffer)(object)val);
			}

			public static IErrorHandler SetupErrorHandler(IErrorHandler userErrorHandler, DistinctErrorLog errorLog)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Expected O, but got Unknown
				LoggingErrorHandler val = new LoggingErrorHandler(errorLog);
				if (userErrorHandler == null)
				{
					return (IErrorHandler)(object)val;
				}
				return (IErrorHandler)(object)new ErrorHandlerWrapper(val, userErrorHandler);
			}

			public static int DriverFilePageSize(DirectoryInfo aeronDirectory, IEpochClock clock, long timeoutMs)
			{
				MappedByteBuffer val = null;
				UnsafeBuffer val2 = null;
				try
				{
					val = WaitForFileMapping(new FileInfo(Path.Combine(aeronDirectory.FullName, "cnc.dat")), clock, timeoutMs);
					val2 = CncFileDescriptor.CreateMetaDataBuffer(val);
					return DriverFilePageSize((IDirectBuffer)(object)val2);
				}
				finally
				{
					if (val2 != null)
					{
						val2.Dispose();
					}
					if (val != null)
					{
						val.Dispose();
					}
				}
			}

			internal static int DriverFilePageSize(IDirectBuffer metadata)
			{
				int num = CncFileDescriptor.FilePageSize(metadata);
				if (num == 0)
				{
					return 4096;
				}
				return num;
			}

			private static void Sleep(int durationMs)
			{
				try
				{
					Thread.Sleep(durationMs);
				}
				catch (ThreadInterruptedException innerException)
				{
					Thread.CurrentThread.Interrupt();
					throw new AeronException("unexpected interrupt", innerException);
				}
			}
		}

		public const int NULL_VALUE = -1;

		private readonly AtomicBoolean _isClosed = new AtomicBoolean(false);

		private readonly long _clientId;

		private readonly ClientConductor _conductor;

		private readonly IRingBuffer _commandBuffer;

		private readonly AgentInvoker _conductorInvoker;

		private readonly AgentRunner _conductorRunner;

		private readonly Context _ctx;

		public bool IsClosed => _isClosed.Get();

		public Context Ctx => _ctx;

		public long ClientId => _clientId;

		public AgentInvoker ConductorAgentInvoker => _conductorInvoker;

		public CountersReader CountersReader
		{
			get
			{
				if (_isClosed.Get())
				{
					throw new AeronException("client is closed");
				}
				return _conductor.CountersReader();
			}
		}

		internal Aeron()
		{
		}//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown


		internal Aeron(Context ctx)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			try
			{
				ctx.Conclude();
				_ctx = ctx;
				_clientId = ctx.ClientId();
				_commandBuffer = ctx.ToDriverBuffer();
				_conductor = new ClientConductor(ctx, this);
				if (ctx.UseConductorAgentInvoker())
				{
					_conductorInvoker = new AgentInvoker(ctx.ErrorHandler(), (AtomicCounter)null, (IAgent)(object)_conductor);
					_conductorRunner = null;
				}
				else
				{
					_conductorInvoker = null;
					_conductorRunner = new AgentRunner(ctx.IdleStrategy(), ctx.ErrorHandler(), (AtomicCounter)null, (IAgent)(object)_conductor);
				}
			}
			catch (ConcurrentConcludeException)
			{
				throw;
			}
			catch (Exception)
			{
				CloseHelper.QuietDispose((IDisposable)ctx);
				throw;
			}
		}

		public static Aeron Connect()
		{
			return Connect(new Context());
		}

		public static Aeron Connect(Context ctx)
		{
			try
			{
				Aeron aeron = new Aeron(ctx);
				if (ctx.UseConductorAgentInvoker())
				{
					aeron.ConductorAgentInvoker.Start();
				}
				else
				{
					AgentRunner.StartOnThread(aeron._conductorRunner, ctx.ThreadFactory());
				}
				return aeron;
			}
			catch (ConcurrentConcludeException)
			{
				throw;
			}
			catch (Exception)
			{
				ctx.Dispose();
				throw;
			}
		}

		public void PrintCounters(StreamWriter @out)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			CountersReader.ForEach((CounterConsumer)delegate(long value, int id, string label)
			{
				@out.WriteLine("{0,3}: {1:} - {2}", id, value, label);
			});
		}

		public bool IsCommandActive(long correlationId)
		{
			return _conductor.IsCommandActive(correlationId);
		}

		public bool HasActiveCommands()
		{
			return _conductor.HasActiveCommands();
		}

		public void Dispose()
		{
			if (_isClosed.CompareAndSet(false, true))
			{
				IErrorHandler val = _ctx.ErrorHandler();
				if (_conductorRunner != null)
				{
					CloseHelper.Dispose(val, (IDisposable)_conductorRunner);
				}
				else
				{
					CloseHelper.Dispose(val, (IDisposable)_conductorInvoker);
				}
			}
		}

		public Publication AddPublication(string channel, int streamId)
		{
			return _conductor.AddPublication(channel, streamId);
		}

		public ExclusivePublication AddExclusivePublication(string channel, int streamId)
		{
			return _conductor.AddExclusivePublication(channel, streamId);
		}

		public long AsyncAddPublication(string channel, int streamId)
		{
			return _conductor.AsyncAddPublication(channel, streamId);
		}

		public void AsyncRemovePublication(long registrationId)
		{
			_conductor.RemovePublication(registrationId);
		}

		public long AsyncAddExclusivePublication(string channel, int streamId)
		{
			return _conductor.AsyncAddExclusivePublication(channel, streamId);
		}

		public ConcurrentPublication GetPublication(long registrationId)
		{
			return _conductor.GetPublication(registrationId);
		}

		public ExclusivePublication GetExclusivePublication(long registrationId)
		{
			return _conductor.GetExclusivePublication(registrationId);
		}

		public Subscription AddSubscription(string channel, int streamId)
		{
			return _conductor.AddSubscription(channel, streamId);
		}

		public Subscription AddSubscription(string channel, int streamId, AvailableImageHandler availableImageHandler, UnavailableImageHandler unavailableImageHandler)
		{
			return _conductor.AddSubscription(channel, streamId, availableImageHandler, unavailableImageHandler);
		}

		public long AsyncAddSubscription(string channel, int streamId, AvailableImageHandler availableImageHandler, UnavailableImageHandler unavailableImageHandler)
		{
			return _conductor.AsyncAddSubscription(channel, streamId, availableImageHandler, unavailableImageHandler);
		}

		public long AsyncAddSubscription(string channel, int streamId)
		{
			return _conductor.AsyncAddSubscription(channel, streamId);
		}

		public void AsyncRemoveSubscription(long registrationId)
		{
			_conductor.RemoveSubscription(registrationId);
		}

		public Subscription GetSubscription(long registrationId)
		{
			return _conductor.GetSubscription(registrationId);
		}

		public long NextCorrelationId()
		{
			if (_isClosed.Get())
			{
				throw new AeronException("client is closed");
			}
			return _commandBuffer.NextCorrelationId();
		}

		public int NextSessionId(int streamId)
		{
			if (_isClosed.Get())
			{
				throw new AeronException("client is closed");
			}
			return _conductor.NextSessionId(streamId);
		}

		public Counter AddCounter(int typeId, IDirectBuffer keyBuffer, int keyOffset, int keyLength, IDirectBuffer labelBuffer, int labelOffset, int labelLength)
		{
			return _conductor.AddCounter(typeId, keyBuffer, keyOffset, keyLength, labelBuffer, labelOffset, labelLength);
		}

		public Counter AddCounter(int typeId, string label)
		{
			return _conductor.AddCounter(typeId, label);
		}

		public Counter AddStaticCounter(int typeId, IDirectBuffer keyBuffer, int keyOffset, int keyLength, IDirectBuffer labelBuffer, int labelOffset, int labelLength, long registrationId)
		{
			return _conductor.AddStaticCounter(typeId, keyBuffer, keyOffset, keyLength, labelBuffer, labelOffset, labelLength, registrationId);
		}

		public Counter AddStaticCounter(int typeId, string label, long registrationId)
		{
			return _conductor.AddStaticCounter(typeId, label, registrationId);
		}

		public long AsyncAddCounter(int typeId, string label)
		{
			return _conductor.AsyncAddCounter(typeId, label);
		}

		public long AsyncAddCounter(int typeId, IDirectBuffer keyBuffer, int keyOffset, int keyLength, IDirectBuffer labelBuffer, int labelOffset, int labelLength)
		{
			return _conductor.AsyncAddCounter(typeId, keyBuffer, keyOffset, keyLength, labelBuffer, labelOffset, labelLength);
		}

		public long AsyncAddStaticCounter(int typeId, string label, long registrationId)
		{
			return _conductor.AsyncAddStaticCounter(typeId, label, registrationId);
		}

		public long AsyncAddStaticCounter(int typeId, IDirectBuffer keyBuffer, int keyOffset, int keyLength, IDirectBuffer labelBuffer, int labelOffset, int labelLength, long registrationId)
		{
			return _conductor.AsyncAddStaticCounter(typeId, keyBuffer, keyOffset, keyLength, labelBuffer, labelOffset, labelLength, registrationId);
		}

		public Counter GetCounter(long correlationId)
		{
			return _conductor.GetCounter(correlationId);
		}

		public void AsyncRemoveCounter(long registrationId)
		{
			_conductor.AsyncRemoveCounter(registrationId);
		}

		public long AddAvailableCounterHandler(AvailableCounterHandler handler)
		{
			return _conductor.AddAvailableCounterHandler(handler);
		}

		public bool RemoveAvailableCounterHandler(long registrationId)
		{
			return _conductor.RemoveAvailableCounterHandler(registrationId);
		}

		[Obsolete]
		public bool RemoveAvailableCounterHandler(AvailableCounterHandler handler)
		{
			return _conductor.RemoveAvailableCounterHandler(handler);
		}

		public long AddUnavailableCounterHandler(UnavailableCounterHandler handler)
		{
			return _conductor.AddUnavailableCounterHandler(handler);
		}

		public bool RemoveUnavailableCounterHandler(long registrationId)
		{
			return _conductor.RemoveUnavailableCounterHandler(registrationId);
		}

		[Obsolete]
		public bool RemoveUnavailableCounterHandler(UnavailableCounterHandler handler)
		{
			return _conductor.RemoveUnavailableCounterHandler(handler);
		}

		public long AddCloseHandler(Action handler)
		{
			return _conductor.AddCloseHandler(handler);
		}

		[Obsolete]
		public bool RemoveCloseHandler(Action handler)
		{
			return _conductor.RemoveCloseHandler(handler);
		}

		public bool RemoveCloseHandler(long registrationId)
		{
			return _conductor.RemoveCloseHandler(registrationId);
		}

		public override string ToString()
		{
			string[] obj = new string[5]
			{
				"Aeron{isClosed=",
				_isClosed.Get().ToString(),
				", clientId=",
				null,
				null
			};
			long clientId = _clientId;
			obj[3] = clientId.ToString();
			obj[4] = "}";
			return string.Concat(obj);
		}

		internal void InternalClose()
		{
			_isClosed.Set(true);
		}
	}
	public static class AeronCounters
	{
		public const int SYSTEM_COUNTER_ID_BYTES_SENT = 0;

		public const int SYSTEM_COUNTER_ID_BYTES_RECEIVED = 1;

		public const int SYSTEM_COUNTER_ID_RECEIVER_PROXY_FAILS = 2;

		public const int SYSTEM_COUNTER_ID_SENDER_PROXY_FAILS = 3;

		public const int SYSTEM_COUNTER_ID_CONDUCTOR_PROXY_FAILS = 4;

		public const int SYSTEM_COUNTER_ID_NAK_MESSAGES_SENT = 5;

		public const int SYSTEM_COUNTER_ID_NAK_MESSAGES_RECEIVED = 6;

		public const int SYSTEM_COUNTER_ID_STATUS_MESSAGES_SENT = 7;

		public const int SYSTEM_COUNTER_ID_STATUS_MESSAGES_RECEIVED = 8;

		public const int SYSTEM_COUNTER_ID_HEARTBEATS_SENT = 9;

		public const int SYSTEM_COUNTER_ID_HEARTBEATS_RECEIVED = 10;

		public const int SYSTEM_COUNTER_ID_RETRANSMITS_SENT = 11;

		public const int SYSTEM_COUNTER_ID_FLOW_CONTROL_UNDER_RUNS = 12;

		public const int SYSTEM_COUNTER_ID_FLOW_CONTROL_OVER_RUNS = 13;

		public const int SYSTEM_COUNTER_ID_INVALID_PACKETS = 14;

		public const int SYSTEM_COUNTER_ID_ERRORS = 15;

		public const int SYSTEM_COUNTER_ID_SHORT_SENDS = 16;

		public const int SYSTEM_COUNTER_ID_FREE_FAILS = 17;

		public const int SYSTEM_COUNTER_ID_SENDER_FLOW_CONTROL_LIMITS = 18;

		public const int SYSTEM_COUNTER_ID_UNBLOCKED_PUBLICATIONS = 19;

		public const int SYSTEM_COUNTER_ID_UNBLOCKED_COMMANDS = 20;

		public const int SYSTEM_COUNTER_ID_POSSIBLE_TTL_ASYMMETRY = 21;

		public const int SYSTEM_COUNTER_ID_CONTROLLABLE_IDLE_STRATEGY = 22;

		public const int SYSTEM_COUNTER_ID_LOSS_GAP_FILLS = 23;

		public const int SYSTEM_COUNTER_ID_CLIENT_TIMEOUTS = 24;

		public const int SYSTEM_COUNTER_ID_RESOLUTION_CHANGES = 25;

		public const int SYSTEM_COUNTER_ID_CONDUCTOR_MAX_CYCLE_TIME = 26;

		public const int SYSTEM_COUNTER_ID_CONDUCTOR_CYCLE_TIME_THRESHOLD_EXCEEDED = 27;

		public const int SYSTEM_COUNTER_ID_SENDER_MAX_CYCLE_TIME = 28;

		public const int SYSTEM_COUNTER_ID_SENDER_CYCLE_TIME_THRESHOLD_EXCEEDED = 29;

		public const int SYSTEM_COUNTER_ID_RECEIVER_MAX_CYCLE_TIME = 30;

		public const int SYSTEM_COUNTER_ID_RECEIVER_CYCLE_TIME_THRESHOLD_EXCEEDED = 31;

		public const int SYSTEM_COUNTER_ID_NAME_RESOLVER_MAX_TIME = 32;

		public const int SYSTEM_COUNTER_ID_NAME_RESOLVER_TIME_THRESHOLD_EXCEEDED = 33;

		public const int SYSTEM_COUNTER_ID_AERON_VERSION = 34;

		public const int SYSTEM_COUNTER_ID_BYTES_CURRENTLY_MAPPED = 35;

		public const int SYSTEM_COUNTER_ID_RETRANSMITTED_BYTES = 36;

		public const int SYSTEM_COUNTER_ID_RETRANSMIT_OVERFLOW = 37;

		public const int SYSTEM_COUNTER_ID_ERROR_FRAMES_RECEIVED = 38;

		public const int SYSTEM_COUNTER_ID_ERROR_FRAMES_SENT = 39;

		public const int SYSTEM_COUNTER_ID_PUBLICATIONS_REVOKED = 40;

		public const int SYSTEM_COUNTER_ID_PUBLICATION_IMAGES_REVOKED = 41;

		public const int SYSTEM_COUNTER_ID_IMAGES_REJECTED = 42;

		public const int SYSTEM_COUNTER_ID_CONTROL_PROTOCOL_VERSION = 43;

		public const int DRIVER_SYSTEM_COUNTER_TYPE_ID = 0;

		public const int DRIVER_PUBLISHER_LIMIT_TYPE_ID = 1;

		public const int DRIVER_SENDER_POSITION_TYPE_ID = 2;

		public const int DRIVER_RECEIVER_HWM_TYPE_ID = 3;

		public const int DRIVER_SUBSCRIBER_POSITION_TYPE_ID = 4;

		public const int DRIVER_RECEIVER_POS_TYPE_ID = 5;

		public const int DRIVER_SEND_CHANNEL_STATUS_TYPE_ID = 6;

		public const int DRIVER_RECEIVE_CHANNEL_STATUS_TYPE_ID = 7;

		public const int DRIVER_SENDER_LIMIT_TYPE_ID = 9;

		public const int DRIVER_PER_IMAGE_TYPE_ID = 10;

		public const int DRIVER_HEARTBEAT_TYPE_ID = 11;

		public const int DRIVER_PUBLISHER_POS_TYPE_ID = 12;

		public const int DRIVER_SENDER_BPE_TYPE_ID = 13;

		public const int NAME_RESOLVER_NEIGHBORS_COUNTER_TYPE_ID = 15;

		public const int NAME_RESOLVER_CACHE_ENTRIES_COUNTER_TYPE_ID = 16;

		public const int DRIVER_LOCAL_SOCKET_ADDRESS_STATUS_TYPE_ID = 14;

		public const int FLOW_CONTROL_RECEIVERS_COUNTER_TYPE_ID = 17;

		public const int MDC_DESTINATIONS_COUNTER_TYPE_ID = 18;

		public const int DRIVER_SENDER_NAKS_RECEIVED_TYPE_ID = 19;

		public const int DRIVER_RECEIVER_NAKS_SENT_TYPE_ID = 20;

		public const int ARCHIVE_RECORDING_POSITION_TYPE_ID = 100;

		public const int ARCHIVE_ERROR_COUNT_TYPE_ID = 101;

		public const int ARCHIVE_CONTROL_SESSIONS_TYPE_ID = 102;

		public const int ARCHIVE_MAX_CYCLE_TIME_TYPE_ID = 103;

		public const int ARCHIVE_CYCLE_TIME_THRESHOLD_EXCEEDED_TYPE_ID = 104;

		public const int ARCHIVE_RECORDER_MAX_WRITE_TIME_TYPE_ID = 105;

		public const int ARCHIVE_RECORDER_TOTAL_WRITE_BYTES_TYPE_ID = 106;

		public const int ARCHIVE_RECORDER_TOTAL_WRITE_TIME_TYPE_ID = 107;

		public const int ARCHIVE_REPLAYER_MAX_READ_TIME_TYPE_ID = 108;

		public const int ARCHIVE_REPLAYER_TOTAL_READ_BYTES_TYPE_ID = 109;

		public const int ARCHIVE_REPLAYER_TOTAL_READ_TIME_TYPE_ID = 110;

		public const int ARCHIVE_RECORDING_SESSION_COUNT_TYPE_ID = 111;

		public const int ARCHIVE_REPLAY_SESSION_COUNT_TYPE_ID = 112;

		public const int ARCHIVE_CONTROL_SESSION_TYPE_ID = 113;

		public const int CLUSTER_CONSENSUS_MODULE_STATE_TYPE_ID = 200;

		public const int CLUSTER_NODE_ROLE_TYPE_ID = 201;

		public const int CLUSTER_CONTROL_TOGGLE_TYPE_ID = 202;

		public const int CLUSTER_COMMIT_POSITION_TYPE_ID = 203;

		public const int CLUSTER_RECOVERY_STATE_TYPE_ID = 204;

		public const int CLUSTER_SNAPSHOT_COUNTER_TYPE_ID = 205;

		public const int CLUSTER_ELECTION_STATE_TYPE_ID = 207;

		public const int CLUSTER_BACKUP_STATE_TYPE_ID = 208;

		public const int CLUSTER_BACKUP_LIVE_LOG_POSITION_TYPE_ID = 209;

		public const int CLUSTER_BACKUP_QUERY_DEADLINE_TYPE_ID = 210;

		public const int CLUSTER_BACKUP_ERROR_COUNT_TYPE_ID = 211;

		public const int CLUSTER_CONSENSUS_MODULE_ERROR_COUNT_TYPE_ID = 212;

		public const int CLUSTER_CLIENT_TIMEOUT_COUNT_TYPE_ID = 213;

		public const int CLUSTER_INVALID_REQUEST_COUNT_TYPE_ID = 214;

		public const int CLUSTER_CLUSTERED_SERVICE_ERROR_COUNT_TYPE_ID = 215;

		public const int CLUSTER_MAX_CYCLE_TIME_TYPE_ID = 216;

		public const int CLUSTER_CYCLE_TIME_THRESHOLD_EXCEEDED_TYPE_ID = 217;

		public const int CLUSTER_CLUSTERED_SERVICE_MAX_CYCLE_TIME_TYPE_ID = 218;

		public const int CLUSTER_CLUSTERED_SERVICE_CYCLE_TIME_THRESHOLD_EXCEEDED_TYPE_ID = 219;

		public const int CLUSTER_STANDBY_STATE_TYPE_ID = 220;

		public const int CLUSTER_STANDBY_ERROR_COUNT_TYPE_ID = 221;

		public const int CLUSTER_STANDBY_HEARTBEAT_RESPONSE_COUNT_TYPE_ID = 222;

		public const int CLUSTER_STANDBY_CONTROL_TOGGLE_TYPE_ID = 223;

		public const int TRANSITION_MODULE_STATE_TYPE_ID = 224;

		public const int TRANSITION_MODULE_CONTROL_TOGGLE_TYPE_ID = 225;

		public const int TRANSITION_MODULE_ERROR_COUNT_TYPE_ID = 226;

		public const int CLUSTER_STANDBY_MAX_CYCLE_TIME_TYPE_ID = 227;

		public const int CLUSTER_STANDBY_CYCLE_TIME_THRESHOLD_EXCEEDED_TYPE_ID = 228;

		public const int TRANSITION_MODULE_MAX_CYCLE_TIME_TYPE_ID = 229;

		public const int TRANSITION_MODULE_CYCLE_TIME_THRESHOLD_EXCEEDED_TYPE_ID = 230;

		public const int CLUSTER_STANDBY_SOURCE_MEMBER_ID_TYPE_ID = 231;

		public const int CLUSTER_STANDBY_SNAPSHOT_COUNTER_TYPE_ID = 232;

		public const int NODE_CONTROL_TOGGLE_TYPE_ID = 233;

		public const int CLUSTER_TOTAL_MAX_SNAPSHOT_DURATION_TYPE_ID = 234;

		public const int CLUSTER_TOTAL_SNAPSHOT_DURATION_THRESHOLD_EXCEEDED_TYPE_ID = 235;

		public const int CLUSTERED_SERVICE_MAX_SNAPSHOT_DURATION_TYPE_ID = 236;

		public const int CLUSTERED_SERVICE_SNAPSHOT_DURATION_THRESHOLD_EXCEEDED_TYPE_ID = 237;

		public const int CLUSTER_ELECTION_COUNT_TYPE_ID = 238;

		public const int CLUSTER_LEADERSHIP_TERM_ID_TYPE_ID = 239;

		public const int CLUSTER_BACKUP_SNAPSHOT_RETRIEVE_COUNT_TYPE_ID = 240;

		public const int CLUSTER_SESSION_TYPE_ID = 241;

		public const int SEQUENCER_INDEX_COUNTER_TYPE_ID = 500;

		public const int SEQUENCER_GROUP_HWM_COUNTER_TYPE_ID = 501;

		public const int SEQUENCER_SESSION_GREATEST_MESSAGE_ID_COUNTER_TYPE_ID = 502;

		public const int SEQUENCER_SESSION_MESSAGES_COUNTER_TYPE_ID = 503;

		public const int SEQUENCER_SESSION_GREATEST_MESSAGE_TIMESTAMP_COUNTER_TYPE_ID = 504;

		public const int SEQUENCER_CLIENT_SNAPSHOT_ID_COUNTER_TYPE_ID = 505;

		public const int SEQUENCER_APPLICATION_SEQUENCE_INDEX_COUNTER_TYPE_ID = 507;

		public const int SEQUENCER_APPLICATION_STATE_COUNTER_TYPE_ID = 508;

		public const int SEQUENCER_APPLICATION_ERROR_COUNT_TYPE_ID = 509;

		public const int SEQUENCER_APPLICATION_MAX_SERVICE_TIME_TYPE_ID = 510;

		public const int SEQUENCER_APPLICATION_SERVICE_TIME_THRESHOLD_EXCEEDED_COUNT_TYPE_ID = 511;

		public const int SEQUENCER_APPLICATION_INTERVAL_SERVICE_TIME_TYPE_ID = 512;

		public const int SEQUENCER_APPLICATION_INTERVAL_MAX_SERVICE_TIME_TYPE_ID = 513;

		public const int SEQUENCER_APPLICATION_INTERVAL_TOTAL_INVOCATIONS_TYPE_ID = 514;

		public const int SEQUENCER_APPLICATION_SNAPSHOT_LOAD_TIME_TYPE_ID = 515;

		public const int SEQUENCER_APPLICATION_SNAPSHOT_STORE_TIME_TYPE_ID = 516;

		public const int SEQUENCER_APPLICATION_TAKE_SNAPSHOT_FAILURES_TYPE_ID = 517;

		public const int SEQUENCER_APPLICATION_TAKE_SNAPSHOT_COUNT_TYPE_ID = 518;

		public const int SEQUENCER_APPLICATION_SESSION_ID_TYPE_ID = 519;

		public const int SEQUENCER_REPLAY_INDEX_MIN_SEQUENCE_INDEX_COUNTER_TYPE_ID = 520;

		public const int SEQUENCER_REPLAY_INDEX_MIN_SEQUENCE_LOG_POSITION_COUNTER_TYPE_ID = 521;

		public const int SEQUENCER_REPLAY_INDEX_MAX_SEQUENCE_INDEX_COUNTER_TYPE_ID = 522;

		public const int SEQUENCER_REPLAY_INDEX_MAX_SEQUENCE_LOG_POSITION_COUNTER_TYPE_ID = 523;

		public const int SEQUENCER_REPLAY_INDEX_INITIAL_SEQUENCE_INDEX_COUNTER_TYPE_ID = 524;

		public const int SEQUENCER_REPLAY_INDEX_INITIAL_SEQUENCE_LOG_POSITION_COUNTER_TYPE_ID = 525;

		public static void ValidateCounterTypeId(CountersReader countersReader, int counterId, int expectedCounterTypeId)
		{
			int counterTypeId = countersReader.GetCounterTypeId(counterId);
			if (expectedCounterTypeId != counterTypeId)
			{
				throw new ConfigurationException("The type for counterId=" + counterId + ", typeId=" + counterTypeId + " does not match the expected=" + expectedCounterTypeId);
			}
		}

		public static void ValidateCounterTypeId(Aeron aeron, Counter counter, int expectedCounterTypeId)
		{
			ValidateCounterTypeId(aeron.CountersReader, ((AtomicCounter)counter).Id, expectedCounterTypeId);
		}

		public static int AppendVersionInfo(IMutableDirectBuffer tempBuffer, int offset, string fullVersion)
		{
			int num = tempBuffer.PutStringWithoutLengthAscii(offset, " ");
			return num + tempBuffer.PutStringWithoutLengthAscii(offset + num, FormatVersionInfo(fullVersion));
		}

		public static int AppendToLabel(IAtomicBuffer metaDataBuffer, int counterId, string value)
		{
			if (metaDataBuffer == null)
			{
				throw new ArgumentNullException("metaDataBuffer");
			}
			ValidateCounterId(metaDataBuffer, counterId);
			int num = CountersReader.MetaDataOffset(counterId);
			int intVolatile = metaDataBuffer.GetIntVolatile(num);
			if (1 != intVolatile)
			{
				throw new ArgumentException("counter id " + counterId + " is not allocated, state: " + intVolatile);
			}
			int @int = ((IDirectBuffer)metaDataBuffer).GetInt(num + CountersReader.LABEL_OFFSET);
			int num2 = CountersReader.MAX_LABEL_LENGTH - @int;
			int num3 = ((IMutableDirectBuffer)metaDataBuffer).PutStringWithoutLengthAscii(num + CountersReader.LABEL_OFFSET + 4 + @int, value, 0, num2);
			if (num3 > 0)
			{
				metaDataBuffer.PutIntRelease(num + CountersReader.LABEL_OFFSET, @int + num3);
			}
			return num3;
		}

		public static string FormatVersionInfo(string fullVersion)
		{
			return "version=" + fullVersion;
		}

		private static void ValidateCounterId(IAtomicBuffer metaDataBuffer, int counterId)
		{
			if (counterId < 0)
			{
				throw new ArgumentException("counter id " + counterId + " is negative");
			}
			int num = ((IDirectBuffer)metaDataBuffer).Capacity / CountersReader.METADATA_LENGTH - 1;
			if (counterId > num)
			{
				throw new ArgumentException("counter id " + counterId + " out of range: 0 - maxCounterId=" + num);
			}
		}
	}
	public class AeronThrowHelper
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public static void ThrowAeronException(string message)
		{
			throw GetAeronException(message);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static AeronException GetAeronException(string message)
		{
			return new AeronException(message);
		}
	}
	public class AeronVersion
	{
		public const string VERSION = "1.43.0";

		public const int MAJOR_VERSION = 1;

		public const int MINOR_VERSION = 43;

		public const int PATCH_VERSION = 0;
	}
	public delegate void AvailableCounterHandler(CountersReader countersReader, long registrationId, int counterId);
	public delegate void AvailableImageHandler(Image image);
	public sealed class BufferBuilder
	{
		internal const int MAX_CAPACITY = 2147483639;

		internal const int INIT_MIN_CAPACITY = 4096;

		private int _limit;

		private int _nextTermOffset = -1;

		private readonly UnsafeBuffer _buffer = new UnsafeBuffer();

		private readonly UnsafeBuffer headerBuffer = new UnsafeBuffer();

		private readonly Header completeHeader = new Header(0, 0);

		public BufferBuilder()
			: this(0)
		{
		}

		public BufferBuilder(int initialCapacity)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (initialCapacity < 0 || initialCapacity > 2147483639)
			{
				throw new ArgumentException("initialCapacity outside range 0 - " + 2147483639 + ": initialCapacity=" + initialCapacity);
			}
			if (initialCapacity > 0)
			{
				_buffer.Wrap(new byte[initialCapacity]);
			}
			headerBuffer.Wrap(new byte[32]);
		}

		public int Capacity()
		{
			return _buffer.Capacity;
		}

		public int Limit()
		{
			return _limit;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public void Limit(int limit)
		{
			if (limit < 0 || limit >= _buffer.Capacity)
			{
				ThrowHelper.ThrowArgumentException($"limit outside range: capacity={_buffer.Capacity:D} limit={limit:D}");
			}
			_limit = limit;
		}

		public int NextTermOffset()
		{
			return _nextTermOffset;
		}

		public void NextTermOffset(int offset)
		{
			_nextTermOffset = offset;
		}

		public IMutableDirectBuffer Buffer()
		{
			return (IMutableDirectBuffer)(object)_buffer;
		}

		public BufferBuilder Reset()
		{
			_limit = 0;
			_nextTermOffset = -1;
			completeHeader.Context = null;
			completeHeader.FragmentedFrameLength = -1;
			return this;
		}

		public BufferBuilder Compact()
		{
			int num = Math.Max(4096, _limit);
			if (num < _buffer.Capacity)
			{
				Resize(num);
			}
			return this;
		}

		public BufferBuilder Append(IDirectBuffer srcBuffer, int srcOffset, int length)
		{
			EnsureCapacity(length);
			srcBuffer.GetBytes(srcOffset, (IMutableDirectBuffer)(object)_buffer, _limit, length);
			_limit += length;
			return this;
		}

		public BufferBuilder CaptureHeader(Header header)
		{
			completeHeader.InitialTermId = header.InitialTermId;
			completeHeader.PositionBitsToShift = header.PositionBitsToShift;
			completeHeader.Offset = 0;
			completeHeader.Buffer = (IDirectBuffer)(object)headerBuffer;
			headerBuffer.PutBytes(0, header.Buffer, header.Offset, 32);
			return this;
		}

		public Header CompleteHeader(Header header)
		{
			int @int = headerBuffer.GetInt(0, (ByteOrder)1);
			int fragmentedFrameLength = LogBufferDescriptor.ComputeFragmentedFrameLength(_limit, @int - 32);
			completeHeader.Context = header.Context;
			completeHeader.FragmentedFrameLength = fragmentedFrameLength;
			headerBuffer.PutInt(0, 32 + _limit, (ByteOrder)1);
			headerBuffer.PutByte(5, (byte)(headerBuffer.GetByte(5) | header.Flags));
			return completeHeader;
		}

		private void EnsureCapacity(int additionalLength)
		{
			long num = (long)_limit + (long)additionalLength;
			int capacity = _buffer.Capacity;
			if (num > capacity)
			{
				if (num > 2147483639)
				{
					throw new InvalidOperationException("insufficient capacity: maxCapacity=" + 2147483639 + " limit=" + _limit + " additionalLength=" + additionalLength);
				}
				Resize(FindSuitableCapacity(capacity, num));
			}
		}

		private void Resize(int newCapacity)
		{
			_buffer.Wrap(CopyOf(_buffer.ByteArray, newCapacity));
		}

		private static T[] CopyOf<T>(T[] original, int newLength)
		{
			T[] array = new T[newLength];
			Array.Copy(original, 0, array, 0, Math.Min(original.Length, newLength));
			return array;
		}

		internal static int FindSuitableCapacity(int capacity, long requiredCapacity)
		{
			long num = Math.Max(capacity, 4096);
			while (num < requiredCapacity)
			{
				num += num >> 1;
				if (num > 2147483639)
				{
					num = 2147483639L;
					break;
				}
			}
			return (int)num;
		}
	}
	public sealed class ChannelUri
	{
		private enum State
		{
			MEDIA,
			PARAMS_KEY,
			PARAMS_VALUE
		}

		public const string AERON_SCHEME = "aeron";

		public const string SPY_QUALIFIER = "aeron-spy";

		public const long INVALID_TAG = -1L;

		public const int MAX_URI_LENGTH = 4095;

		private const int CHANNEL_TAG_INDEX = 0;

		private const int ENTITY_TAG_INDEX = 1;

		private static readonly string AERON_PREFIX = "aeron:";

		private string _prefix;

		private string _media;

		private readonly Map<string, string> _params;

		private readonly string[] _tags;

		public bool IsUdp => "udp".Equals(_media);

		public bool IsIpc => "ipc".Equals(_media);

		public ChannelUri(string prefix, string media, Map<string, string> @params)
		{
			_prefix = prefix;
			_media = media;
			_params = @params;
			_tags = SplitTags(_params.Get("tags"));
		}

		public string Prefix()
		{
			return _prefix;
		}

		public ChannelUri Prefix(string prefix)
		{
			_prefix = prefix;
			return this;
		}

		public string Media()
		{
			return _media;
		}

		public ChannelUri Media(string media)
		{
			ValidateMedia(media);
			_media = media;
			return this;
		}

		public string Scheme()
		{
			return "aeron";
		}

		public string Get(string key)
		{
			return _params.Get(key);
		}

		public string Get(string key, string defaultValue)
		{
			string text = _params.Get(key);
			if (text != null)
			{
				return text;
			}
			return defaultValue;
		}

		public string Put(string key, string value)
		{
			return _params.Put(key, value);
		}

		public string Remove(string key)
		{
			return _params.Remove(key);
		}

		public bool ContainsKey(string key)
		{
			return _params.ContainsKey(key);
		}

		public string ChannelTag()
		{
			if (_tags == null || _tags.Length == 0)
			{
				return null;
			}
			return _tags[0];
		}

		public string EntityTag()
		{
			if (_tags.Length <= 1)
			{
				return null;
			}
			return _tags[1];
		}

		private bool Equals(ChannelUri other)
		{
			if (_prefix == other._prefix && _media == other._media && object.Equals(_params, other._params))
			{
				return object.Equals(_tags, other._tags);
			}
			return false;
		}

		public override bool Equals(object obj)
		{
			if (this == obj)
			{
				return true;
			}
			if (!(obj is ChannelUri channelUri))
			{
				return false;
			}
			if (object.Equals(_prefix, channelUri._prefix) && object.Equals(_media, channelUri._media) && object.Equals(_params, channelUri._params))
			{
				return object.Equals(_tags, channelUri._tags);
			}
			return false;
		}

		public override int GetHashCode()
		{
			return (((((((_prefix != null) ? _prefix.GetHashCode() : 0) * 397) ^ ((_media != null) ? _media.GetHashCode() : 0)) * 397) ^ ((_params != null) ? ((object)_params).GetHashCode() : 0)) * 397) ^ ((_tags != null) ? _tags.GetHashCode() : 0);
		}

		public override string ToString()
		{
			StringBuilder stringBuilder;
			if (_prefix == null || string.IsNullOrEmpty(_prefix))
			{
				stringBuilder = new StringBuilder(_params.Count * 20 + 10);
			}
			else
			{
				stringBuilder = new StringBuilder(_params.Count * 20 + 20);
				stringBuilder.Append(_prefix);
				if (!_prefix.EndsWith(":"))
				{
					stringBuilder.Append(":");
				}
			}
			stringBuilder.Append(AERON_PREFIX).Append(_media);
			if (_params.Count > 0)
			{
				stringBuilder.Append('?');
				foreach (KeyValuePair<string, string> param in _params)
				{
					stringBuilder.Append(param.Key).Append('=').Append(param.Value)
						.Append('|');
				}
				stringBuilder.Length--;
			}
			return stringBuilder.ToString();
		}

		public void InitialPosition(long position, int initialTermId, int termLength)
		{
			if (position < 0 || (position & 0x1F) != 0L)
			{
				throw new ArgumentException("invalid position: " + position);
			}
			int positionBitsToShift = LogBufferDescriptor.PositionBitsToShift(termLength);
			int num = LogBufferDescriptor.ComputeTermIdFromPosition(position, positionBitsToShift, initialTermId);
			int num2 = (int)(position & (termLength - 1));
			Put("init-term-id", Convert.ToString(initialTermId));
			Put("term-id", Convert.ToString(num));
			Put("term-offset", Convert.ToString(num2));
			Put("term-length", Convert.ToString(termLength));
		}

		public static ChannelUri Parse(string uri)
		{
			int length = uri.Length;
			if (length > 4095)
			{
				throw new ArgumentException("URI length (" + length + ") exceeds max supported length (" + 4095 + "): " + uri.Substring(0, 4095));
			}
			int num = 0;
			string prefix;
			if (StartsWith(uri, 0, "aeron-spy:"))
			{
				prefix = "aeron-spy";
				num = "aeron-spy:".Length;
			}
			else
			{
				prefix = "";
			}
			if (!StartsWith(uri, num, AERON_PREFIX))
			{
				throw new ArgumentException("Aeron URIs must start with 'aeron:', found: " + uri);
			}
			num += AERON_PREFIX.Length;
			StringBuilder stringBuilder = new StringBuilder();
			Map<string, string> val = new Map<string, string>((string)null);
			string media = null;
			string text = null;
			State state = State.MEDIA;
			for (int i = num; i < length; i++)
			{
				char c = uri[i];
				switch (state)
				{
				case State.MEDIA:
					switch (c)
					{
					case '?':
						media = stringBuilder.ToString();
						stringBuilder.Length = 0;
						state = State.PARAMS_KEY;
						break;
					case ':':
					case '=':
					case '|':
						throw new ArgumentException("encountered '" + c + "' within media definition at index " + i + " in " + uri);
					default:
						stringBuilder.Append(c);
						break;
					}
					break;
				case State.PARAMS_KEY:
					switch (c)
					{
					case '=':
						if (stringBuilder.Length == 0)
						{
							throw new ArgumentException("empty key not allowed at index " + i + " in " + uri);
						}
						text = stringBuilder.ToString();
						stringBuilder.Length = 0;
						state = State.PARAMS_VALUE;
						break;
					case '|':
						throw new ArgumentException("invalid end of key at index " + i + " in " + uri);
					default:
						stringBuilder.Append(c);
						break;
					}
					break;
				case State.PARAMS_VALUE:
					if (c == '|')
					{
						val.Put(text, stringBuilder.ToString());
						stringBuilder.Length = 0;
						state = State.PARAMS_KEY;
					}
					else
					{
						stringBuilder.Append(c);
					}
					break;
				default:
					throw new ArgumentException("unexpected state=" + state.ToString() + " in " + uri);
				}
			}
			switch (state)
			{
			case State.MEDIA:
				media = stringBuilder.ToString();
				ValidateMedia(media);
				break;
			case State.PARAMS_VALUE:
				val.Put(text, stringBuilder.ToString());
				break;
			default:
				throw new ArgumentException("no more input found, state=" + state.ToString() + " in " + uri);
			}
			return new ChannelUri(prefix, media, val);
		}

		public static string AddSessionId(string channel, int sessionId)
		{
			ChannelUri channelUri = Parse(channel);
			channelUri.Put("session-id", Convert.ToString(sessionId));
			return channelUri.ToString();
		}

		public static string AddAliasIfAbsent(string uri, string alias)
		{
			if (!string.IsNullOrEmpty(alias))
			{
				ChannelUri channelUri = Parse(uri);
				if (!channelUri.ContainsKey("alias"))
				{
					channelUri.Put("alias", alias);
					return channelUri.ToString();
				}
			}
			return uri;
		}

		public static bool IsTagged(string paramValue)
		{
			return StartsWith(paramValue, 0, "tag:");
		}

		public static long GetTag(string paramValue)
		{
			if (!IsTagged(paramValue))
			{
				return -1L;
			}
			return long.Parse(paramValue.Substring(4, paramValue.Length - 4));
		}

		public static string CreateDestinationUri(string channel, string endpoint)
		{
			ChannelUri channelUri = Parse(channel);
			string text = AERON_PREFIX + channelUri.Media() + "?endpoint=" + endpoint;
			string text2 = channelUri.Get("interface");
			if (text2 != null)
			{
				return text + "|interface=" + text2;
			}
			return text;
		}

		public void ReplaceEndpointWildcardPort(string resolvedEndpoint)
		{
			if (resolvedEndpoint == null)
			{
				throw new ArgumentNullException("resolvedEndpoint", "resolvedEndpoint is null");
			}
			int num = resolvedEndpoint.LastIndexOf(':');
			if (-1 == num)
			{
				throw new ArgumentException("No port specified on resolvedEndpoint=" + resolvedEndpoint);
			}
			if (resolvedEndpoint.EndsWith(":0", StringComparison.Ordinal))
			{
				throw new ArgumentException("Wildcard port specified on resolvedEndpoint=" + resolvedEndpoint);
			}
			string text = Get("endpoint");
			if (text == null)
			{
				Put("endpoint", resolvedEndpoint);
			}
			else if (text.EndsWith(":0", StringComparison.Ordinal))
			{
				string value = text.Substring(0, text.Length - 2) + resolvedEndpoint.Substring(resolvedEndpoint.LastIndexOf(':'));
				Put("endpoint", value);
			}
		}

		public void ForEachParameter(Action<string, string> consumer)
		{
			_params.ForEach(consumer);
		}

		public bool HasControlModeResponse()
		{
			return "response".Equals(Get("control-mode"));
		}

		public static bool IsControlModeResponse(string channelUri)
		{
			return Parse(channelUri).HasControlModeResponse();
		}

		private static void ValidateMedia(string media)
		{
			if ("ipc".Equals(media) || "udp".Equals(media))
			{
				return;
			}
			throw new ArgumentException("unknown media: " + media);
		}

		private static bool StartsWith(string input, int position, string prefix)
		{
			if (input.Length - position < prefix.Length)
			{
				return false;
			}
			for (int i = 0; i < prefix.Length; i++)
			{
				if (input[position + i] != prefix[i])
				{
					return false;
				}
			}
			return true;
		}

		private static string[] SplitTags(string tagsValue)
		{
			string[] array = ArrayUtil.EMPTY_STRING_ARRAY;
			if (tagsValue != null)
			{
				int num = CountTags(tagsValue);
				if (num == 1)
				{
					array = new string[1] { tagsValue };
				}
				else
				{
					int num2 = 0;
					int num3 = 0;
					array = new string[num];
					int i = 0;
					for (int length = tagsValue.Length; i < length; i++)
					{
						if (tagsValue[i] == ',')
						{
							array[num3++] = tagsValue.Substring(num2, i - num2);
							num2 = i + 1;
							if (num3 >= num - 1)
							{
								array[num3] = tagsValue.Substring(num2, length - num2);
							}
						}
					}
				}
			}
			return array;
		}

		private static int CountTags(string tags)
		{
			int num = 1;
			int i = 0;
			for (int length = tags.Length; i < length; i++)
			{
				if (tags[i] == ',')
				{
					num++;
				}
			}
			return num;
		}
	}
	public sealed class ChannelUriStringBuilder
	{
		public const string TAG_PREFIX = "tag:";

		private readonly StringBuilder _sb = new StringBuilder(64);

		private string _prefix;

		private string _media;

		private string _endpoint;

		private string _networkInterface;

		private string _controlEndpoint;

		private string _controlMode;

		private string _tags;

		private string _alias;

		private string _cc;

		private string _fc;

		private string _mediaReceiveTimestampOffset;

		private string _channelReceiveTimestampOffset;

		private string _channelSendTimestampOffset;

		private string _responseCorrelationId;

		private string _responseEndpoint;

		private bool? _reliable;

		private bool? _sparse;

		private bool? _eos;

		private bool? _tether;

		private bool? _group;

		private bool? _rejoin;

		private bool? _ssc;

		private int? _ttl;

		private int? _mtu;

		private int? _termLength;

		private int? _initialTermId;

		private int? _termId;

		private int? _termOffset;

		private int? _socketSndbufLength;

		private int? _socketRcvbufLength;

		private int? _receiverWindowLength;

		private int? _maxResend;

		private int? _streamId;

		private int? _publicationWindowLength;

		private long? _sessionId;

		private long? _groupTag;

		private long? _linger;

		private long? nakDelay;

		private long? _untetheredWindowLimitTimeoutNs;

		private long? _untetheredLingerTimeoutNs;

		private long? untetheredRestingTimeoutNs;

		private bool _isSessionIdTagged;

		public ChannelUriStringBuilder()
		{
		}

		public ChannelUriStringBuilder(string initialUri)
			: this(ChannelUri.Parse(initialUri))
		{
		}

		public ChannelUriStringBuilder(ChannelUri channelUri)
		{
			_isSessionIdTagged = false;
			Prefix(channelUri);
			Media(channelUri);
			Endpoint(channelUri);
			NetworkInterface(channelUri);
			ControlEndpoint(channelUri);
			ControlMode(channelUri);
			Tags(channelUri);
			Alias(channelUri);
			CongestionControl(channelUri);
			FlowControl(channelUri);
			Reliable(channelUri);
			Ttl(channelUri);
			Mtu(channelUri);
			TermLength(channelUri);
			InitialTermId(channelUri);
			TermId(channelUri);
			TermOffset(channelUri);
			SessionId(channelUri);
			Group(channelUri);
			Linger(channelUri);
			Sparse(channelUri);
			Eos(channelUri);
			Tether(channelUri);
			GroupTag(channelUri);
			Rejoin(channelUri);
			SpiesSimulateConnection(channelUri);
			SocketRcvbufLength(channelUri);
			SocketSndbufLength(channelUri);
			ReceiverWindowLength(channelUri);
			MediaReceiveTimestampOffset(channelUri);
			ChannelReceiveTimestampOffset(channelUri);
			ChannelSendTimestampOffset(channelUri);
			ResponseEndpoint(channelUri);
			ResponseCorrelationId(channelUri);
			NakDelay(channelUri);
			UntetheredWindowLimitTimeout(channelUri);
			UntetheredLingerTimeout(channelUri);
			UntetheredRestingTimeout(channelUri);
			MaxResend(channelUri);
			StreamId(channelUri);
			PublicationWindowLength(channelUri);
		}

		public ChannelUriStringBuilder Clear()
		{
			_prefix = null;
			_media = null;
			_endpoint = null;
			_networkInterface = null;
			_controlEndpoint = null;
			_controlMode = null;
			_tags = null;
			_alias = null;
			_cc = null;
			_fc = null;
			_reliable = null;
			_ttl = null;
			_mtu = null;
			_termLength = null;
			_initialTermId = null;
			_termId = null;
			_termOffset = null;
			_sessionId = null;
			_groupTag = null;
			_linger = null;
			_sparse = null;
			_eos = null;
			_tether = null;
			_group = null;
			_rejoin = null;
			_isSessionIdTagged = false;
			_socketRcvbufLength = null;
			_socketSndbufLength = null;
			_receiverWindowLength = null;
			_mediaReceiveTimestampOffset = null;
			_channelReceiveTimestampOffset = null;
			_channelSendTimestampOffset = null;
			_responseEndpoint = null;
			_responseCorrelationId = null;
			_maxResend = null;
			_streamId = null;
			_publicationWindowLength = null;
			return this;
		}

		public ChannelUriStringBuilder Validate()
		{
			if (_media == null)
			{
				throw new ArgumentException("media type is mandatory");
			}
			if ("udp".Equals(_media) && _endpoint == null && _controlEndpoint == null)
			{
				throw new ArgumentException("either 'endpoint' or 'control' must be specified for UDP.");
			}
			bool num = _initialTermId.HasValue || _termId.HasValue || _termOffset.HasValue;
			bool flag = !_initialTermId.HasValue || !_termId.HasValue || !_termOffset.HasValue;
			if (num)
			{
				if (flag)
				{
					throw new ArgumentException("either all or none of the parameters ['initialTermId', 'termId', 'termOffset'] must be provided");
				}
				if (_termId - _initialTermId < 0)
				{
					int? termId = _termId;
					string? text = termId.ToString();
					termId = _initialTermId;
					throw new ArgumentException("difference greater than 2^31 - 1: termId=" + text + " - initialTermId=" + termId);
				}
				if (_termLength.HasValue && _termOffset > _termLength)
				{
					int? termOffset = _termOffset;
					string? text2 = termOffset.ToString();
					termOffset = _termLength;
					throw new ArgumentException("termOffset=" + text2 + " > termLength=" + termOffset);
				}
			}
			return this;
		}

		public ChannelUriStringBuilder Prefix(string prefix)
		{
			if (prefix != null && !string.IsNullOrEmpty(prefix) && !prefix.Equals("aeron-spy"))
			{
				throw new ArgumentException("invalid prefix: " + prefix);
			}
			_prefix = prefix;
			return this;
		}

		public ChannelUriStringBuilder Prefix(ChannelUri channelUri)
		{
			return Prefix(channelUri.Prefix());
		}

		public string Prefix()
		{
			return _prefix;
		}

		public ChannelUriStringBuilder Media(string media)
		{
			if (!(media == "udp") && !(media == "ipc"))
			{
				throw new ArgumentException("invalid media: " + media);
			}
			_media = media;
			return this;
		}

		public ChannelUriStringBuilder Media(ChannelUri channelUri)
		{
			return Media(channelUri.Media());
		}

		public string Media()
		{
			return _media;
		}

		public ChannelUriStringBuilder Endpoint(string endpoint)
		{
			_endpoint = endpoint;
			return this;
		}

		public ChannelUriStringBuilder Endpoint(ChannelUri channelUri)
		{
			return Endpoint(channelUri.Get("endpoint"));
		}

		public string Endpoint()
		{
			return _endpoint;
		}

		public ChannelUriStringBuilder NetworkInterface(string networkInterface)
		{
			_networkInterface = networkInterface;
			return this;
		}

		public ChannelUriStringBuilder NetworkInterface(ChannelUri channelUri)
		{
			return NetworkInterface(channelUri.Get("interface"));
		}

		public string NetworkInterface()
		{
			return _networkInterface;
		}

		public ChannelUriStringBuilder ControlEndpoint(string controlEndpoint)
		{
			_controlEndpoint = controlEndpoint;
			return this;
		}

		public ChannelUriStringBuilder ControlEndpoint(ChannelUri channelUri)
		{
			return ControlEndpoint(channelUri.Get("control"));
		}

		public string ControlEndpoint()
		{
			return _controlEndpoint;
		}

		public ChannelUriStringBuilder ControlMode(string controlMode)
		{
			if (controlMode != null && !controlMode.Equals("manual") && !controlMode.Equals("dynamic") && !controlMode.Equals("response"))
			{
				throw new ArgumentException("invalid control mode: " + controlMode);
			}
			_controlMode = controlMode;
			return this;
		}

		public ChannelUriStringBuilder ControlMode(ChannelUri channelUri)
		{
			return ControlMode(channelUri.Get("control-mode"));
		}

		public string ControlMode()
		{
			return _controlMode;
		}

		public ChannelUriStringBuilder Reliable(bool? isReliable)
		{
			_reliable = isReliable;
			return this;
		}

		public ChannelUriStringBuilder Reliable(ChannelUri channelUri)
		{
			string text = channelUri.Get("reliable");
			if (text == null)
			{
				_reliable = null;
				return this;
			}
			return Reliable(Convert.ToBoolean(text));
		}

		public bool? Reliable()
		{
			return _reliable;
		}

		public ChannelUriStringBuilder Ttl(int? ttl)
		{
			if (ttl.HasValue && (ttl < 0 || ttl > 255))
			{
				int? num = ttl;
				throw new ArgumentException("TTL not in range 0-255: " + num);
			}
			_ttl = ttl;
			return this;
		}

		public ChannelUriStringBuilder Ttl(ChannelUri channelUri)
		{
			string text = channelUri.Get("ttl");
			if (text == null)
			{
				_ttl = null;
				return this;
			}
			try
			{
				return Ttl(Convert.ToInt32(text));
			}
			catch (FormatException innerException)
			{
				throw new ArgumentException("'ttl' must be a value integer", innerException);
			}
		}

		public int? Ttl()
		{
			return _ttl;
		}

		public ChannelUriStringBuilder Mtu(int? mtu)
		{
			if (mtu.HasValue)
			{
				if (mtu < 32 || mtu > 65504)
				{
					int? num = mtu;
					throw new ArgumentException("MTU not in range 32-65504: " + num);
				}
				if ((mtu & 0x1F) != 0)
				{
					int? num = mtu;
					throw new ArgumentException("MTU not a multiple of FRAME_ALIGNMENT: mtu=" + num);
				}
			}
			_mtu = mtu;
			return this;
		}

		public ChannelUriStringBuilder Mtu(ChannelUri channelUri)
		{
			string text = channelUri.Get("mtu");
			if (text == null)
			{
				_mtu = null;
				return this;
			}
			long num = SystemUtil.ParseSize("mtu", text);
			if (num > int.MaxValue)
			{
				throw new InvalidOperationException("mtu " + num + " > " + int.MaxValue);
			}
			return Mtu((int)num);
		}

		public int? Mtu()
		{
			return _mtu;
		}

		public ChannelUriStringBuilder TermLength(int? termLength)
		{
			if (termLength.HasValue)
			{
				LogBufferDescriptor.CheckTermLength(termLength.Value);
			}
			_termLength = termLength;
			return this;
		}

		public ChannelUriStringBuilder TermLength(ChannelUri channelUri)
		{
			string text = channelUri.Get("term-length");
			if (text == null)
			{
				_termLength = null;
				return this;
			}
			long num = SystemUtil.ParseSize("term-length", text);
			if (num > int.MaxValue)
			{
				string text2 = 1073741824.ToString();
				int? termLength = _termLength;
				throw new ArgumentException("term length more than max length of " + text2 + ": length=" + termLength);
			}
			return TermLength((int)num);
		}

		public int? TermLength()
		{
			return _termLength;
		}

		public ChannelUriStringBuilder InitialTermId(int? initialTermId)
		{
			_initialTermId = initialTermId;
			return this;
		}

		public ChannelUriStringBuilder InitialTermId(ChannelUri channelUri)
		{
			string text = channelUri.Get("init-term-id");
			if (text == null)
			{
				_initialTermId = null;
				return this;
			}
			try
			{
				return InitialTermId(Convert.ToInt32(text));
			}
			catch (FormatException innerException)
			{
				throw new ArgumentException("'initial-term-id' must be a valid integer", innerException);
			}
		}

		public int? InitialTermId()
		{
			return _initialTermId;
		}

		public ChannelUriStringBuilder TermId(int? termId)
		{
			_termId = termId;
			return this;
		}

		public ChannelUriStringBuilder TermId(ChannelUri channelUri)
		{
			string text = channelUri.Get("term-id");
			if (text == null)
			{
				_termId = null;
				return this;
			}
			try
			{
				return TermId(Convert.ToInt32(text));
			}
			catch (FormatException innerException)
			{
				throw new ArgumentException("'term-id' must be a valid integer", innerException);
			}
		}

		public int? TermId()
		{
			return _termId;
		}

		public ChannelUriStringBuilder TermOffset(int? termOffset)
		{
			if (termOffset.HasValue)
			{
				if (termOffset < 0 || termOffset > 1073741824)
				{
					int? num = termOffset;
					throw new ArgumentException("term offset not in range 0-1g: " + num);
				}
				if (0 != (termOffset & 0x1F))
				{
					int? num = termOffset;
					throw new ArgumentException("term offset not multiple of FRAME_ALIGNMENT: " + num);
				}
			}
			_termOffset = termOffset;
			return this;
		}

		public ChannelUriStringBuilder TermOffset(ChannelUri channelUri)
		{
			string text = channelUri.Get("term-offset");
			if (text == null)
			{
				_termOffset = null;
				return this;
			}
			try
			{
				return TermOffset(Convert.ToInt32(text));
			}
			catch (FormatException innerException)
			{
				throw new ArgumentException("'term-offset' must be a valid integer", innerException);
			}
		}

		public int? TermOffset()
		{
			return _termOffset;
		}

		public ChannelUriStringBuilder SessionId(int? sessionId)
		{
			_sessionId = sessionId;
			return this;
		}

		public ChannelUriStringBuilder SessionId(string sessionIdStr)
		{
			if (sessionIdStr != null)
			{
				if (ChannelUri.IsTagged(sessionIdStr))
				{
					TaggedSessionId(ChannelUri.GetTag(sessionIdStr));
				}
				else
				{
					IsSessionIdTagged(isSessionIdTagged: false);
					try
					{
						SessionId(Convert.ToInt32(sessionIdStr));
					}
					catch (FormatException innerException)
					{
						throw new ArgumentException("'session-id' must be a valid integer", innerException);
					}
				}
			}
			else
			{
				SessionId((int?)null);
			}
			return this;
		}

		public ChannelUriStringBuilder TaggedSessionId(long? sessionId)
		{
			IsSessionIdTagged(isSessionIdTagged: true);
			_sessionId = sessionId;
			return this;
		}

		public ChannelUriStringBuilder SessionId(ChannelUri channelUri)
		{
			return SessionId(channelUri.Get("session-id"));
		}

		[Obsolete("this method will not correctly handle tagged sessionId values that are outside the range of")]
		public int? SessionId()
		{
			return (int?)_sessionId;
		}

		public ChannelUriStringBuilder Linger(long? lingerNs)
		{
			if (lingerNs.HasValue && lingerNs < 0)
			{
				long? num = lingerNs;
				throw new ArgumentException("linger value cannot be negative: " + num);
			}
			_linger = lingerNs;
			return this;
		}

		public ChannelUriStringBuilder Linger(ChannelUri channelUri)
		{
			string text = channelUri.Get("linger");
			if (text == null)
			{
				_linger = null;
				return this;
			}
			return Linger(SystemUtil.ParseDuration("linger", text));
		}

		public long? Linger()
		{
			return _linger;
		}

		public ChannelUriStringBuilder Sparse(bool? isSparse)
		{
			_sparse = isSparse;
			return this;
		}

		public ChannelUriStringBuilder Sparse(ChannelUri channelUri)
		{
			string text = channelUri.Get("sparse");
			if (text == null)
			{
				_sparse = null;
				return this;
			}
			return Sparse(Convert.ToBoolean(text));
		}

		public bool? Sparse()
		{
			return _sparse;
		}

		public ChannelUriStringBuilder Eos(bool? eos)
		{
			_eos = eos;
			return this;
		}

		public ChannelUriStringBuilder Eos(ChannelUri channelUri)
		{
			string text = channelUri.Get("eos");
			if (text == null)
			{
				_eos = null;
				return this;
			}
			return Eos(Convert.ToBoolean(text));
		}

		public bool? Eos()
		{
			return _eos;
		}

		public ChannelUriStringBuilder Tether(bool? tether)
		{
			_tether = tether;
			return this;
		}

		public ChannelUriStringBuilder Tether(ChannelUri channelUri)
		{
			string text = channelUri.Get("tether");
			if (text == null)
			{
				_tether = null;
				return this;
			}
			return Tether(Convert.ToBoolean(text));
		}

		public bool? Tether()
		{
			return _tether;
		}

		public ChannelUriStringBuilder Group(bool? group)
		{
			_group = group;
			return this;
		}

		public ChannelUriStringBuilder Group(ChannelUri channelUri)
		{
			string text = channelUri.Get("group");
			if (text == null)
			{
				_group = null;
				return this;
			}
			return Group(Convert.ToBoolean(text));
		}

		public bool? Group()
		{
			return _group;
		}

		public ChannelUriStringBuilder Tags(string tags)
		{
			_tags = tags;
			return this;
		}

		public ChannelUriStringBuilder Tags(ChannelUri channelUri)
		{
			return Tags(channelUri.Get("tags"));
		}

		public ChannelUriStringBuilder Tags(long? channelTag, long? pubSubTag)
		{
			if (!channelTag.HasValue && pubSubTag.HasValue)
			{
				throw new ArgumentException("null == channelTag && null != pubSubTag");
			}
			if (!channelTag.HasValue)
			{
				return Tags((string)null);
			}
			long? num = channelTag;
			string? text = num.ToString();
			object obj;
			if (!pubSubTag.HasValue)
			{
				obj = "";
			}
			else
			{
				num = pubSubTag;
				obj = "," + num;
			}
			return Tags(text + (string?)obj);
		}

		public string Tags()
		{
			return _tags;
		}

		public ChannelUriStringBuilder IsSessionIdTagged(bool isSessionIdTagged)
		{
			_isSessionIdTagged = isSessionIdTagged;
			return this;
		}

		public bool IsSessionIdTagged()
		{
			return _isSessionIdTagged;
		}

		public ChannelUriStringBuilder Alias(string alias)
		{
			_alias = alias;
			return this;
		}

		public ChannelUriStringBuilder Alias(ChannelUri channelUri)
		{
			return Alias(channelUri.Get("alias"));
		}

		public string Alias()
		{
			return _alias;
		}

		public ChannelUriStringBuilder CongestionControl(string congestionControl)
		{
			_cc = congestionControl;
			return this;
		}

		public ChannelUriStringBuilder CongestionControl(ChannelUri channelUri)
		{
			return CongestionControl(channelUri.Get("cc"));
		}

		public string CongestionControl()
		{
			return _cc;
		}

		public ChannelUriStringBuilder FlowControl(string flowControl)
		{
			_fc = flowControl;
			return this;
		}

		public ChannelUriStringBuilder TaggedFlowControl(long? groupTag, int? minGroupSize, string timeout)
		{
			string text = "tagged";
			if (groupTag.HasValue || minGroupSize.HasValue)
			{
				text += ",g:";
				if (groupTag.HasValue)
				{
					string text2 = text;
					long? num = groupTag;
					text = text2 + num;
				}
				if (minGroupSize.HasValue)
				{
					string text3 = text;
					int? num2 = minGroupSize;
					text = text3 + "/" + num2;
				}
			}
			if (timeout != null)
			{
				text = text + ",t:" + timeout;
			}
			return FlowControl(text);
		}

		public ChannelUriStringBuilder MinFlowControl(int? minGroupSize, string timeout)
		{
			string text = "min";
			if (minGroupSize.HasValue)
			{
				string text2 = text;
				int? num = minGroupSize;
				text = text2 + ",g:/" + num;
			}
			if (timeout != null)
			{
				text = text + ",t:" + timeout;
			}
			return FlowControl(text);
		}

		public ChannelUriStringBuilder FlowControl(ChannelUri channelUri)
		{
			return FlowControl(channelUri.Get("fc"));
		}

		public string FlowControl()
		{
			return _fc;
		}

		public ChannelUriStringBuilder GroupTag(long? groupTag)
		{
			_groupTag = groupTag;
			return this;
		}

		public ChannelUriStringBuilder GroupTag(ChannelUri channelUri)
		{
			string text = channelUri.Get("gtag");
			if (text == null)
			{
				_groupTag = null;
				return this;
			}
			try
			{
				return GroupTag(Convert.ToInt64(text));
			}
			catch (FormatException innerException)
			{
				throw new ArgumentException("'gtag# must be a valid long value", innerException);
			}
		}

		public long? GroupTag()
		{
			return _groupTag;
		}

		public ChannelUriStringBuilder Rejoin(bool? rejoin)
		{
			_rejoin = rejoin;
			return this;
		}

		public ChannelUriStringBuilder Rejoin(ChannelUri channelUri)
		{
			string text = channelUri.Get("rejoin");
			if (text == null)
			{
				_rejoin = null;
				return this;
			}
			return Rejoin(Convert.ToBoolean(text));
		}

		public bool? Rejoin()
		{
			return _rejoin;
		}

		public ChannelUriStringBuilder SpiesSimulateConnection(bool? spiesSimulateConnection)
		{
			_ssc = spiesSimulateConnection;
			return this;
		}

		public ChannelUriStringBuilder SpiesSimulateConnection(ChannelUri channelUri)
		{
			string text = channelUri.Get("ssc");
			if (text == null)
			{
				_ssc = null;
				return this;
			}
			return SpiesSimulateConnection(Convert.ToBoolean(text));
		}

		public bool? SpiesSimulateConnection()
		{
			return _ssc;
		}

		public ChannelUriStringBuilder InitialPosition(long position, int initialTermId, int termLength)
		{
			if (position < 0)
			{
				throw new ArgumentException("invalid position=" + position + " < 0");
			}
			if ((position & 0x1F) != 0L)
			{
				throw new ArgumentException("invalid position=" + position + " does not have frame alignment=" + 32);
			}
			int positionBitsToShift = LogBufferDescriptor.PositionBitsToShift(termLength);
			_initialTermId = initialTermId;
			_termId = LogBufferDescriptor.ComputeTermIdFromPosition(position, positionBitsToShift, initialTermId);
			_termOffset = (int)(position & (termLength - 1));
			_termLength = termLength;
			return this;
		}

		public ChannelUriStringBuilder SocketSndbufLength(int? socketSndbufLength)
		{
			_socketSndbufLength = socketSndbufLength;
			return this;
		}

		public ChannelUriStringBuilder SocketSndbufLength(ChannelUri channelUri)
		{
			string text = channelUri.Get("so-sndbuf");
			if (text == null)
			{
				_socketSndbufLength = null;
				return this;
			}
			long num = SystemUtil.ParseSize("so-sndbuf", text);
			if (num > int.MaxValue)
			{
				throw new ArgumentException("value exceeds maximum permitted: value=" + num);
			}
			return SocketSndbufLength((int)num);
		}

		public int? SocketSndbufLength()
		{
			return _socketSndbufLength;
		}

		public ChannelUriStringBuilder SocketRcvbufLength(int? socketRcvbufLength)
		{
			_socketRcvbufLength = socketRcvbufLength;
			return this;
		}

		public ChannelUriStringBuilder SocketRcvbufLength(ChannelUri channelUri)
		{
			string text = channelUri.Get("so-rcvbuf");
			if (text == null)
			{
				_socketRcvbufLength = null;
				return this;
			}
			long num = SystemUtil.ParseSize("so-rcvbuf", text);
			if (num > int.MaxValue)
			{
				throw new ArgumentException("value exceeds maximum permitted: value=" + num);
			}
			return SocketRcvbufLength((int)num);
		}

		public int? SocketRcvbufLength()
		{
			return _socketRcvbufLength;
		}

		public ChannelUriStringBuilder ReceiverWindowLength(int? receiverWindowLength)
		{
			_receiverWindowLength = receiverWindowLength;
			return this;
		}

		public ChannelUriStringBuilder ReceiverWindowLength(ChannelUri channelUri)
		{
			string text = channelUri.Get("rcv-wnd");
			if (text == null)
			{
				_receiverWindowLength = null;
				return this;
			}
			long num = SystemUtil.ParseSize("rcv-wnd", text);
			if (num > int.MaxValue)
			{
				throw new ArgumentException("value exceeds maximum permitted: value=" + num);
			}
			return ReceiverWindowLength((int)num);
		}

		public int? ReceiverWindowLength()
		{
			return _receiverWindowLength;
		}

		public string MediaReceiveTimestampOffset()
		{
			return _mediaReceiveTimestampOffset;
		}

		public ChannelUriStringBuilder MediaReceiveTimestampOffset(string timestampOffset)
		{
			if (timestampOffset != null && !"reserved".Equals(timestampOffset))
			{
				try
				{
					int.Parse(timestampOffset);
				}
				catch (FormatException)
				{
					throw new ArgumentException("mediaReceiveTimestampOffset must be a number or the value 'reserved' found: " + timestampOffset);
				}
			}
			_mediaReceiveTimestampOffset = timestampOffset;
			return this;
		}

		public ChannelUriStringBuilder MediaReceiveTimestampOffset(ChannelUri channelUri)
		{
			return MediaReceiveTimestampOffset(channelUri.Get("media-rcv-ts-offset"));
		}

		public string ChannelReceiveTimestampOffset()
		{
			return _channelReceiveTimestampOffset;
		}

		public ChannelUriStringBuilder ChannelReceiveTimestampOffset(string timestampOffset)
		{
			if (timestampOffset != null && !"reserved".Equals(timestampOffset))
			{
				try
				{
					int.Parse(timestampOffset);
				}
				catch (FormatException)
				{
					throw new ArgumentException("channelReceiveTimestampOffset must be a number or the value 'reserved' found: " + timestampOffset);
				}
			}
			_channelReceiveTimestampOffset = timestampOffset;
			return this;
		}

		public ChannelUriStringBuilder ChannelReceiveTimestampOffset(ChannelUri channelUri)
		{
			return ChannelReceiveTimestampOffset(channelUri.Get("channel-rcv-ts-offset"));
		}

		public ChannelUriStringBuilder ChannelSendTimestampOffset(string timestampOffset)
		{
			if (timestampOffset != null && !"reserved".Equals(timestampOffset))
			{
				try
				{
					int.Parse(timestampOffset);
				}
				catch (FormatException)
				{
					throw new ArgumentException("channelSendTimestampOffset must be a number or the value 'reserved' found: " + timestampOffset);
				}
			}
			_channelSendTimestampOffset = timestampOffset;
			return this;
		}

		public ChannelUriStringBuilder ChannelSendTimestampOffset(ChannelUri channelUri)
		{
			return ChannelSendTimestampOffset(channelUri.Get("channel-snd-ts-offset"));
		}

		public string ChannelSendTimestampOffset()
		{
			return _channelSendTimestampOffset;
		}

		public ChannelUriStringBuilder ResponseEndpoint(string responseEndpoint)
		{
			_responseEndpoint = responseEndpoint;
			return this;
		}

		public ChannelUriStringBuilder ResponseEndpoint(ChannelUri channelUri)
		{
			return ResponseEndpoint(channelUri.Get("response-endpoint"));
		}

		public string ResponseEndpoint()
		{
			return _responseEndpoint;
		}

		public string ResponseCorrelationId()
		{
			return _responseCorrelationId;
		}

		public ChannelUriStringBuilder ResponseCorrelationId(long? responseCorrelationId)
		{
			_responseCorrelationId = Convert.ToString(responseCorrelationId);
			return this;
		}

		public ChannelUriStringBuilder ResponseCorrelationId(string responseCorrelationId)
		{
			if (responseCorrelationId != null && !"prototype".Equals(responseCorrelationId))
			{
				try
				{
					if (long.Parse(responseCorrelationId) < -1)
					{
						throw new FormatException("responseCorrelationId must be positive");
					}
				}
				catch (FormatException)
				{
					throw new ArgumentException("responseCorrelationId must be a number greater than or equal to -1, or the value 'prototype' found: " + responseCorrelationId);
				}
			}
			_responseCorrelationId = responseCorrelationId;
			return this;
		}

		public ChannelUriStringBuilder ResponseCorrelationId(ChannelUri channelUri)
		{
			string text = channelUri.Get("response-correlation-id");
			if (text != null)
			{
				ResponseCorrelationId(text);
			}
			return this;
		}

		public ChannelUriStringBuilder NakDelay(string nakDelay)
		{
			if (this.nakDelay.HasValue)
			{
				this.nakDelay = SystemUtil.ParseDuration("nak-delay", nakDelay);
			}
			else
			{
				this.nakDelay = null;
			}
			return this;
		}

		pu