1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 16:22:06 +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,14 +172,19 @@ class PacketWriter {
*/
private Packet nextPacket() {
synchronized(queue) {
while (queue.size() == 0) {
while (!done && queue.size() == 0) {
try {
queue.wait();
queue.wait(2000);
}
catch (InterruptedException ie) { }
}
if (queue.size() > 0) {
return (Packet)queue.removeLast();
}
else {
return null;
}
}
}
private void writePackets() {
@ -196,9 +201,11 @@ class PacketWriter {
// Write out packets from the queue.
while (!done) {
Packet packet = nextPacket();
if (packet != null) {
writer.write(packet.toXML());
writer.flush();
}
}
// Close the stream.
try {
writer.write("</stream:stream>");
@ -228,14 +235,20 @@ class PacketWriter {
Packet sentPacket;
// Wait until a new packet has been sent
synchronized(sentPackets) {
while (sentPackets.size() == 0) {
while (!done && sentPackets.size() == 0) {
try {
sentPackets.wait();
sentPackets.wait(2000);
}
catch (InterruptedException ie) { }
}
if (sentPackets.size() > 0) {
sentPacket = (Packet)sentPackets.removeLast();
}
else {
sentPacket = null;
}
}
if (sentPacket != null) {
// Notify the listeners of the new sent packet
int size = listeners.size();
for (int i=0; i<size; i++) {
@ -246,6 +259,7 @@ class PacketWriter {
}
}
}
}
/**
* A wrapper class to associate a packet filter with a listener.