Exemplo n.º 1
0
        public void Create(Address?address, int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth)
        {
            if (_host != null)
            {
                throw new InvalidOperationException("Already created.");
            }
            if (peerLimit < 0 || peerLimit > Native.ENET_PROTOCOL_MAXIMUM_PEER_ID)
            {
                throw new ArgumentOutOfRangeException("peerLimit");
            }
            CheckChannelLimit(channelLimit);

            if (address != null)
            {
                var nativeAddress = address.Value.NativeData;
                _host = Native.enet_host_create(ref nativeAddress, (IntPtr)peerLimit,
                                                incomingBandwidth, outgoingBandwidth);
            }
            else
            {
                _host = Native.enet_host_create(null, (IntPtr)peerLimit,
                                                incomingBandwidth, outgoingBandwidth);
            }
            if (_host == null)
            {
                throw new ENetException(0, "Host creation call failed.");
            }
        }
Exemplo n.º 2
0
        public void Create(Address?address, int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth, int bufferSize)
        {
            if (nativeHost != IntPtr.Zero)
            {
                throw new InvalidOperationException("Host already created");
            }

            if (peerLimit < 0 || peerLimit > Library.maxPeers)
            {
                throw new ArgumentOutOfRangeException("peerLimit");
            }

            ThrowIfChannelsExceeded(channelLimit);

            if (address != null)
            {
                var nativeAddress = address.Value.NativeData;

                nativeHost = Native.enet_host_create(ref nativeAddress, (IntPtr)peerLimit, (IntPtr)channelLimit, incomingBandwidth, outgoingBandwidth, bufferSize);
            }
            else
            {
                nativeHost = Native.enet_host_create(IntPtr.Zero, (IntPtr)peerLimit, (IntPtr)channelLimit, incomingBandwidth, outgoingBandwidth, bufferSize);
            }

            if (nativeHost == IntPtr.Zero)
            {
                throw new InvalidOperationException("Host creation call failed");
            }
        }
Exemplo n.º 3
0
        public void Create(Address address, int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth, int bufferSize)
        {
            if (nativeHost != IntPtr.Zero)
            {
                throw new InvalidOperationException("Host already created");
            }

            if (peerLimit < 0 || peerLimit > Library.maxPeers)
            {
                throw new ENetError(ENetErrorCode.PeersLimitOutOfBound, "Peers limit is more than max peers count.");
            }

            ThrowIfChannelsExceeded(channelLimit);

            nativeHost = Native.enet_host_create(ref address, (IntPtr)peerLimit, (IntPtr)channelLimit, incomingBandwidth, outgoingBandwidth, bufferSize);

            if (nativeHost == IntPtr.Zero)
            {
                Library.ThrowLastError();
            }
        }