mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-26 20:47:58 +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:
parent
89fa351758
commit
d843cc9a77
3 changed files with 28 additions and 18 deletions
|
@ -212,6 +212,24 @@ class PacketReader {
|
|||
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.
|
||||
*/
|
||||
|
@ -238,7 +256,8 @@ class PacketReader {
|
|||
if (!processedPacket) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ie) { }
|
||||
}
|
||||
catch (InterruptedException ie) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -289,18 +308,9 @@ class PacketReader {
|
|||
}
|
||||
catch (Exception e) {
|
||||
if (!done) {
|
||||
// Set done to true since we want to do our own notification of connection closing.
|
||||
done = true;
|
||||
connection.close();
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// Close the connection and notify connection listeners of the
|
||||
// error.
|
||||
notifyConnectionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
package org.jivesoftware.smack;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Iterator;
|
||||
import java.io.*;
|
||||
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
|
@ -145,7 +146,6 @@ class PacketWriter {
|
|||
stream.append(" to=\"" + connection.getHost() + "\"");
|
||||
stream.append(" xmlns=\"jabber:client\"");
|
||||
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.flush();
|
||||
stream = null;
|
||||
|
@ -170,8 +170,8 @@ class PacketWriter {
|
|||
}
|
||||
catch (IOException ioe){
|
||||
if (!done) {
|
||||
ioe.printStackTrace();
|
||||
connection.close();
|
||||
done = true;
|
||||
connection.packetReader.notifyConnectionError(ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,8 +117,8 @@ public class XMPPConnection {
|
|||
private boolean authenticated = false;
|
||||
private boolean anonymous = false;
|
||||
|
||||
private PacketWriter packetWriter;
|
||||
private PacketReader packetReader;
|
||||
PacketWriter packetWriter;
|
||||
PacketReader packetReader;
|
||||
|
||||
Roster roster = null;
|
||||
private AccountManager accountManager = null;
|
||||
|
|
Loading…
Reference in a new issue