1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 14:02:06 +01:00

Packet writer errors will now notify listeners of errors (SMACK-85)

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2092 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2003-09-18 22:35:42 +00:00 committed by mtucker
parent 89fa351758
commit d843cc9a77
3 changed files with 28 additions and 18 deletions

View file

@ -212,6 +212,24 @@ class PacketReader {
done = true; done = true;
} }
/**
* Sends out a notification that there was an error with the connection
* and closes the connection.
*
* @param e the exception that causes the connection close event.
*/
void notifyConnectionError(Exception e) {
done = true;
connection.close();
// Notify connection listeners of the error.
synchronized (connectionListeners) {
for (Iterator i=connectionListeners.iterator(); i.hasNext(); ) {
ConnectionListener listener = (ConnectionListener)i.next();
listener.connectionClosedOnError(e);
}
}
}
/** /**
* Process listeners. * Process listeners.
*/ */
@ -238,7 +256,8 @@ class PacketReader {
if (!processedPacket) { if (!processedPacket) {
try { try {
Thread.sleep(100); Thread.sleep(100);
} catch (InterruptedException ie) { } }
catch (InterruptedException ie) { }
} }
} }
} }
@ -289,18 +308,9 @@ class PacketReader {
} }
catch (Exception e) { catch (Exception e) {
if (!done) { if (!done) {
// Set done to true since we want to do our own notification of connection closing. // Close the connection and notify connection listeners of the
done = true; // error.
connection.close(); notifyConnectionError(e);
// An exception occurred while parsing. Notify connection listeners of
// the error and close the connection.
synchronized (connectionListeners) {
for (Iterator i=connectionListeners.iterator(); i.hasNext(); ) {
ConnectionListener listener = (ConnectionListener)i.next();
listener.connectionClosedOnError(e);
}
}
} }
} }
} }

View file

@ -53,6 +53,7 @@
package org.jivesoftware.smack; package org.jivesoftware.smack;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Iterator;
import java.io.*; import java.io.*;
import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Packet;
@ -145,7 +146,6 @@ class PacketWriter {
stream.append(" to=\"" + connection.getHost() + "\""); stream.append(" to=\"" + connection.getHost() + "\"");
stream.append(" xmlns=\"jabber:client\""); stream.append(" xmlns=\"jabber:client\"");
stream.append(" xmlns:stream=\"http://etherx.jabber.org/streams\">"); stream.append(" xmlns:stream=\"http://etherx.jabber.org/streams\">");
// stream.append("xmlns:sasl=\"http://www.iana.org/assignments/sasl-mechanisms\" ");
writer.write(stream.toString()); writer.write(stream.toString());
writer.flush(); writer.flush();
stream = null; stream = null;
@ -170,8 +170,8 @@ class PacketWriter {
} }
catch (IOException ioe){ catch (IOException ioe){
if (!done) { if (!done) {
ioe.printStackTrace(); done = true;
connection.close(); connection.packetReader.notifyConnectionError(ioe);
} }
} }
} }

View file

@ -117,8 +117,8 @@ public class XMPPConnection {
private boolean authenticated = false; private boolean authenticated = false;
private boolean anonymous = false; private boolean anonymous = false;
private PacketWriter packetWriter; PacketWriter packetWriter;
private PacketReader packetReader; PacketReader packetReader;
Roster roster = null; Roster roster = null;
private AccountManager accountManager = null; private AccountManager accountManager = null;