public void close(boolean removeSocket, boolean stopKeepAliveTask) {  
        isRunning = false;
    	// we need to close everything because the socket may be closed by the other end
    	// like in LB scenarios sending OPTIONS and killing the socket after it gets the response    	
        if (mySock != null) {
        	if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                logger.logDebug("Closing socket " + key);
        	try {
	            mySock.close();
	            mySock = null;
        	} catch (IOException ex) {
                if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                    logger.logDebug("Error closing socket " + ex);
            }
        }        
        if(myParser != null) {
        	if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                logger.logDebug("Closing my parser " + myParser);
            myParser.close();            
        }  
        // no need to close myClientInputStream since myParser.close() above will do it
        if(myClientOutputStream != null) {
        	if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                logger.logDebug("Closing client output stream " + myClientOutputStream);
        	try {
        		myClientOutputStream.close();
        	} catch (IOException ex) {
                if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                    logger.logDebug("Error closing client output stream" + ex);
            }
        }   
        if(removeSocket) {                  
	        // remove the "tcp:" part of the key to cleanup the ioHandler hashmap
	        String ioHandlerKey = key.substring(4);
	        if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
	            logger.logDebug("Closing TCP socket " + ioHandlerKey);
	        // Issue 358 : remove socket and semaphore on close to avoid leaking
	        sipStack.ioHandler.removeSocket(ioHandlerKey);
	        if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
                logger.logDebug("Closing message Channel (key = " + key +")" + this);
            }
        } else {
            if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
                String ioHandlerKey = key.substring(4);
                logger.logDebug("not removing socket key from the cached map since it has already been updated by the iohandler.sendBytes " + ioHandlerKey);
            }
        }
        if(stopKeepAliveTask) {
			cancelPingKeepAliveTimeoutTaskIfStarted();
		}
    }
public void close(boolean removeSocket, boolean stopKeepAliveTask) {  
        isRunning = false;
    
    
        if (mySock != null) {
        	if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                logger.logDebug("Closing socket " + key);
        	try {
	            mySock.close();
	            mySock = null;
        	} catch (IOException ex) {
                if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                    logger.logDebug("Error closing socket " + ex);
            }
        }        
        if(myParser != null) {
        	if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                logger.logDebug("Closing my parser " + myParser);
            myParser.close();            
        }  
       
        if(myClientOutputStream != null) {
        	if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                logger.logDebug("Closing client output stream " + myClientOutputStream);
        	try {
        		myClientOutputStream.close();
        	} catch (IOException ex) {
                if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                    logger.logDebug("Error closing client output stream" + ex);
            }
        }   
        if(removeSocket) {                  
	       
	        String ioHandlerKey = key.substring(4);
	        if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
	            logger.logDebug("Closing TCP socket " + ioHandlerKey);
	       
	        sipStack.ioHandler.removeSocket(ioHandlerKey);
	        if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
                logger.logDebug("Closing message Channel (key = " + key +")" + this);
            }
        } else {
            if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
                String ioHandlerKey = key.substring(4);
                logger.logDebug("not removing socket key from the cached map since it has already been updated by the iohandler.sendBytes " + ioHandlerKey);
            }
        }
        if(stopKeepAliveTask) {
			cancelPingKeepAliveTimeoutTaskIfStarted();
		}
    }
public void close(boolean removesocket, boolean stopkeepalivetask) { isrunning = false; if (mysock != null) { if (logger.isloggingenabled(logwriter.trace_debug)) logger.logdebug("closing socket " + key); try { mysock.close(); mysock = null; } catch (ioexception ex) { if (logger.isloggingenabled(logwriter.trace_debug)) logger.logdebug("error closing socket " + ex); } } if(myparser != null) { if (logger.isloggingenabled(logwriter.trace_debug)) logger.logdebug("closing my parser " + myparser); myparser.close(); } if(myclientoutputstream != null) { if (logger.isloggingenabled(logwriter.trace_debug)) logger.logdebug("closing client output stream " + myclientoutputstream); try { myclientoutputstream.close(); } catch (ioexception ex) { if (logger.isloggingenabled(logwriter.trace_debug)) logger.logdebug("error closing client output stream" + ex); } } if(removesocket) { string iohandlerkey = key.substring(4); if (logger.isloggingenabled(logwriter.trace_debug)) logger.logdebug("closing tcp socket " + iohandlerkey); sipstack.iohandler.removesocket(iohandlerkey); if (logger.isloggingenabled(logwriter.trace_debug)) { logger.logdebug("closing message channel (key = " + key +")" + this); } } else { if (logger.isloggingenabled(logwriter.trace_debug)) { string iohandlerkey = key.substring(4); logger.logdebug("not removing socket key from the cached map since it has already been updated by the iohandler.sendbytes " + iohandlerkey); } } if(stopkeepalivetask) { cancelpingkeepalivetimeouttaskifstarted(); } }