1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-15 16:52:07 +01:00

Fix connection closing notifications on error.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2050 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2003-08-20 16:29:46 +00:00 committed by mtucker
parent 3c3b3d5cdf
commit 334cfd8c3a

View file

@ -200,14 +200,16 @@ class PacketReader {
* Shuts the packet reader down. * Shuts the packet reader down.
*/ */
public void shutdown() { public void shutdown() {
done = true; // Notify connection listeners of the connection closing if done hasn't already been set.
// Notify connection listeners of the connection closing. if (!done) {
synchronized (connectionListeners) { synchronized (connectionListeners) {
for (Iterator i=connectionListeners.iterator(); i.hasNext(); ) { for (Iterator i=connectionListeners.iterator(); i.hasNext(); ) {
ConnectionListener listener = (ConnectionListener)i.next(); ConnectionListener listener = (ConnectionListener)i.next();
listener.connectionClosed(); listener.connectionClosed();
}
} }
} }
done = true;
} }
/** /**
@ -287,15 +289,18 @@ 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.
done = true;
connection.close();
// An exception occurred while parsing. Notify connection listeners of // An exception occurred while parsing. Notify connection listeners of
// the error and close the connection. // the error and close the connection.
connection.close();
synchronized (connectionListeners) { synchronized (connectionListeners) {
for (Iterator i=connectionListeners.iterator(); i.hasNext(); ) { for (Iterator i=connectionListeners.iterator(); i.hasNext(); ) {
ConnectionListener listener = (ConnectionListener)i.next(); ConnectionListener listener = (ConnectionListener)i.next();
listener.connectionClosedOnError(e); listener.connectionClosedOnError(e);
} }
} }
} }
} }
} }