From f154c49e7f18b2f12d1ea724b7230621e7886665 Mon Sep 17 00:00:00 2001 From: erickson Date: Sat, 28 Jul 2007 17:41:32 +0000 Subject: [PATCH] synchronizing the initial xmpp login to prevent thread race condition on authentication git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1064 9efc2488-bf62-4759-914b-345cdb29e865 --- .../org/opensrf/net/xmpp/XMPPSession.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/java/org/opensrf/net/xmpp/XMPPSession.java b/src/java/org/opensrf/net/xmpp/XMPPSession.java index e8b639e..11e0c7d 100644 --- a/src/java/org/opensrf/net/xmpp/XMPPSession.java +++ b/src/java/org/opensrf/net/xmpp/XMPPSession.java @@ -113,29 +113,33 @@ public class XMPPSession { thread.setDaemon(true); thread.start(); - /* send the initial jabber message */ - sendConnect(); - reader.waitCoreEvent(10000); + synchronized(reader) { + /* send the initial jabber message */ + sendConnect(); + reader.waitCoreEvent(10000); + } if( reader.getXMPPStreamState() != XMPPReader.XMPPStreamState.CONNECT_RECV ) throw new XMPPException("unable to connect to jabber server"); - /* send the basic auth message */ - sendBasicAuth(); /* XXX add support for other auth mechanisms */ - reader.waitCoreEvent(10000); - if(!connected()) + synchronized(reader) { + /* send the basic auth message */ + sendBasicAuth(); + reader.waitCoreEvent(10000); + } + if(!connected()) throw new XMPPException("Authentication failed"); } /** Sends the initial jabber message */ private void sendConnect() { - writer.printf(JABBER_CONNECT, host); reader.setXMPPStreamState(XMPPReader.XMPPStreamState.CONNECT_SENT); + writer.printf(JABBER_CONNECT, host); } /** Send the basic auth message */ private void sendBasicAuth() { - writer.printf(JABBER_BASIC_AUTH, username, password, resource); reader.setXMPPStreamState(XMPPReader.XMPPStreamState.AUTH_SENT); + writer.printf(JABBER_BASIC_AUTH, username, password, resource); } -- 2.43.2