mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-22 04:27:58 +01:00
Merge branch '4.3'
This commit is contained in:
commit
d10319f1a0
2 changed files with 42 additions and 11 deletions
|
@ -1516,7 +1516,29 @@ public final class Roster extends Manager {
|
|||
final Presence presence = (Presence) packet;
|
||||
final Jid from = presence.getFrom();
|
||||
|
||||
final BareJid key = from != null ? from.asBareJid() : null;
|
||||
final BareJid key;
|
||||
if (from != null) {
|
||||
key = from.asBareJid();
|
||||
} else {
|
||||
XMPPConnection connection = connection();
|
||||
if (connection == null) {
|
||||
LOGGER.finest("Connection was null while trying to handle exotic presence stanza: " + presence);
|
||||
return;
|
||||
}
|
||||
// Assume the presence come "from the users account on the server" since no from was set (RFC 6120 §
|
||||
// 8.1.2.1 4.). Note that getUser() may return null, but should never return null in this case as where
|
||||
// connected.
|
||||
EntityFullJid myJid = connection.getUser();
|
||||
if (myJid == null) {
|
||||
LOGGER.info(
|
||||
"Connection had no local address in Roster's presence listener."
|
||||
+ " Possibly we received a presence without from before being authenticated."
|
||||
+ " Presence: " + presence);
|
||||
return;
|
||||
}
|
||||
LOGGER.info("Exotic presence stanza without from received: " + presence);
|
||||
key = myJid.asBareJid();
|
||||
}
|
||||
|
||||
asyncButOrdered.performAsyncButOrdered(key, new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -482,10 +482,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
}
|
||||
|
||||
private void shutdown(boolean instant) {
|
||||
if (disconnectedButResumeable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// First shutdown the writer, this will result in a closing stream element getting send to
|
||||
// the server
|
||||
LOGGER.finer("PacketWriter shutdown()");
|
||||
|
@ -503,6 +499,15 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
CloseableUtil.maybeClose(socket, LOGGER);
|
||||
|
||||
setWasAuthenticated();
|
||||
|
||||
// Wait for reader and writer threads to be terminated.
|
||||
readerWriterSemaphore.acquireUninterruptibly(2);
|
||||
readerWriterSemaphore.release(2);
|
||||
|
||||
if (disconnectedButResumeable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are able to resume the stream, then don't set
|
||||
// connected/authenticated/usingTLS to false since we like behave like we are still
|
||||
// connected (e.g. sendStanza should not throw a NotConnectedException).
|
||||
|
@ -523,10 +528,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
writer = null;
|
||||
|
||||
initState();
|
||||
|
||||
// Wait for reader and writer threads to be terminated.
|
||||
readerWriterSemaphore.acquireUninterruptibly(2);
|
||||
readerWriterSemaphore.release(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -860,6 +861,8 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
|
||||
protected class PacketReader {
|
||||
|
||||
private final String threadName = "Smack Reader (" + getConnectionCounter() + ')';
|
||||
|
||||
XmlPullParser parser;
|
||||
|
||||
private volatile boolean done;
|
||||
|
@ -874,13 +877,15 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
Async.go(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LOGGER.finer(threadName + " start");
|
||||
try {
|
||||
parsePackets();
|
||||
} finally {
|
||||
LOGGER.finer(threadName + " exit");
|
||||
XMPPTCPConnection.this.readerWriterSemaphore.release();
|
||||
}
|
||||
}
|
||||
}, "Smack Reader (" + getConnectionCounter() + ")");
|
||||
}, threadName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1128,6 +1133,8 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
protected class PacketWriter {
|
||||
public static final int QUEUE_SIZE = XMPPTCPConnection.QUEUE_SIZE;
|
||||
|
||||
private final String threadName = "Smack Writer (" + getConnectionCounter() + ')';
|
||||
|
||||
private final ArrayBlockingQueueWithShutdown<Element> queue = new ArrayBlockingQueueWithShutdown<>(
|
||||
QUEUE_SIZE, true);
|
||||
|
||||
|
@ -1173,13 +1180,15 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
Async.go(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LOGGER.finer(threadName + " start");
|
||||
try {
|
||||
writePackets();
|
||||
} finally {
|
||||
LOGGER.finer(threadName + " exit");
|
||||
XMPPTCPConnection.this.readerWriterSemaphore.release();
|
||||
}
|
||||
}
|
||||
}, "Smack Writer (" + getConnectionCounter() + ")");
|
||||
}, threadName);
|
||||
}
|
||||
|
||||
private boolean done() {
|
||||
|
|
Loading…
Reference in a new issue