This commit is contained in:
akwizgran
2011-10-14 21:37:55 +01:00
parent 0d11553134
commit cb06ebc5d2

View File

@@ -18,7 +18,7 @@ public class OutgoingStreamConnection extends StreamConnection {
private final TransportId transportId; private final TransportId transportId;
private long connectionNum = -1L; private long connectionNum = -1L; // Locking: this
OutgoingStreamConnection(ConnectionReaderFactory connReaderFactory, OutgoingStreamConnection(ConnectionReaderFactory connReaderFactory,
ConnectionWriterFactory connWriterFactory, DatabaseComponent db, ConnectionWriterFactory connWriterFactory, DatabaseComponent db,
@@ -33,8 +33,10 @@ public class OutgoingStreamConnection extends StreamConnection {
@Override @Override
protected ConnectionReader createConnectionReader() throws DbException, protected ConnectionReader createConnectionReader() throws DbException,
IOException { IOException {
if(connectionNum == -1L) synchronized(this) {
connectionNum = db.getConnectionNumber(contactId, transportId); if(connectionNum == -1L)
connectionNum = db.getConnectionNumber(contactId, transportId);
}
byte[] secret = db.getSharedSecret(contactId); byte[] secret = db.getSharedSecret(contactId);
return connReaderFactory.createConnectionReader( return connReaderFactory.createConnectionReader(
connection.getInputStream(), false, transportId, connectionNum, connection.getInputStream(), false, transportId, connectionNum,
@@ -44,8 +46,10 @@ public class OutgoingStreamConnection extends StreamConnection {
@Override @Override
protected ConnectionWriter createConnectionWriter() throws DbException, protected ConnectionWriter createConnectionWriter() throws DbException,
IOException { IOException {
if(connectionNum == -1L) synchronized(this) {
connectionNum = db.getConnectionNumber(contactId, transportId); if(connectionNum == -1L)
connectionNum = db.getConnectionNumber(contactId, transportId);
}
byte[] secret = db.getSharedSecret(contactId); byte[] secret = db.getSharedSecret(contactId);
return connWriterFactory.createConnectionWriter( return connWriterFactory.createConnectionWriter(
connection.getOutputStream(), Long.MAX_VALUE, true, transportId, connection.getOutputStream(), Long.MAX_VALUE, true, transportId,