1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-23 02:58:00 +01:00

SMACK-384 Don't use a semaphore while waiting for PacketReader to be started.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@13581 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Florian Schmaus 2013-03-22 18:15:13 +00:00 committed by flow
parent a7d73993b0
commit bd70a95f8c

View file

@ -51,7 +51,6 @@ class PacketReader {
volatile boolean done; volatile boolean done;
private String connectionID = null; private String connectionID = null;
private Semaphore connectionSemaphore;
protected PacketReader(final XMPPConnection connection) { protected PacketReader(final XMPPConnection connection) {
this.connection = connection; this.connection = connection;
@ -97,21 +96,17 @@ class PacketReader {
* @throws XMPPException if the server fails to send an opening stream back * @throws XMPPException if the server fails to send an opening stream back
* for more than five seconds. * for more than five seconds.
*/ */
public void startup() throws XMPPException { synchronized public void startup() throws XMPPException {
connectionSemaphore = new Semaphore(1);
readerThread.start(); readerThread.start();
// Wait for stream tag before returing. We'll wait a couple of seconds before // Wait for stream tag before returning. We'll wait a couple of seconds before
// giving up and throwing an error. // giving up and throwing an error.
try { try {
connectionSemaphore.acquire();
// A waiting thread may be woken up before the wait time or a notify // A waiting thread may be woken up before the wait time or a notify
// (although this is a rare thing). Therefore, we continue waiting // (although this is a rare thing). Therefore, we continue waiting
// until either a connectionID has been set (and hence a notify was // until either a connectionID has been set (and hence a notify was
// made) or the total wait time has elapsed. // made) or the total wait time has elapsed.
int waitTime = SmackConfiguration.getPacketReplyTimeout(); int waitTime = SmackConfiguration.getPacketReplyTimeout();
connectionSemaphore.tryAcquire(3 * waitTime, TimeUnit.MILLISECONDS); wait(3 * waitTime);
} }
catch (InterruptedException ie) { catch (InterruptedException ie) {
// Ignore. // Ignore.
@ -304,8 +299,8 @@ class PacketReader {
* 3) TLS negotiation was successful * 3) TLS negotiation was successful
* *
*/ */
private void releaseConnectionIDLock() { synchronized private void releaseConnectionIDLock() {
connectionSemaphore.release(); notify();
} }
/** /**