1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-23 06:42: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:
Gaston Dombiak 2004-01-13 18:13:23 +00:00 committed by gdombiak
parent 4f8f6b4c17
commit 4dfb2b08fa

View file

@ -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);
}
} }
} }
} }