Methods Summary |
---|
protected boolean | canRead()
synchronized( read_buffers ){
return( read_buffers.size() > 0 );
}
|
protected boolean | canWrite()
return( set.canWrite( this ));
|
protected void | close(java.lang.String reason)
if ( transport != null ){
transport.close( reason );
}else{
closeSupport( reason );
}
|
protected void | closeSupport(java.lang.String reason)
connected = false;
read_buffer_sem.releaseForever();
set.close( this, reason );
|
protected void | failed(java.lang.Throwable reason)
if ( transport != null ){
transport.failed( reason );
}else{
failedSupport( reason );
}
|
protected void | failedSupport(java.lang.Throwable reason)
connected = false;
read_buffer_sem.releaseForever();
set.failed( this, reason );
|
protected int | getID()
return( id );
|
protected UDPSelector | getSelector()
return( set.getSelector());
|
protected UDPTransportHelper | getTransport()
return( transport );
|
protected boolean | isConnected()
return( connected );
|
public boolean | isIncoming()
return( transport.isIncoming());
|
protected void | poll()
if ( transport != null ){
transport.poll();
}
|
protected int | read(java.nio.ByteBuffer buffer)
int total = 0;
synchronized( read_buffers ){
while( read_buffers.size() > 0 ){
int rem = buffer.remaining();
if ( rem == 0 ){
break;
}
ByteBuffer b = (ByteBuffer)read_buffers.get(0);
int old_limit = b.limit();
if ( b.remaining() > rem ){
b.limit( b.position() + rem );
}
buffer.put( b );
b.limit( old_limit );
total += rem - buffer.remaining();
if ( b.hasRemaining()){
break;
}else{
read_buffers.remove(0);
read_buffer_sem.release();
}
}
}
// System.out.println( "Connection(" + getID() + ") - read -> " +total );
return( total );
|
protected void | receive(java.nio.ByteBuffer data)
// packets reach us using 8K space regardless of content - trim this back for small protocol
// messages to save memory
int rem = data.remaining();
if ( rem < 256 ){
byte[] temp = new byte[rem];
data.get( temp );
data = ByteBuffer.wrap( temp );
}
read_buffer_sem.reserve();
if ( !connected ){
throw( new IOException( "Transport closed" ));
}
boolean was_empty = false;
synchronized( read_buffers ){
was_empty = read_buffers.size() == 0;
read_buffers.add( data );
}
if ( was_empty ){
transport.canRead();
}
|
protected void | sent()
// notification that a packet has been sent
transport.canWrite();
|
protected void | setID(int _id)
id = _id;
|
protected void | setSecret(byte[] session_secret)
set.setSecret( this, session_secret );
|
protected void | setTransport(UDPTransportHelper _transport)
transport = _transport;
|
protected int | write(java.nio.ByteBuffer[] buffers, int offset, int length)
int written = set.write( this, buffers, offset, length );
// System.out.println( "Connection(" + getID() + ") - write -> " + written );
return( written );
|