1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 22:12: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,6 +774,8 @@ public class XMPPConnection {
} }
} }
try
{
packetWriter = new PacketWriter(this); packetWriter = new PacketWriter(this);
packetReader = new PacketReader(this); packetReader = new PacketReader(this);
@ -784,6 +799,42 @@ public class XMPPConnection {
// 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.
}
}
/** /**
* Fires listeners on connection established events. * Fires listeners on connection established events.