Example #1
0
        UdpSocket(UdpPlatform platform, UdpSerializerFactory serializerFactory, UdpConfig config)
        {
            this.platform          = platform;
            this.serializerFactory = serializerFactory;
            this.Config            = config.Duplicate();
            this.configCopy        = config;

            state          = UdpSocketState.Created;
            random         = new System.Random();
            stats          = new UdpStats();
            availableEvent = new AutoResetEvent(false);

            if (this.Config.NoiseFunction == null)
            {
                this.Config.NoiseFunction = delegate() { return((float)random.NextDouble()); };
            }

            readStream  = new UdpStream(new byte[config.PacketSize * 2]);
            writeStream = new UdpStream(new byte[config.PacketSize * 2]);
            streamPool  = new UdpStreamPool(this);

            eventQueueIn  = new Queue <UdpEvent>(config.InitialEventQueueSize);
            eventQueueOut = new Queue <UdpEvent>(config.InitialEventQueueSize);

            threadSocket              = new Thread(NetworkLoop);
            threadSocket.Name         = "udpkit thread";
            threadSocket.IsBackground = true;
            threadSocket.Start();
        }
Example #2
0
        bool CheckState(UdpSocketState s)
        {
            if (state != s)
            {
                return(false);
            }

            return(true);
        }
Example #3
0
        bool ChangeState(UdpSocketState from, UdpSocketState to)
        {
            if (CheckState(from))
            {
                state = to;
                return(true);
            }

            return(false);
        }