common/src/main/java/HTTPClient/StreamDemultiplexor.java
/**
     * Close the socket if all the streams have been closed.
     *
     * <P>When a stream reaches eof it is removed from the response handler
     * list, but when somebody close()'s the response stream it is just
     * marked as such. This means that all responses in the list have either
     * not been read at all or only partially read, but they might have been
     * close()'d meaning that nobody is interested in the data. So If all the
     * response streams up till and including the one markedForClose have
     * been close()'d then we can remove them from our list and close the
     * socket.
     *
     * <P>Note: if the response list is emtpy or if no response is
     * markedForClose then this method does nothing. Specifically it does
     * not close the socket. We only want to close the socket if we've been
     * told to do so.
     *
     * <P>Also note that there might still be responses in the list after
     * the markedForClose one. These are due to us having pipelined more
     * requests to the server than it's willing to serve on a single
     * connection. These requests will be retried if possible.
     */
Close the socket if all the streams have been closed.
When a stream reaches eof it is removed from the response handler
list, but when somebody close()'s the response stream it is just
marked as such. This means that all responses in the list have either
not been read at all or only partially read, but they might have been
close()'d meaning that nobody is interested in the data. So If all the
response streams up till and including the one markedForClose have
been close()'d then we can remove them from our list and close the
socket.

Note: if the response list is emtpy or if no response is
markedForClose then this method does nothing. Specifically it does
not close the socket. We only want to close the socket if we've been
told to do so.

Also note that there might still be responses in the list after
the markedForClose one. These are due to us having pipelined more
requests to the server than it's willing to serve on a single
connection. These requests will be retried if possible.
Close the socket if all the streams have been closed . When a stream reaches eof it is removed from the response handler list but when somebody close () ' s the response stream it is just marked as such . This means that all responses in the list have either not been read at all or only partially read but they might have been close () ' d meaning that nobody is interested in the data . So If all the response streams up till and including the one markedForClose have been close () ' d then we can remove them from our list and close the socket . Note : if the response list is emtpy or if no response is markedForClose then this method does nothing . Specifically it does not close the socket . We only want to close the socket if we ' ve been told to do so . Also note that there might still be responses in the list after the markedForClose one . These are due to us having pipelined more requests to the server than it ' s willing to serve on a single connection . These requests will be retried if possible .
synchronized void closeSocketIfAllStreamsClosed()
    {
	synchronized (RespHandlerList)
	{
	    ResponseHandler resph = (ResponseHandler) RespHandlerList.enumerate();
	    while (resph != null  &&  resph.stream.closed)
	    {
		if (resph == MarkedForClose)
		{
		    ResponseHandler tmp;
		    do
		    {
			tmp = (ResponseHandler) RespHandlerList.getFirst();
			RespHandlerList.remove(tmp);
		    }
		    while (tmp != resph);
		    close(new IOException("Premature end of Keep-Alive"), false);
		    return;
		}
		resph = (ResponseHandler) RespHandlerList.next();
	    }
	}
    }
synchronized void closeSocketIfAllStreamsClosed ( ) { synchronized ( RespHandlerList ) { ResponseHandler resph = ( ResponseHandler ) RespHandlerList . enumerate ( ) ; while ( resph != null && resph . stream . closed ) { if ( resph == MarkedForClose ) { ResponseHandler tmp ; do { tmp = ( ResponseHandler ) RespHandlerList . getFirst ( ) ; RespHandlerList . remove ( tmp ) ; } while ( tmp != resph ) ; close ( new IOException ( "Premature end of Keep-Alive" ) , false ) ; return ; } resph = ( ResponseHandler ) RespHandlerList . next ( ) ; } } }
Close the socket if all the streams have been closed.
Close the socket if all the streams have been closed .
// remove all response handlers first // close the socket