reworked that loop that iterates over various servers

This commit is contained in:
Daniel Gultsch 2016-01-11 19:05:25 +01:00
parent a85bba0010
commit 20ec9ff2c6
1 changed files with 10 additions and 16 deletions

View File

@ -255,12 +255,10 @@ public class XmppConnection implements Runnable {
throw new UnknownHostException(); throw new UnknownHostException();
} }
} else { } else {
final Bundle result = DNSHelper.getSRVRecord(account.getServer(),mXmppConnectionService); final Bundle result = DNSHelper.getSRVRecord(account.getServer(), mXmppConnectionService);
final ArrayList<Parcelable>values = result.getParcelableArrayList("values"); final ArrayList<Parcelable>values = result.getParcelableArrayList("values");
int i = 0; for(Iterator<Parcelable> iterator = values.iterator(); iterator.hasNext();) {
boolean socketError = true; final Bundle namePort = (Bundle) iterator.next();
while (socketError && values.size() > i) {
final Bundle namePort = (Bundle) values.get(i);
try { try {
String srvRecordServer; String srvRecordServer;
try { try {
@ -285,22 +283,18 @@ public class XmppConnection implements Runnable {
} }
socket = new Socket(); socket = new Socket();
socket.connect(addr, Config.SOCKET_TIMEOUT * 1000); socket.connect(addr, Config.SOCKET_TIMEOUT * 1000);
socketError = false; tagWriter.setOutputStream(socket.getOutputStream());
tagReader.setInputStream(socket.getInputStream());
tagWriter.beginDocument();
sendStartStream();
} catch (final Throwable e) { } catch (final Throwable e) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage() +"("+e.getClass().getName()+")"); 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; Tag nextTag;
while ((nextTag = tagReader.readTag()) != null) { while ((nextTag = tagReader.readTag()) != null) {
if (nextTag.isStart("stream")) { if (nextTag.isStart("stream")) {