From 5a1f449f0307e1eb245c66ec595190a1be86110e Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Mon, 27 Jan 2003 15:56:21 +0000 Subject: [PATCH] Cleaned up connection close operation. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1829 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/PacketReader.java | 6 +++--- source/org/jivesoftware/smack/PacketWriter.java | 7 +++++-- source/org/jivesoftware/smack/XMPPConnection.java | 5 +++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/source/org/jivesoftware/smack/PacketReader.java b/source/org/jivesoftware/smack/PacketReader.java index e4428fb90..dd3946a44 100644 --- a/source/org/jivesoftware/smack/PacketReader.java +++ b/source/org/jivesoftware/smack/PacketReader.java @@ -263,10 +263,10 @@ class PacketReader { } while (eventType != parser.END_DOCUMENT && !done); } catch (Exception e) { - // An exception occurred while parsing. Print the error an close the - // connection. - e.printStackTrace(); if (!done) { + // An exception occurred while parsing. Print the error an close the + // connection. + e.printStackTrace(); connection.close(); } } diff --git a/source/org/jivesoftware/smack/PacketWriter.java b/source/org/jivesoftware/smack/PacketWriter.java index 63e055607..5a8064a19 100644 --- a/source/org/jivesoftware/smack/PacketWriter.java +++ b/source/org/jivesoftware/smack/PacketWriter.java @@ -148,6 +148,7 @@ class PacketWriter { // stream.append("xmlns:sasl=\"http://www.iana.org/assignments/sasl-mechanisms\" "); writer.write(stream.toString()); writer.flush(); + stream = null; // Write out packets from the queue. while (!done) { Packet packet = nextPacket(); @@ -168,8 +169,10 @@ class PacketWriter { } } catch (IOException ioe){ - ioe.printStackTrace(); - connection.close(); + if (!done) { + ioe.printStackTrace(); + connection.close(); + } } } } diff --git a/source/org/jivesoftware/smack/XMPPConnection.java b/source/org/jivesoftware/smack/XMPPConnection.java index 28d4311eb..ed5adea85 100644 --- a/source/org/jivesoftware/smack/XMPPConnection.java +++ b/source/org/jivesoftware/smack/XMPPConnection.java @@ -323,6 +323,11 @@ public class XMPPConnection { packetWriter.sendPacket(new Presence(Presence.Type.UNAVAILABLE)); packetWriter.shutdown(); packetReader.shutdown(); + // Wait 100 ms for processes to clean-up, then shutdown. + try { + Thread.sleep(100); + } + catch (Exception e) { } try { socket.close(); }