mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-23 14:52:06 +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:
parent
aaf6cf0ca9
commit
31b508cc9f
1 changed files with 70 additions and 19 deletions
|
@ -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.
|
||||||
|
|
Loading…
Reference in a new issue