public HeapPointers HandleIncomingMessagePoll(ArraySegment <byte> payload) { // Read the sequence number ushort sequence = (ushort)(payload.Array[payload.Offset] | (ushort)(payload.Array[payload.Offset + 1] << 8)); lock (_receiveLock) { if (_incomingAckedPackets.Contains(sequence)) { // We have already received this message. Ignore it. return(null); } // Add to sequencer _incomingAckedPackets.Set(sequence, true); // Alloc pointers HeapPointers pointers = memoryManager.AllocHeapPointers(1); // Alloc wrapper pointers.Pointers[0] = memoryManager.AllocMemoryWrapper(new ArraySegment <byte>(payload.Array, payload.Offset + 2, payload.Count - 2)); return(pointers); } }
public HeapPointers HandleIncomingMessagePoll(ArraySegment <byte> payload) { // -> Sorting happens in the ConcurrentCircularQueue when messages are Enqueued // // Read the sequence number ushort sequence = (ushort)(payload.Array[payload.Offset] | (ushort)(payload.Array[payload.Offset + 1] << 8)); lock (_receiveLock) { if (_incomingAckedPackets.Contains(sequence)) { // We have already received this message. Ignore it. return(null); } /* if (SequencingUtils.Distance(sequence, _incomingLowestAckedSequence, sizeof(ushort)) <= 0) * { * if (SequencingUtils.Distance(sequence, _lastPollSequence, sizeof(ushort)) > 0) * { * Logging.LogInfo("Skipping dropping packet since it's newer than _lastPollSequence (" + _lastPollSequence + ") | _incomingLowestAckedSequence: " + _incomingLowestAckedSequence + " | currentSequence: " + sequence); * } * } */ if (SequencingUtils.Distance(sequence, _lastPollSequence, sizeof(ushort)) > 0) // ! We're using _lastPollSequence instead of _incomingLowestAckedSequence to not drop old packets if we're still waiting for them to be polled by the game/MLAPI, which can still be sorted properly { // Set the new sequence _incomingLowestAckedSequence = sequence; _incomingAckedPackets.Set(sequence, true); // Alloc pointers HeapPointers pointers = memoryManager.AllocHeapPointers(1); // Alloc wrapper pointers.Pointers[0] = memoryManager.AllocMemoryWrapper(new ArraySegment <byte>(payload.Array, payload.Offset + 2, payload.Count - 2)); return(pointers); } return(null); } }