From 20ec9ff2c6b9b0908d77306cc30d5d480fba8c21 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 11 Jan 2016 19:05:25 +0100 Subject: reworked that loop that iterates over various servers --- .../siacs/conversations/xmpp/XmppConnection.java | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'src/main/java/eu') diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index af3c7533..4bc44ce9 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -255,12 +255,10 @@ public class XmppConnection implements Runnable { throw new UnknownHostException(); } } else { - final Bundle result = DNSHelper.getSRVRecord(account.getServer(),mXmppConnectionService); + final Bundle result = DNSHelper.getSRVRecord(account.getServer(), mXmppConnectionService); final ArrayListvalues = result.getParcelableArrayList("values"); - int i = 0; - boolean socketError = true; - while (socketError && values.size() > i) { - final Bundle namePort = (Bundle) values.get(i); + for(Iterator iterator = values.iterator(); iterator.hasNext();) { + final Bundle namePort = (Bundle) iterator.next(); try { String srvRecordServer; try { @@ -285,22 +283,18 @@ public class XmppConnection implements Runnable { } socket = new Socket(); socket.connect(addr, Config.SOCKET_TIMEOUT * 1000); - socketError = false; + tagWriter.setOutputStream(socket.getOutputStream()); + tagReader.setInputStream(socket.getInputStream()); + tagWriter.beginDocument(); + sendStartStream(); } catch (final Throwable e) { Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage() +"("+e.getClass().getName()+")"); - i++; + if (!iterator.hasNext()) { + throw new UnknownHostException(); + } } } - if (socketError) { - throw new UnknownHostException(); - } } - final OutputStream out = socket.getOutputStream(); - tagWriter.setOutputStream(out); - final InputStream in = socket.getInputStream(); - tagReader.setInputStream(in); - tagWriter.beginDocument(); - sendStartStream(); Tag nextTag; while ((nextTag = tagReader.readTag()) != null) { if (nextTag.isStart("stream")) { -- cgit v1.2.3