mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Code formatting and small cleanups.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package org.briarproject.reliability;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
@@ -38,12 +39,12 @@ class Receiver implements ReadHandler {
|
||||
|
||||
Data read() throws IOException, InterruptedException {
|
||||
synchLock.lock();
|
||||
try{
|
||||
try {
|
||||
long now = clock.currentTimeMillis(), end = now + READ_TIMEOUT;
|
||||
while(now < end && valid) {
|
||||
if(dataFrames.isEmpty()) {
|
||||
// Wait for a data frame
|
||||
dataFrameAvailable.await(end - now, TimeUnit.MILLISECONDS);
|
||||
dataFrameAvailable.await(end - now, MILLISECONDS);
|
||||
} else {
|
||||
Data d = dataFrames.first();
|
||||
if(d.getSequenceNumber() == nextSequenceNumber) {
|
||||
@@ -55,15 +56,14 @@ class Receiver implements ReadHandler {
|
||||
return d;
|
||||
} else {
|
||||
// Wait for the next in-order data frame
|
||||
dataFrameAvailable.await(end - now, TimeUnit.MILLISECONDS);
|
||||
dataFrameAvailable.await(end - now, MILLISECONDS);
|
||||
}
|
||||
}
|
||||
now = clock.currentTimeMillis();
|
||||
}
|
||||
if(valid) throw new IOException("Read timed out");
|
||||
throw new IOException("Connection closed");
|
||||
}
|
||||
finally{
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
}
|
||||
}
|
||||
@@ -73,8 +73,7 @@ class Receiver implements ReadHandler {
|
||||
synchLock.lock();
|
||||
try {
|
||||
dataFrameAvailable.signalAll();
|
||||
}
|
||||
finally{
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
}
|
||||
}
|
||||
@@ -97,7 +96,7 @@ class Receiver implements ReadHandler {
|
||||
|
||||
private void handleData(byte[] b) throws IOException {
|
||||
synchLock.lock();
|
||||
try{
|
||||
try {
|
||||
if(b.length < Data.MIN_LENGTH || b.length > Data.MAX_LENGTH) {
|
||||
// Ignore data frame with invalid length
|
||||
return;
|
||||
@@ -134,8 +133,7 @@ class Receiver implements ReadHandler {
|
||||
}
|
||||
// Acknowledge the data frame even if it's a duplicate
|
||||
sender.sendAck(sequenceNumber, windowSize);
|
||||
}
|
||||
finally{
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package org.briarproject.reliability;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
@@ -101,9 +102,9 @@ class Sender {
|
||||
// Don't accept an unreasonably large window size
|
||||
windowSize = Math.min(a.getWindowSize(), MAX_WINDOW_SIZE);
|
||||
// If space has become available, notify any waiting writers
|
||||
if(windowSize > oldWindowSize || foundIndex != -1) sendWindowAvailable.signalAll();
|
||||
}
|
||||
finally{
|
||||
if(windowSize > oldWindowSize || foundIndex != -1)
|
||||
sendWindowAvailable.signalAll();
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
}
|
||||
// Fast retransmission
|
||||
@@ -145,8 +146,7 @@ class Sender {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally{
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
}
|
||||
// Send a window probe if necessary
|
||||
@@ -171,7 +171,7 @@ class Sender {
|
||||
long now = clock.currentTimeMillis(), end = now + WRITE_TIMEOUT;
|
||||
while(now < end && outstandingBytes + payloadLength >= windowSize) {
|
||||
dataWaiting = true;
|
||||
sendWindowAvailable.await(end - now, TimeUnit.MILLISECONDS);
|
||||
sendWindowAvailable.await(end - now, MILLISECONDS);
|
||||
now = clock.currentTimeMillis();
|
||||
}
|
||||
if(outstandingBytes + payloadLength >= windowSize)
|
||||
@@ -179,8 +179,7 @@ class Sender {
|
||||
outstanding.add(new Outstanding(d, now));
|
||||
outstandingBytes += payloadLength;
|
||||
dataWaiting = false;
|
||||
}
|
||||
finally{
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
}
|
||||
writeHandler.handleWrite(d.getBuffer());
|
||||
@@ -188,10 +187,10 @@ class Sender {
|
||||
|
||||
void flush() throws IOException, InterruptedException {
|
||||
synchLock.lock();
|
||||
try{
|
||||
while(dataWaiting || !outstanding.isEmpty()) sendWindowAvailable.await();
|
||||
}
|
||||
finally{
|
||||
try {
|
||||
while(dataWaiting || !outstanding.isEmpty())
|
||||
sendWindowAvailable.await();
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user