Tightened up the DefaultServer connection close code

to make sure that the connection closed change event
only goes out once.
Added some additional logging to the endpoint closings.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7244 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
PSp..om 14 years ago
parent 189a787d36
commit 1f1c2ac15b
  1. 36
      engine/src/networking/com/jme3/network/base/DefaultServer.java
  2. 2
      engine/src/networking/com/jme3/network/kernel/tcp/SelectorKernel.java
  3. 2
      engine/src/networking/com/jme3/network/kernel/udp/UdpEndpoint.java
  4. 2
      engine/src/networking/com/jme3/network/kernel/udp/UdpKernel.java

@ -358,18 +358,8 @@ public class DefaultServer implements Server
if( removed != null ) { if( removed != null ) {
log.log( Level.INFO, "Client closed:{0}.", removed ); log.log( Level.INFO, "Client closed:{0}.", removed );
// Make sure both endpoints are closed. Note: reliable removed.closeConnection();
// should always already be closed through all paths that I
// can conceive... but it doesn't hurt to be sure.
if( removed.reliable != null && removed.reliable.isConnected() ) {
removed.reliable.close();
}
if( removed.fast != null && removed.fast.isConnected() ) {
removed.fast.close();
}
fireConnectionRemoved( removed );
} }
} }
@ -378,6 +368,7 @@ public class DefaultServer implements Server
private int id; private int id;
private Endpoint reliable; private Endpoint reliable;
private Endpoint fast; private Endpoint fast;
private boolean closed;
private Map<String,Object> sessionData = new ConcurrentHashMap<String,Object>(); private Map<String,Object> sessionData = new ConcurrentHashMap<String,Object>();
@ -410,6 +401,25 @@ public class DefaultServer implements Server
fast.send( buffer ); fast.send( buffer );
} }
} }
protected void closeConnection()
{
if( closed )
return;
closed = true;
// Make sure both endpoints are closed. Note: reliable
// should always already be closed through all paths that I
// can conceive... but it doesn't hurt to be sure.
if( reliable != null && reliable.isConnected() ) {
reliable.close();
}
if( fast != null && fast.isConnected() ) {
fast.close();
}
fireConnectionRemoved( this );
}
public void close( String reason ) public void close( String reason )
{ {
@ -422,6 +432,8 @@ public class DefaultServer implements Server
// Just close the reliable endpoint // Just close the reliable endpoint
// fast will be cleaned up as a side-effect // fast will be cleaned up as a side-effect
// when closeConnection() is called by the
// connectionClosed() endpoint callback.
if( reliable != null ) { if( reliable != null ) {
// Close with flush so we make sure our // Close with flush so we make sure our
// message gets out // message gets out

@ -181,6 +181,8 @@ public class SelectorKernel extends AbstractKernel
*/ */
protected void closeEndpoint( NioEndpoint p ) throws IOException protected void closeEndpoint( NioEndpoint p ) throws IOException
{ {
log.log( Level.INFO, "Closing endpoint:{0}.", p );
thread.cancel(p); thread.cancel(p);
} }

@ -49,7 +49,7 @@ import com.jme3.network.kernel.*;
*/ */
public class UdpEndpoint implements Endpoint public class UdpEndpoint implements Endpoint
{ {
private long id; private long id;
private SocketAddress address; private SocketAddress address;
private DatagramSocket socket; private DatagramSocket socket;
private UdpKernel kernel; private UdpKernel kernel;

@ -152,6 +152,8 @@ public class UdpKernel extends AbstractKernel
*/ */
protected void closeEndpoint( UdpEndpoint p ) throws IOException protected void closeEndpoint( UdpEndpoint p ) throws IOException
{ {
log.log( Level.INFO, "Closing endpoint:{0}.", p );
// Just book-keeping to do here. // Just book-keeping to do here.
socketEndpoints.remove( p.getRemoteAddress() ); socketEndpoints.remove( p.getRemoteAddress() );

Loading…
Cancel
Save