1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-15 20:12:04 +01:00

Drop stream state after stream error

Fixes SMACK-696.
This commit is contained in:
Florian Schmaus 2015-08-26 18:47:05 +02:00
parent b1e4884fbb
commit 8aa3f94c90

View file

@ -16,6 +16,7 @@
*/ */
package org.jivesoftware.smack.tcp; package org.jivesoftware.smack.tcp;
import org.jivesoftware.smack.AbstractConnectionListener;
import org.jivesoftware.smack.AbstractXMPPConnection; import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode; import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
@ -295,6 +296,14 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
public XMPPTCPConnection(XMPPTCPConnectionConfiguration config) { public XMPPTCPConnection(XMPPTCPConnectionConfiguration config) {
super(config); super(config);
this.config = config; this.config = config;
addConnectionListener(new AbstractConnectionListener() {
@Override
public void connectionClosedOnError(Exception e) {
if (e instanceof XMPPException.StreamErrorException) {
dropSmState();
}
}
});
} }
/** /**
@ -402,7 +411,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
// connection instance though). This is used in writePackets to decide if stanzas should // connection instance though). This is used in writePackets to decide if stanzas should
// be added to the unacknowledged stanzas queue, because they have to be added right // be added to the unacknowledged stanzas queue, because they have to be added right
// after the 'enable' stream element has been sent. // after the 'enable' stream element has been sent.
unacknowledgedStanzas = null; dropSmState();
} }
if (isSmAvailable() && useSm) { if (isSmAvailable() && useSm) {
// Remove what is maybe left from previously stream managed sessions // Remove what is maybe left from previously stream managed sessions
@ -1707,6 +1716,17 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
} }
} }
/**
* Drop the stream management state. Sets {@link #smSessionId} and
* {@link #unacknowledgedStanzas} to <code>null</code>.
*/
private void dropSmState() {
// clientHandledCount and serverHandledCount will be reset on <enable/> and <enabled/>
// respective. No need to reset them here.
smSessionId = null;
unacknowledgedStanzas = null;
}
/** /**
* Get the maximum resumption time in seconds after which a managed stream can be resumed. * Get the maximum resumption time in seconds after which a managed stream can be resumed.
* <p> * <p>