Commit a2d3ba78 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Set STATUS_CLOSED to session when closing socket. This prevents running...

Set STATUS_CLOSED to session when closing socket. This prevents running closing logic many times. JM-1042

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8106 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7e8ed285
...@@ -16,9 +16,6 @@ import org.apache.mina.common.IoSession; ...@@ -16,9 +16,6 @@ import org.apache.mina.common.IoSession;
import org.apache.mina.filter.CompressionFilter; import org.apache.mina.filter.CompressionFilter;
import org.apache.mina.filter.SSLFilter; import org.apache.mina.filter.SSLFilter;
import org.dom4j.io.OutputFormat; import org.dom4j.io.OutputFormat;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.XMLWriter;
import org.jivesoftware.openfire.Connection; import org.jivesoftware.openfire.Connection;
import org.jivesoftware.openfire.ConnectionCloseListener; import org.jivesoftware.openfire.ConnectionCloseListener;
import org.jivesoftware.openfire.PacketDeliverer; import org.jivesoftware.openfire.PacketDeliverer;
...@@ -28,6 +25,9 @@ import org.jivesoftware.openfire.net.SSLJiveKeyManagerFactory; ...@@ -28,6 +25,9 @@ import org.jivesoftware.openfire.net.SSLJiveKeyManagerFactory;
import org.jivesoftware.openfire.net.SSLJiveTrustManagerFactory; import org.jivesoftware.openfire.net.SSLJiveTrustManagerFactory;
import org.jivesoftware.openfire.net.ServerTrustManager; import org.jivesoftware.openfire.net.ServerTrustManager;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.XMLWriter;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManager;
...@@ -81,12 +81,20 @@ public class NIOConnection implements Connection { ...@@ -81,12 +81,20 @@ public class NIOConnection implements Connection {
*/ */
private CompressionPolicy compressionPolicy = CompressionPolicy.disabled; private CompressionPolicy compressionPolicy = CompressionPolicy.disabled;
private CharsetEncoder encoder; private CharsetEncoder encoder;
/**
* Flag that specifies if the connection should be considered closed. Closing a NIO connection
* is an asynch operation so instead of waiting for the connection to be actually closed just
* keep this flag to avoid using the connection between #close was used and the socket is actually
* closed.
*/
private boolean closed;
public NIOConnection(IoSession session, PacketDeliverer packetDeliverer) { public NIOConnection(IoSession session, PacketDeliverer packetDeliverer) {
this.ioSession = session; this.ioSession = session;
this.backupDeliverer = packetDeliverer; this.backupDeliverer = packetDeliverer;
encoder = Charset.forName(CHARSET).newEncoder(); encoder = Charset.forName(CHARSET).newEncoder();
closed = false;
} }
public boolean validate() { public boolean validate() {
...@@ -124,19 +132,23 @@ public class NIOConnection implements Connection { ...@@ -124,19 +132,23 @@ public class NIOConnection implements Connection {
} }
public void close() { public void close() {
boolean wasClosed = false; boolean closedSuccessfully = false;
synchronized (this) { synchronized (this) {
if (!isClosed()) { if (!isClosed()) {
if (session != null) {
session.setStatus(Session.STATUS_CLOSED);
}
try { try {
deliverRawText(flashClient ? "</flash:stream>" : "</stream:stream>", false); deliverRawText(flashClient ? "</flash:stream>" : "</stream:stream>", false);
} catch (Exception e) { } catch (Exception e) {
// Ignore // Ignore
} }
closeConnection(); ioSession.close();
wasClosed = true; closed = true;
closedSuccessfully = true;
} }
} }
if (wasClosed) { if (closedSuccessfully) {
notifyCloseListeners(); notifyCloseListeners();
} }
} }
...@@ -147,10 +159,6 @@ public class NIOConnection implements Connection { ...@@ -147,10 +159,6 @@ public class NIOConnection implements Connection {
close(); close();
} }
private void closeConnection() {
ioSession.close();
}
/** /**
* Notifies all close listeners that the connection has been closed. * Notifies all close listeners that the connection has been closed.
* Used by subclasses to properly finish closing the connection. * Used by subclasses to properly finish closing the connection.
...@@ -171,7 +179,7 @@ public class NIOConnection implements Connection { ...@@ -171,7 +179,7 @@ public class NIOConnection implements Connection {
public boolean isClosed() { public boolean isClosed() {
if (session == null) { if (session == null) {
return !ioSession.isConnected(); return closed;
} }
return session.getStatus() == Session.STATUS_CLOSED; return session.getStatus() == Session.STATUS_CLOSED;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment