mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-18 21:02:04 +01:00
Better threading logic when waiting for a connection (SMACK-37).
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2469 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
be8535765a
commit
92869fa583
1 changed files with 16 additions and 2 deletions
|
@ -142,7 +142,21 @@ class PacketReader {
|
||||||
// giving up and throwing an error.
|
// giving up and throwing an error.
|
||||||
try {
|
try {
|
||||||
synchronized(connectionIDLock) {
|
synchronized(connectionIDLock) {
|
||||||
connectionIDLock.wait(SmackConfiguration.getPacketReplyTimeout());
|
if (connectionID == null) {
|
||||||
|
// A waiting thread may be woken up before the wait time or a notify
|
||||||
|
// (although this is a rare thing). Therefore, we continue waiting
|
||||||
|
// until either a connectionID has been set (and hence a notify was
|
||||||
|
// made) or the total wait time has elapsed.
|
||||||
|
long waitTime = SmackConfiguration.getPacketReplyTimeout();
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
while (connectionID == null && !done) {
|
||||||
|
if (waitTime <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
connectionIDLock.wait(waitTime);
|
||||||
|
waitTime -= System.currentTimeMillis() - start;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException ie) { }
|
catch (InterruptedException ie) { }
|
||||||
|
@ -252,8 +266,8 @@ class PacketReader {
|
||||||
for (int i=0; i<parser.getAttributeCount(); i++) {
|
for (int i=0; i<parser.getAttributeCount(); i++) {
|
||||||
if (parser.getAttributeName(i).equals("id")) {
|
if (parser.getAttributeName(i).equals("id")) {
|
||||||
// Save the connectionID and notify that we've gotten it.
|
// Save the connectionID and notify that we've gotten it.
|
||||||
connectionID = parser.getAttributeValue(i);
|
|
||||||
synchronized(connectionIDLock) {
|
synchronized(connectionIDLock) {
|
||||||
|
connectionID = parser.getAttributeValue(i);
|
||||||
connectionIDLock.notifyAll();
|
connectionIDLock.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue