diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-01-11 19:05:25 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-01-11 19:05:25 +0100 |
commit | 20ec9ff2c6b9b0908d77306cc30d5d480fba8c21 (patch) | |
tree | 97051025ed3aca3a5e55a3f365801b902ca79b91 | |
parent | a85bba0010e177782fa1dadaeefff29902904d43 (diff) |
reworked that loop that iterates over various servers
-rw-r--r-- | src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index af3c7533f..4bc44ce9c 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 ArrayList<Parcelable>values = result.getParcelableArrayList("values"); - int i = 0; - boolean socketError = true; - while (socketError && values.size() > i) { - final Bundle namePort = (Bundle) values.get(i); + for(Iterator<Parcelable> 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")) { |