OnDisconnect() private method

private OnDisconnect ( ENetEvent eNetEvent ) : void
eNetEvent ENetEvent
return void
Ejemplo n.º 1
0
        public void Update()
        {
            this.OnEvents();

            if (this.Service() < 0)
            {
                return;
            }

            while (true)
            {
                ENetEvent eNetEvent = this.TryGetEvent();
                if (eNetEvent == null)
                {
                    return;
                }

                switch (eNetEvent.Type)
                {
                case EventType.Connect:
                {
                    // 这是一个connect peer
                    if (this.USocketManager.ContainsKey(eNetEvent.Peer))
                    {
                        USocket uSocket = this.USocketManager[eNetEvent.Peer];
                        uSocket.OnConnected();
                        break;
                    }

                    // 这是accept peer
                    if (this.AcceptTcs != null)
                    {
                        this.OnAccepted(eNetEvent);
                        break;
                    }

                    // 如果server端没有acceptasync,则请求放入队列
                    this.connQueue.Add(eNetEvent.Peer, eNetEvent);
                    break;
                }

                case EventType.Receive:
                {
                    USocket uSocket = this.USocketManager[eNetEvent.Peer];
                    uSocket.OnReceived(eNetEvent);
                    break;
                }

                case EventType.Disconnect:
                {
                    USocket uSocket = this.USocketManager[eNetEvent.Peer];
                    this.USocketManager.Remove(uSocket.PeerPtr);
                    uSocket.PeerPtr = IntPtr.Zero;
                    uSocket.OnDisconnect(eNetEvent);
                    break;
                }
                }
            }
        }
Ejemplo n.º 2
0
        public void Update()
        {
            this.OnEvents();

            if (this.Service() < 0)
            {
                return;
            }

            while (true)
            {
                if (NativeMethods.enet_host_check_events(this.host, ref this.eNetEventCache) <= 0)
                {
                    return;
                }

                switch (this.eNetEventCache.Type)
                {
                case EventType.Connect:
                {
                    // 这是一个connect peer
                    if (this.USocketManager.ContainsKey(this.eNetEventCache.Peer))
                    {
                        USocket uSocket = this.USocketManager[this.eNetEventCache.Peer];
                        uSocket.OnConnected();
                        break;
                    }

                    // 这是accept peer
                    if (this.AcceptTcs != null)
                    {
                        this.OnAccepted(this.eNetEventCache);
                        break;
                    }

                    // 如果server端没有acceptasync,则请求放入队列
                    this.connQueue.Enqueue(this.eNetEventCache.Peer);
                    break;
                }

                case EventType.Receive:
                {
                    USocket uSocket = this.USocketManager[this.eNetEventCache.Peer];
                    uSocket.OnReceived(this.eNetEventCache);
                    break;
                }

                case EventType.Disconnect:
                {
                    USocket uSocket = this.USocketManager[this.eNetEventCache.Peer];
                    this.USocketManager.Remove(uSocket.PeerPtr);
                    uSocket.PeerPtr = IntPtr.Zero;
                    uSocket.OnDisconnect(this.eNetEventCache);
                    break;
                }
                }
            }
        }
Ejemplo n.º 3
0
        public void Update()
        {
            this.OnEvents();

            if (this.Service() < 0)
            {
                return;
            }

            while (true)
            {
                ENetEvent eNetEvent = this.GetEvent();
                if (eNetEvent == null)
                {
                    return;
                }

                switch (eNetEvent.Type)
                {
                case EventType.Connect:
                {
                    // 这是一个connect peer
                    if (this.USocketManager.ContainsKey(eNetEvent.Peer))
                    {
                        USocket uSocket = this.USocketManager[eNetEvent.Peer];
                        uSocket.OnConnected(eNetEvent);
                    }
                    break;
                }

                case EventType.Receive:
                {
                    USocket uSocket = this.USocketManager[eNetEvent.Peer];
                    uSocket.OnReceived(eNetEvent);
                    break;
                }

                case EventType.Disconnect:
                {
                    USocket uSocket = this.USocketManager[eNetEvent.Peer];
                    this.USocketManager.Remove(uSocket.PeerPtr);
                    uSocket.PeerPtr = IntPtr.Zero;
                    uSocket.OnDisconnect(eNetEvent);
                    break;
                }
                }
            }
        }