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(); }
private async Task SendAckQueueAsync() { var queue = OutgoingAckQueue; int queueCount = queue.Count; if (queueCount == 0) { return; } var acks = Acks.CreateObject(); for (int i = 0; i < queueCount; i++) { if (!queue.TryDequeue(out int ack)) { break; } _nacked.Remove(ack); acks.acks.Add(ack); } if (acks.acks.Count > 0) { byte[] data = acks.Encode(); await _packetSender.SendDataAsync(data, EndPoint); Interlocked.Increment(ref ConnectionInfo.AckSent); } acks.PutPool(); }
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(); }); }
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); } }