Merge remote-tracking branch 'origin/master'
This commit is contained in:
+33
-14
@@ -1146,30 +1146,39 @@ public abstract class AbstractTeamspeakClientSocket
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getGeneration(int packetId) {
|
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;
|
packetId %= generationSize;
|
||||||
|
|
||||||
// find if right of the start and within the start's bounds
|
// find if right of the start and within the start's bounds
|
||||||
if (packetId >= bufferStart.getValue()
|
if (packetId >= bufferStartCopy.getValue()
|
||||||
&& packetId < bufferStart.getValue() + bufferSize
|
&& packetId < bufferStartCopy.getValue() + bufferSize
|
||||||
&& packetId < generationSize) {
|
&& packetId < generationSize) {
|
||||||
return bufferStart.getKey();
|
return bufferStartCopy.getKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
// find if left of end and within the end's bounds
|
// find if left of end and within the end's bounds
|
||||||
if (packetId <= bufferEnd.getValue()
|
if (packetId <= bufferEndCopy.getValue()
|
||||||
&& packetId > 0
|
&& packetId > 0
|
||||||
&& packetId > bufferEnd.getValue() - bufferSize
|
&& packetId > bufferEndCopy.getValue() - bufferSize
|
||||||
&& packetId < generationSize) {
|
&& packetId < generationSize) {
|
||||||
return bufferEnd.getKey();
|
return bufferEndCopy.getKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
// find if outside of buffer to the right
|
// find if outside of buffer to the right
|
||||||
if (packetId > bufferEnd.getValue())
|
if (packetId > bufferEndCopy.getValue())
|
||||||
return bufferEnd.getKey(); // ahead in current generation
|
return bufferEndCopy.getKey(); // ahead in current generation
|
||||||
|
|
||||||
// find if outside of buffer to the left
|
// find if outside of buffer to the left
|
||||||
if (packetId < bufferStart.getValue())
|
if (packetId < bufferStartCopy.getValue())
|
||||||
return bufferEnd.getKey() + 1; // modulated wrap, ahead of current generation
|
return bufferEndCopy.getKey() + 1; // modulated wrap, ahead of current generation
|
||||||
|
|
||||||
// should never arrive here.
|
// should never arrive here.
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
@@ -1187,6 +1196,7 @@ public abstract class AbstractTeamspeakClientSocket
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean put(int packetId) {
|
public boolean put(int packetId) {
|
||||||
|
synchronized (this) {
|
||||||
// find if right of the start and within the start's bounds
|
// find if right of the start and within the start's bounds
|
||||||
if (packetId >= bufferStart.getValue()
|
if (packetId >= bufferStart.getValue()
|
||||||
&& packetId < bufferStart.getValue() + bufferSize
|
&& packetId < bufferStart.getValue() + bufferSize
|
||||||
@@ -1229,7 +1239,7 @@ public abstract class AbstractTeamspeakClientSocket
|
|||||||
System.arraycopy(buffer, amountMoved, buffer, 0, toMove);
|
System.arraycopy(buffer, amountMoved, buffer, 0, toMove);
|
||||||
|
|
||||||
int toNullify = Math.max(0, Math.min(bufferSize, amountMoved));
|
int toNullify = Math.max(0, Math.min(bufferSize, amountMoved));
|
||||||
for (int i = bufferSize - toNullify; i < bufferSize; i ++)
|
for (int i = bufferSize - toNullify; i < bufferSize; i++)
|
||||||
buffer[i] = null;
|
buffer[i] = null;
|
||||||
|
|
||||||
int bufferStartGeneration = bufferStart.getKey();
|
int bufferStartGeneration = bufferStart.getKey();
|
||||||
@@ -1238,7 +1248,7 @@ public abstract class AbstractTeamspeakClientSocket
|
|||||||
bufferStartPosition += amountMoved;
|
bufferStartPosition += amountMoved;
|
||||||
if (bufferStartPosition >= generationSize) {
|
if (bufferStartPosition >= generationSize) {
|
||||||
bufferStartPosition %= generationSize;
|
bufferStartPosition %= generationSize;
|
||||||
bufferStartGeneration ++;
|
bufferStartGeneration++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bufferEndGeneration;
|
int bufferEndGeneration;
|
||||||
@@ -1258,14 +1268,22 @@ public abstract class AbstractTeamspeakClientSocket
|
|||||||
|
|
||||||
return put(packetId);
|
return put(packetId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
for (int i = 0; i < bufferSize; i ++)
|
synchronized (this) {
|
||||||
buffer[i] = null;
|
for (int i = 0; i < bufferSize; i++)
|
||||||
|
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) {
|
private boolean putRelative(int index, int generation) {
|
||||||
|
synchronized (this) {
|
||||||
Integer existing = buffer[index];
|
Integer existing = buffer[index];
|
||||||
if (existing == null || existing != generation) {
|
if (existing == null || existing != generation) {
|
||||||
buffer[index] = generation;
|
buffer[index] = generation;
|
||||||
@@ -1275,6 +1293,7 @@ public abstract class AbstractTeamspeakClientSocket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class RemoteCounterFullModulated extends RemoteCounterFull {
|
public static class RemoteCounterFullModulated extends RemoteCounterFull {
|
||||||
private final int modulationSize;
|
private final int modulationSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user