1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-27 00:32:07 +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() {
synchronized(queue) {
while (queue.size() == 0) {
while (!done && queue.size() == 0) {
try {
queue.wait();
queue.wait(2000);
}
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.
while (!done) {
Packet packet = nextPacket();
writer.write(packet.toXML());
writer.flush();
if (packet != null) {
writer.write(packet.toXML());
writer.flush();
}
}
// Close the stream.
try {
@ -228,20 +235,27 @@ 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) { }
}
sentPacket = (Packet)sentPackets.removeLast();
if (sentPackets.size() > 0) {
sentPacket = (Packet)sentPackets.removeLast();
}
else {
sentPacket = null;
}
}
// Notify the listeners of the new sent packet
int size = listeners.size();
for (int i=0; i<size; i++) {
ListenerWrapper listenerWrapper = (ListenerWrapper)listeners.get(i);
if (listenerWrapper != null) {
listenerWrapper.notifyListener(sentPacket);
if (sentPacket != null) {
// Notify the listeners of the new sent packet
int size = listeners.size();
for (int i=0; i<size; i++) {
ListenerWrapper listenerWrapper = (ListenerWrapper)listeners.get(i);
if (listenerWrapper != null) {
listenerWrapper.notifyListener(sentPacket);
}
}
}
}