Exemplo n.º 1
0
        private void SendAckQueue(object state)
        {
            Parallel.ForEach(_playerSessions.Values.ToArray(), delegate(PlayerNetworkSession session)
            {
                var queue  = session.PlayerAckQueue;
                int lenght = queue.Count;

                if (lenght == 0)
                {
                    return;
                }

                Acks acks = Acks.CreateObject();
                for (int i = 0; i < lenght; i++)
                {
                    int ack;
                    if (!session.PlayerAckQueue.TryDequeue(out ack))
                    {
                        break;
                    }

                    acks.acks.Add(ack);
                }

                if (acks.acks.Count > 0)
                {
                    byte[] data = acks.Encode();
                    SendData(data, session.EndPoint, session.SyncRoot);
                }

                acks.PutPool();
            });
        }
Exemplo n.º 2
0
        private void SendAckQueue()
        {
            PlayerNetworkSession session = this;
            var queue  = session.PlayerAckQueue;
            int lenght = queue.Count;

            if (lenght == 0)
            {
                return;
            }

            Acks acks = Acks.CreateObject();

            //Acks acks = new Acks();
            for (int i = 0; i < lenght; i++)
            {
                int ack;
                if (!session.PlayerAckQueue.TryDequeue(out ack))
                {
                    break;
                }

                Interlocked.Increment(ref Server.ServerInfo.NumberOfAckSent);
                acks.acks.Add(ack);
            }

            if (acks.acks.Count > 0)
            {
                byte[] data = acks.Encode();
                Server.SendData(data, session.EndPoint);
            }

            acks.PutPool();
        }
Exemplo n.º 3
0
		private void SendAckQueue(object state)
		{
			var sessions = _playerSessions.Values.ToArray();

			foreach (var s in sessions)
			{
				ThreadPool.QueueUserWorkItem(delegate(object o)
				{
					PlayerNetworkSession session = (PlayerNetworkSession) o;
					var queue = session.PlayerAckQueue;
					int lenght = queue.Count;

					if (lenght == 0) return;

					Acks acks = Acks.CreateObject();
					for (int i = 0; i < lenght; i++)
					{
						int ack;
						if (!session.PlayerAckQueue.TryDequeue(out ack)) break;

						acks.acks.Add(ack);
					}

					if (acks.acks.Count > 0)
					{
						byte[] data = acks.Encode();
						SendData(data, session.EndPoint);
					}

					acks.PutPool();
				}, s);
			}
		}