public static ReliableMessageReceiveTracking Create() { ReliableMessageReceiveTracking rmrt = Recycler <ReliableMessageReceiveTracking> .GetObject(); rmrt.receivePartsLength = 0; rmrt.receivePartsLeft = 0; rmrt.networkMessage = null; return(rmrt); }
public void Destroy() { if (networkMessage != null) { networkMessage.Destroy(); } networkMessage = null; Recycler <ReliableMessageSendTracking <T> > .ReleaseObject(this); }
public static ReliableMessageSendTracking <T> Create() { ReliableMessageSendTracking <T> rmst = Recycler <ReliableMessageSendTracking <T> > .GetObject(); rmst.sendPartsLength = 0; rmst.sendPartsLeft = 0; rmst.nextSendPart = 0; rmst.finished = false; return(rmst); }
public void Destroy() { int usageLeft = Interlocked.Decrement(ref usageCount); if (usageLeft == 0) { if (data != null) { ByteRecycler.ReleaseObject(data); } Recycler <NetworkMessage> .ReleaseObject(this); } }
public static NetworkMessage Create(int type, int size, NetworkMessageType sendType) { NetworkMessage retVal = Recycler <NetworkMessage> .GetObject(); retVal.type = type; retVal.sendType = sendType; retVal.data = null; if (size > 0) { retVal.data = ByteRecycler.GetObject(size); } retVal.usageCount = 1; return(retVal); }
public void FireCallbacks() { if (!useMessagePump) { return; } lock (messages) { foreach (QueuedMessage <T> qm in messages) { HandleReal(qm.networkMessage, qm.connection); Recycler <QueuedMessage <T> > .ReleaseObject(qm); } messages.Clear(); } }
public void SendRawHighPriority(NetworkMessage networkMessage, Connection <T> connection) { lock (sendHighPriorityMessages) { QueuedMessage <T> qm = Recycler <QueuedMessage <T> > .GetObject(); qm.networkMessage = networkMessage; qm.connection = connection; sendHighPriorityMessages.Enqueue(qm); if (networkMessage.data != null) { connection.queuedOut += networkMessage.data.Length; } sendEvent.Set(); } }
public void Handle(NetworkMessage nm, Connection <T> connection) { if (useMessagePump && nm.type >= 0) { lock (messages) { QueuedMessage <T> qm = Recycler <QueuedMessage <T> > .GetObject(); qm.networkMessage = nm; qm.connection = connection; messages.Add(qm); } } else { HandleReal(nm, connection); } }
public void Destroy() { networkMessage = null; Recycler <ReliableMessageReceiveTracking> .ReleaseObject(this); }
private void SendLoop() { while (running) { sendEvent.WaitOne(50); bool sending = true; while (sending) { sending = false; lock (sendHighPriorityMessages) { while (sendHighPriorityMessages.Count > 0) { QueuedMessage <T> qm = sendHighPriorityMessages.Dequeue(); if (qm.networkMessage.data != null) { qm.connection.queuedOut -= qm.networkMessage.data.Length; } ActualSendMessage(qm.networkMessage, qm.connection); Recycler <QueuedMessage <T> > .ReleaseObject(qm); sending = true; } } lock (sendMessages) { foreach (KeyValuePair <Connection <T>, Queue <NetworkMessage> > kvp in sendMessages) { Connection <T> connection = kvp.Key; Queue <NetworkMessage> sendQueue = kvp.Value; while (sendQueue.Count > 0) { if (sendHighPriorityMessages.Count > 0) { break; } NetworkMessage peekMessage = sendQueue.Peek(); //Reliable messages are broken up and do not create actual sends. if (peekMessage.IsReliable()) { NetworkMessage reliableMessage = sendQueue.Dequeue(); if (reliableMessage.data != null) { connection.queuedOut -= reliableMessage.data.Length; } connection.reliableMessageHandler.Queue(reliableMessage); connection.reliableMessageHandler.Send(); continue; } else { if (peekMessage.data != null) { if (peekMessage.data.Length > connection.tokens) { //Not enough tokens to send break; } } NetworkMessage sendMessage = sendQueue.Dequeue(); if (sendMessage.data != null) { connection.queuedOut -= sendMessage.data.Length; } ActualSendMessage(sendMessage, connection); sending = true; } } if (sendHighPriorityMessages.Count > 0) { break; } } } } handler.SendHeartbeat(); } }