1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

SMACK-417 If both PacketReader and PacketWriter fail at the same time, connectionClosedonError() is called two times

Refactored notifyConnectionError() and notifyReconnection() from PacketReader to XMPPConnection. Made PacketReader.done and PacketWriter.done volatile. Prevent duplicate connectionClosedonError() calls by making the method synchronzied and protected them with an enter guard: if (packetReader.done && packetWriter.done) return;

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_3_0@13568 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Florian Schmaus 2013-03-18 19:58:48 +00:00 committed by flow
parent 6dcf8e0123
commit a55b54f20b
5 changed files with 65 additions and 61 deletions

View file

@ -48,7 +48,7 @@ class PacketReader {
private XMPPConnection connection;
private XmlPullParser parser;
private boolean done;
volatile boolean done;
private String connectionID = null;
private Semaphore connectionSemaphore;
@ -155,48 +155,6 @@ class PacketReader {
connection.collectors.clear();
}
/**
* 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;
// Closes the connection temporary. A reconnection is possible
connection.shutdown(new Presence(Presence.Type.unavailable));
// Print the stack trace to help catch the problem
e.printStackTrace();
// Notify connection listeners of the error.
for (ConnectionListener listener : connection.getConnectionListeners()) {
try {
listener.connectionClosedOnError(e);
}
catch (Exception e2) {
// Catch and print any exception so we can recover
// from a faulty listener
e2.printStackTrace();
}
}
}
/**
* Sends a notification indicating that the connection was reconnected successfully.
*/
protected void notifyReconnection() {
// Notify connection listeners of the reconnection.
for (ConnectionListener listener : connection.getConnectionListeners()) {
try {
listener.reconnectionSuccessful();
}
catch (Exception e) {
// Catch and print any exception so we can recover
// from a faulty listener
e.printStackTrace();
}
}
}
/**
* Resets the parser using the latest connection's reader. Reseting the parser is necessary
* when the plain connection has been secured or when a new opening stream element is going
@ -332,7 +290,7 @@ class PacketReader {
if (!(done || connection.isSocketClosed())) {
// Close the connection and notify connection listeners of the
// error.
notifyConnectionError(e);
connection.notifyConnectionError(e);
}
}
}