1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-06-30 23:26:42 +02: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,14 +172,19 @@ 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) { }
} }
if (queue.size() > 0) {
return (Packet)queue.removeLast(); return (Packet)queue.removeLast();
} }
else {
return null;
}
}
} }
private void writePackets() { private void writePackets() {
@ -196,9 +201,11 @@ class PacketWriter {
// Write out packets from the queue. // Write out packets from the queue.
while (!done) { while (!done) {
Packet packet = nextPacket(); Packet packet = nextPacket();
if (packet != null) {
writer.write(packet.toXML()); writer.write(packet.toXML());
writer.flush(); writer.flush();
} }
}
// Close the stream. // Close the stream.
try { try {
writer.write("</stream:stream>"); writer.write("</stream:stream>");
@ -228,14 +235,20 @@ 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) { }
} }
if (sentPackets.size() > 0) {
sentPacket = (Packet)sentPackets.removeLast(); sentPacket = (Packet)sentPackets.removeLast();
} }
else {
sentPacket = null;
}
}
if (sentPacket != null) {
// Notify the listeners of the new sent packet // Notify the listeners of the new sent packet
int size = listeners.size(); int size = listeners.size();
for (int i=0; i<size; i++) { for (int i=0; i<size; i++) {
@ -246,6 +259,7 @@ class PacketWriter {
} }
} }
} }
}
/** /**
* A wrapper class to associate a packet filter with a listener. * A wrapper class to associate a packet filter with a listener.