FileDocCategorySizeDatePackage
SinglePeerDownloader.javaAPI DocAzureus 3.0.3.44049Mon Jun 25 16:48:32 BST 2007com.aelitis.azureus.core.networkmanager.impl

SinglePeerDownloader

public class SinglePeerDownloader extends Object implements RateControlledEntity
A fast read entity backed by a single peer connection.

Fields Summary
private final NetworkConnectionBase
connection
private final RateHandler
rate_handler
Constructors Summary
public SinglePeerDownloader(NetworkConnectionBase connection, RateHandler rate_handler)

    this.connection = connection;
    this.rate_handler = rate_handler;
  
Methods Summary
public booleancanProcess(EventWaiter waiter)

    if( !connection.getTransportBase().isReadyForRead( waiter ) )  {
      return false;  //underlying transport not ready
    }
    if( rate_handler.getCurrentNumBytesAllowed() < 1 ) {
      return false;  //not allowed to receive any bytes
    }
    return true;
  
public booleandoProcessing(EventWaiter waiter)

    if( !connection.getTransportBase().isReadyForRead(waiter) )  {
      return false;
    }
    
    int num_bytes_allowed = rate_handler.getCurrentNumBytesAllowed();
    if( num_bytes_allowed < 1 )  {
      return false;
    }
    
    
    //int mss = NetworkManager.getTcpMssSize();   
    //if( num_bytes_allowed > mss )  num_bytes_allowed = mss;

    int bytes_read = 0;
    
    try {
      bytes_read = connection.getIncomingMessageQueue().receiveFromTransport( num_bytes_allowed );
    }
    catch( Throwable e ) {
      
      if( AEDiagnostics.TRACE_CONNECTION_DROPS ) {
        if( e.getMessage() == null ) {
          Debug.out( "null read exception message: ", e );
        }
        else {
          if( e.getMessage().indexOf( "end of stream on socket read" ) == -1 &&
              e.getMessage().indexOf( "An existing connection was forcibly closed by the remote host" ) == -1 &&
              e.getMessage().indexOf( "Connection reset by peer" ) == -1 &&
              e.getMessage().indexOf( "An established connection was aborted by the software in your host machine" ) == -1 ) {
            
            System.out.println( "SP: read exception [" +connection.getTransportBase().getDescription()+ "]: " +e.getMessage() );
          }
        }
      }
      
      if (! (e instanceof IOException )){
      	
    	  Debug.printStackTrace(e);
      }
      
      connection.notifyOfException( e );
      return false;
    }

    if( bytes_read < 1 )  {
      return false;
    }
    
    rate_handler.bytesProcessed( bytes_read );
    
    return true;
  
public longgetBytesReadyToWrite()

	  return( 0 );
  
public intgetConnectionCount()

	  return( 1 );
  
public intgetPriority()

    return RateControlledEntity.PRIORITY_NORMAL;
  
public intgetReadyConnectionCount(EventWaiter waiter)

	  if ( connection.getTransportBase().isReadyForRead( waiter)){
		  
		  return( 1 );
	  }
	  
	  return( 0 );
  
public java.lang.StringgetString()

	  return( "SPD: " + connection.getString());