mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 09:39:39 +02: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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue