mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 04:22:05 +01:00
Fixes a problem that didn't allow to terminate daemon threads
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2205 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
4f8f6b4c17
commit
4dfb2b08fa
1 changed files with 28 additions and 14 deletions
|
@ -172,13 +172,18 @@ class PacketWriter {
|
||||||
*/
|
*/
|
||||||
private Packet nextPacket() {
|
private Packet nextPacket() {
|
||||||
synchronized(queue) {
|
synchronized(queue) {
|
||||||
while (queue.size() == 0) {
|
while (!done && queue.size() == 0) {
|
||||||
try {
|
try {
|
||||||
queue.wait();
|
queue.wait(2000);
|
||||||
}
|
}
|
||||||
catch (InterruptedException ie) { }
|
catch (InterruptedException ie) { }
|
||||||
}
|
}
|
||||||
return (Packet)queue.removeLast();
|
if (queue.size() > 0) {
|
||||||
|
return (Packet)queue.removeLast();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,8 +201,10 @@ class PacketWriter {
|
||||||
// Write out packets from the queue.
|
// Write out packets from the queue.
|
||||||
while (!done) {
|
while (!done) {
|
||||||
Packet packet = nextPacket();
|
Packet packet = nextPacket();
|
||||||
writer.write(packet.toXML());
|
if (packet != null) {
|
||||||
writer.flush();
|
writer.write(packet.toXML());
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Close the stream.
|
// Close the stream.
|
||||||
try {
|
try {
|
||||||
|
@ -228,20 +235,27 @@ class PacketWriter {
|
||||||
Packet sentPacket;
|
Packet sentPacket;
|
||||||
// Wait until a new packet has been sent
|
// Wait until a new packet has been sent
|
||||||
synchronized(sentPackets) {
|
synchronized(sentPackets) {
|
||||||
while (sentPackets.size() == 0) {
|
while (!done && sentPackets.size() == 0) {
|
||||||
try {
|
try {
|
||||||
sentPackets.wait();
|
sentPackets.wait(2000);
|
||||||
}
|
}
|
||||||
catch (InterruptedException ie) { }
|
catch (InterruptedException ie) { }
|
||||||
}
|
}
|
||||||
sentPacket = (Packet)sentPackets.removeLast();
|
if (sentPackets.size() > 0) {
|
||||||
|
sentPacket = (Packet)sentPackets.removeLast();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sentPacket = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Notify the listeners of the new sent packet
|
if (sentPacket != null) {
|
||||||
int size = listeners.size();
|
// Notify the listeners of the new sent packet
|
||||||
for (int i=0; i<size; i++) {
|
int size = listeners.size();
|
||||||
ListenerWrapper listenerWrapper = (ListenerWrapper)listeners.get(i);
|
for (int i=0; i<size; i++) {
|
||||||
if (listenerWrapper != null) {
|
ListenerWrapper listenerWrapper = (ListenerWrapper)listeners.get(i);
|
||||||
listenerWrapper.notifyListener(sentPacket);
|
if (listenerWrapper != null) {
|
||||||
|
listenerWrapper.notifyListener(sentPacket);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue