Methods Summary |
---|
protected void | asyncProcessComplete(java.io.ByteArrayOutputStream response)
write_buffer = ByteBuffer.wrap( response.toByteArray());
((TRNonBlockingServer)getServer()).readyToWrite( this );
|
protected void | closed()
// System.out.println( "close: " + System.currentTimeMillis());
|
protected void | completed()
// System.out.println( "complete: " + System.currentTimeMillis());
|
protected void | failed()
|
protected java.nio.channels.SocketChannel | getSocketChannel()
return( socket_channel );
|
protected long | getStartTime()
return( start_time );
|
public void | interruptTask()
|
protected abstract java.io.ByteArrayOutputStream | process(java.lang.String input_header, java.lang.String lowercase_input_header, java.lang.String url_path, java.net.InetSocketAddress client_address, boolean announce_and_scrape_only, java.io.InputStream is)
|
protected int | processRead()
if ( read_buffer.remaining() == 0 ){
int capacity = read_buffer.capacity();
if ( capacity == READ_BUFFER_LIMIT ){
return( -1 );
}else{
read_buffer.position(0);
byte[] data = new byte[capacity];
read_buffer.get( data );
read_buffer = ByteBuffer.allocate( capacity + READ_BUFFER_INCREMENT );
read_buffer.put( data );
}
}
try{
int len = socket_channel.read( read_buffer );
// System.out.println( "read op[" + len + "]: " + System.currentTimeMillis());
if ( len < 0 ){
return( -1 );
}else if ( len == 0 ){
return( 2 ); // no progress
}
byte[] data = read_buffer.array();
for (int i=read_buffer.position()-4;i>=0;i--){
if ( data[i] == CR &&
data[i+1] == FF &&
data[i+2] == CR &&
data[i+3] == FF ){
request_header = new String(data,0,read_buffer.position());
// System.out.println( "read done: " + System.currentTimeMillis());
getServer().runProcessor( this );
return( 0 );
}
}
return( 1 );
}catch( IOException e ){
return( -1 );
}
|
protected int | processWrite()
if ( write_buffer == null ){
return( -1 );
}
if ( !write_buffer.hasRemaining()){
return( 0 );
}
try{
int written = socket_channel.write( write_buffer );
if ( written == 0 ){
return( 2 );
}
if ( write_buffer.hasRemaining()){
return( 1 );
}
return( 0 );
}catch( IOException e ){
return( -1 );
}
|
public void | runSupport()
boolean async = false;
try{
String url = request_header.substring(4).trim();
int pos = url.indexOf( " " );
url = url.substring(0,pos);
ByteArrayOutputStream response =
process( request_header,
request_header.toLowerCase(),
url,
(InetSocketAddress)socket_channel.socket().getRemoteSocketAddress(),
TRTrackerServerImpl.restrict_non_blocking_requests,
new ByteArrayInputStream(new byte[0]));
if ( response == null ){
async = true;
}else{
write_buffer = ByteBuffer.wrap( response.toByteArray());
}
}catch( Throwable e ){
}finally{
if ( !async ){
((TRNonBlockingServer)getServer()).readyToWrite( this );
}
}
|