Methods Summary |
---|
public void | connectedInbound()
registerSelectHandling();
|
public void | connectedOutbound()
registerSelectHandling();
|
public java.lang.String | getEncryption()
return( filter==null?"":filter.getName());
|
protected TransportHelperFilter | getFilter()
return( filter );
|
public boolean | isEncrypted()
return( filter==null?false:filter.isEncrypted());
|
public boolean | isReadyForRead(com.aelitis.azureus.core.networkmanager.EventWaiter waiter)Is the transport ready to read,
i.e. will a read request result in >0 bytes read.
if ( waiter != null ){
read_waiter = waiter;
}
return is_ready_for_read || data_already_read != null || ( filter != null && filter.hasBufferedRead());
|
public boolean | isReadyForWrite(com.aelitis.azureus.core.networkmanager.EventWaiter waiter)Is the transport ready to write,
i.e. will a write request result in >0 bytes written.
if ( waiter != null ){
write_waiter = waiter;
}
return is_ready_for_write;
|
public long | read(java.nio.ByteBuffer[] buffers, int array_offset, int length)Read data from the transport into the given buffers.
NOTE: Works like ScatteringByteChannel.
if( read_select_failure != null ) {
throw new IOException( "read_select_failure: " + read_select_failure.getMessage() );
}
//insert already-read data into the front of the stream
if ( data_already_read != null ) {
int inserted = 0;
for( int i = array_offset; i < (array_offset + length); i++ ) {
ByteBuffer bb = buffers[ i ];
int orig_limit = data_already_read.limit();
if( data_already_read.remaining() > bb.remaining() ) {
data_already_read.limit( data_already_read.position() + bb.remaining() );
}
inserted += data_already_read.remaining();
bb.put( data_already_read );
data_already_read.limit( orig_limit );
if( !data_already_read.hasRemaining() ) {
data_already_read = null;
break;
}
}
if( !buffers[ array_offset + length - 1 ].hasRemaining() ) { //the last buffer has nothing left to read into normally
return inserted; //so return right away, skipping socket read
}
}
if ( filter == null ){
throw( new IOException( "Transport not ready" ));
}
long bytes_read = filter.read( buffers, array_offset, length );
if( stats != null ) stats.bytesRead( (int)bytes_read ); //TODO
if( bytes_read == 0 ){
requestReadSelect();
}
return bytes_read;
|
protected void | readFailed(java.lang.Throwable msg)
msg.fillInStackTrace(); // msg picked up on another thread - make sure trace is available
read_select_failure = msg;
is_ready_for_read = true; //set to true so that the next read attempt will throw an exception
|
protected boolean | readyForRead(boolean ready)
if ( ready ){
boolean progress = !is_ready_for_read;
is_ready_for_read = true;
EventWaiter rw = read_waiter;
if ( rw != null ){
rw.eventOccurred();
}
return progress;
}else{
is_ready_for_read = false;
return( false );
}
|
protected boolean | readyForWrite(boolean ready)
if ( trace ){
TimeFormatter.milliTrace( "trans: readyForWrite -> " + ready );
}
if ( ready ){
boolean progress = !is_ready_for_write;
is_ready_for_write = true;
EventWaiter ww = write_waiter;
if ( ww != null ){
ww.eventOccurred();
}
return progress;
}else{
is_ready_for_write = false;
return( false );
}
|
private void | registerSelectHandling()
TransportHelperFilter filter = getFilter();
if( filter == null ) {
Debug.out( "ERROR: registerSelectHandling():: filter == null" );
return;
}
TransportHelper helper = filter.getHelper();
//read selection
helper.registerForReadSelects(
new TransportHelper.selectListener()
{
public boolean
selectSuccess(
TransportHelper helper,
Object attachment )
{
return( readyForRead( true ));
}
public void
selectFailure(
TransportHelper helper,
Object attachment,
Throwable msg)
{
readFailed( msg );
}
},
null );
helper.registerForWriteSelects(
new TransportHelper.selectListener()
{
public boolean
selectSuccess(
TransportHelper helper,
Object attachment )
{
return( readyForWrite( true ));
}
public void
selectFailure(
TransportHelper helper,
Object attachment,
Throwable msg)
{
writeFailed( msg );
}
},
null );
|
private void | requestReadSelect()
is_ready_for_read = false;
if ( filter != null ){
filter.getHelper().resumeReadSelects();
}
|
private void | requestWriteSelect()
is_ready_for_write = false;
if( filter != null ){
filter.getHelper().resumeWriteSelects();
}
|
public void | setAlreadyRead(java.nio.ByteBuffer bytes_already_read)
if ( data_already_read != null ){
Debug.out( "push back already performed" );
}
if ( bytes_already_read != null && bytes_already_read.hasRemaining()){
data_already_read = bytes_already_read;
is_ready_for_read = true;
}
|
public void | setFilter(TransportHelperFilter _filter)
filter = _filter;
if ( trace && _filter != null ){
_filter.setTrace( true );
}
|
public void | setReadyForRead()
readyForRead( true );
|
public void | setTrace(boolean on)
trace = on;
TransportHelperFilter filter = getFilter();
if ( filter != null ){
filter.setTrace( on );
}
|
public long | write(java.nio.ByteBuffer[] buffers, int array_offset, int length)Write data to the transport from the given buffers.
NOTE: Works like GatheringByteChannel.
if ( write_select_failure != null ){
throw new IOException( "write_select_failure: " + write_select_failure.getMessage() );
}
if ( filter == null ) return 0;
long written = filter.write( buffers, array_offset, length );
if ( stats != null ) stats.bytesWritten( (int)written ); //TODO
if ( written < 1 ) requestWriteSelect();
return written;
|
protected void | writeFailed(java.lang.Throwable msg)
msg.fillInStackTrace();
write_select_failure = msg;
is_ready_for_write = true; //set to true so that the next write attempt will throw an exception
|