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. 34
      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/UdpKernel.java

@ -359,17 +359,7 @@ public class DefaultServer implements Server
log.log( Level.INFO, "Client closed:{0}.", removed );
// 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( removed.reliable != null && removed.reliable.isConnected() ) {
removed.reliable.close();
}
if( removed.fast != null && removed.fast.isConnected() ) {
removed.fast.close();
}
fireConnectionRemoved( removed );
removed.closeConnection();
}
}
@ -378,6 +368,7 @@ public class DefaultServer implements Server
private int id;
private Endpoint reliable;
private Endpoint fast;
private boolean closed;
private Map<String,Object> sessionData = new ConcurrentHashMap<String,Object>();
@ -411,6 +402,25 @@ public class DefaultServer implements Server
}
}
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 )
{
// Send a reason
@ -422,6 +432,8 @@ public class DefaultServer implements Server
// Just close the reliable endpoint
// fast will be cleaned up as a side-effect
// when closeConnection() is called by the
// connectionClosed() endpoint callback.
if( reliable != null ) {
// Close with flush so we make sure our
// message gets out

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

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

Loading…
Cancel
Save