Merge remote-tracking branch 'origin/master'

This commit is contained in:
Manevolent
2018-10-13 01:35:14 -04:00
@@ -1146,30 +1146,39 @@ public abstract class AbstractTeamspeakClientSocket
@Override
public int getGeneration(int packetId) {
Pair<Integer, Integer> bufferStartCopy;
Pair<Integer, Integer> bufferEndCopy;
// Shorter synchronization
synchronized (this) {
bufferStartCopy = this.bufferStart;
bufferEndCopy = this.bufferEnd;
}
packetId %= generationSize;
// find if right of the start and within the start's bounds
if (packetId >= bufferStart.getValue()
&& packetId < bufferStart.getValue() + bufferSize
if (packetId >= bufferStartCopy.getValue()
&& packetId < bufferStartCopy.getValue() + bufferSize
&& packetId < generationSize) {
return bufferStart.getKey();
return bufferStartCopy.getKey();
}
// find if left of end and within the end's bounds
if (packetId <= bufferEnd.getValue()
if (packetId <= bufferEndCopy.getValue()
&& packetId > 0
&& packetId > bufferEnd.getValue() - bufferSize
&& packetId > bufferEndCopy.getValue() - bufferSize
&& packetId < generationSize) {
return bufferEnd.getKey();
return bufferEndCopy.getKey();
}
// find if outside of buffer to the right
if (packetId > bufferEnd.getValue())
return bufferEnd.getKey(); // ahead in current generation
if (packetId > bufferEndCopy.getValue())
return bufferEndCopy.getKey(); // ahead in current generation
// find if outside of buffer to the left
if (packetId < bufferStart.getValue())
return bufferEnd.getKey() + 1; // modulated wrap, ahead of current generation
if (packetId < bufferStartCopy.getValue())
return bufferEndCopy.getKey() + 1; // modulated wrap, ahead of current generation
// should never arrive here.
throw new IllegalStateException();
@@ -1187,6 +1196,7 @@ public abstract class AbstractTeamspeakClientSocket
@Override
public boolean put(int packetId) {
synchronized (this) {
// find if right of the start and within the start's bounds
if (packetId >= bufferStart.getValue()
&& packetId < bufferStart.getValue() + bufferSize
@@ -1258,14 +1268,22 @@ public abstract class AbstractTeamspeakClientSocket
return put(packetId);
}
}
@Override
public void reset() {
synchronized (this) {
for (int i = 0; i < bufferSize; i++)
buffer[i] = null;
this.buffer[i] = null;
this.bufferStart = new Pair<>(0, 0);
this.bufferEnd = new Pair<>(0, bufferSize - 1);
this.latestPacketId = 0;
}
}
private boolean putRelative(int index, int generation) {
synchronized (this) {
Integer existing = buffer[index];
if (existing == null || existing != generation) {
buffer[index] = generation;
@@ -1275,6 +1293,7 @@ public abstract class AbstractTeamspeakClientSocket
}
}
}
}
public static class RemoteCounterFullModulated extends RemoteCounterFull {
private final int modulationSize;