1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-23 06:42:05 +01:00

1. Closes reader and writer when the connection is closed. SMACK-156

2. Closes reader and writer and shuts down PacketReader and PacketWriter if an exception occurs while initializing the connection. SMACK-156


git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2385 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2004-09-24 02:15:55 +00:00 committed by gdombiak
parent aaf6cf0ca9
commit 31b508cc9f

View file

@ -562,6 +562,19 @@ public class XMPPConnection {
} }
catch (Exception e) { catch (Exception e) {
} }
// Close down the readers and writers.
if (reader != null)
{
try { reader.close(); } catch (Throwable ignore) { }
reader = null;
}
if (writer != null)
{
try { writer.close(); } catch (Throwable ignore) { }
writer = null;
}
try { try {
socket.close(); socket.close();
} }
@ -761,28 +774,66 @@ public class XMPPConnection {
} }
} }
packetWriter = new PacketWriter(this); try
packetReader = new PacketReader(this); {
packetWriter = new PacketWriter(this);
packetReader = new PacketReader(this);
// If debugging is enabled, we should start the thread that will listen for // If debugging is enabled, we should start the thread that will listen for
// all packets and then log them. // all packets and then log them.
if (DEBUG_ENABLED) { if (DEBUG_ENABLED) {
packetReader.addPacketListener(debugger.getReaderListener(), null); packetReader.addPacketListener(debugger.getReaderListener(), null);
if (debugger.getWriterListener() != null) { if (debugger.getWriterListener() != null) {
packetWriter.addPacketListener(debugger.getWriterListener(), null); packetWriter.addPacketListener(debugger.getWriterListener(), null);
}
} }
} // Start the packet writer. This will open a XMPP stream to the server
// Start the packet writer. This will open a XMPP stream to the server packetWriter.startup();
packetWriter.startup(); // Start the packet reader. The startup() method will block until we
// Start the packet reader. The startup() method will block until we // get an opening stream packet back from server.
// get an opening stream packet back from server. packetReader.startup();
packetReader.startup();
// Make note of the fact that we're now connected. // Make note of the fact that we're now connected.
connected = true; connected = true;
// Notify that a new connection has been established // Notify that a new connection has been established
connectionEstablished(this); connectionEstablished(this);
}
catch (XMPPException ex)
{
// An exception occurred in setting up the connection. Make sure we shut down the
// readers and writers and close the socket.
if (packetWriter != null)
{
try { packetWriter.shutdown(); } catch (Throwable ignore) { }
packetWriter = null;
}
if (packetReader != null)
{
try { packetReader.shutdown(); } catch (Throwable ignore) { }
packetReader = null;
}
if (reader != null)
{
try { reader.close(); } catch (Throwable ignore) { }
reader = null;
}
if (writer != null)
{
try { writer.close(); } catch (Throwable ignore) { }
writer = null;
}
if (socket != null)
{
try { socket.close(); } catch (Exception e) { }
socket = null;
}
authenticated = false;
connected = false;
throw ex; // Everything stoppped. Now throw the exception.
}
} }
/** /**