public Payloads(int capacity, uint maxPayloadSize)
 {
     m_PayloadSize   = maxPayloadSize;
     m_Handles       = new UnsafeAtomicFreeList(capacity, Allocator.Persistent);
     m_PayloadArray  = new UnsafeBaselibNetworkArray(capacity * (int)maxPayloadSize);
     m_EndpointArray = new UnsafeBaselibNetworkArray(capacity * (int)Binding.Baselib_RegisteredNetwork_Endpoint_MaxSize);
 }
        public unsafe void Initialize(params INetworkParameter[] param)
        {
            //if (!Binding.Baselib_RegisteredNetwork_SupportsNetwork())
            //    throw new Exception("Baselib does not support networking");

            m_Baselib = new NativeArray <BaselibData>(1, Allocator.Persistent);

            var baselib = default(BaselibData);

            rxQueueSize        = k_defaultRxQueueSize;
            txQueueSize        = k_defaultTxQueueSize;
            maximumPayloadSize = NetworkParameterConstants.MTU;

            for (int i = 0; i < param.Length; ++i)
            {
                if (param[i] is BaselibNetworkParameter)
                {
                    var config = (BaselibNetworkParameter)param[i];
                    rxQueueSize        = config.receiveQueueCapacity;
                    txQueueSize        = config.sendQueueCapacity;
                    maximumPayloadSize = config.maximumPayloadSize;
                }
            }

            m_PayloadsTx           = new Payloads(txQueueSize, maximumPayloadSize);
            m_PayloadsRx           = new Payloads(rxQueueSize, maximumPayloadSize);
            m_LocalAndTempEndpoint = new UnsafeBaselibNetworkArray(2 * (int)Binding.Baselib_RegisteredNetwork_Endpoint_MaxSize);

            baselib.m_PayloadsTx = m_PayloadsTx;

            m_Baselib[0] = baselib;

            // Emulate current interface behavior
            NetworkInterfaceEndPoint ep = CreateInterfaceEndPoint(NetworkEndPoint.AnyIpv4);

            if (Bind(ep) != 0)
            {
                throw new Exception("Could not bind socket");
            }
        }