- try { socket.close(); }\r
- catch (IOException e) {}\r
- \r
- //logger.info("CLIENT: closing connection to port " + socket.getPort());\r
- manager.removeEndPoint(this);\r
+ SocketManager mgr=manager;\r
+ manager=null; // stops receive thread\r
+ if (socket!=null) {\r
+ try { socket.close(); }\r
+ catch (IOException e) {}\r
+ socket=null;\r
+ }\r
+ //logger.info("CLIENT: closing connection to port " + socket.getPort());\r
+ // terminate() can be called by the socket manager to shutdown the connection,\r
+ // or the receive thread after an exception has been received\r
+ // (which includes the above case when the socket is closed.\r
+ // so we only want to removeEndPoint once - for the initial call to terminate()\r
+ if (mgr!=null)\r
+ mgr.removeEndPoint(this);\r