Methods Summary |
---|
protected void | canRead()
fireReadSelect();
|
protected void | canWrite()
fireWriteSelect();
|
public synchronized void | cancelReadSelects()
selector.cancel( this, read_listener );
read_selects_paused = true;
read_listener = null;
read_attachment = null;
|
public synchronized void | cancelWriteSelects()
selector.cancel( this, write_listener );
write_selects_paused = true;
write_listener = null;
write_attachment = null;
|
public void | close(java.lang.String reason)
synchronized( this ){
closed = true;
fireReadSelect();
fireWriteSelect();
}
connection.closeSupport( reason );
|
public boolean | delayWrite(java.nio.ByteBuffer buffer)
// TODO: support this one day?
return false;
|
public void | failed(java.lang.Throwable reason)
synchronized( this ){
if ( reason instanceof IOException ){
failed = (IOException)reason;
}else{
failed = new IOException( Debug.getNestedExceptionMessageAndStack(reason));
}
fireReadSelect();
fireWriteSelect();
}
connection.failedSupport( reason );
|
protected void | fireReadSelect()
synchronized( this ){
if ( read_listener != null && !read_selects_paused ){
if ( failed != null ){
selector.ready( this, read_listener, read_attachment, failed );
}else if ( closed ){
selector.ready( this, read_listener, read_attachment, new Throwable( "Transport closed" ));
}else if ( connection.canRead()){
selector.ready( this, read_listener, read_attachment );
}
}
}
|
protected void | fireWriteSelect()
synchronized( this ){
if ( write_listener != null && !write_selects_paused ){
if ( failed != null ){
write_selects_paused = true;
selector.ready( this, write_listener, write_attachment, failed );
}else if ( closed ){
write_selects_paused = true;
selector.ready( this, write_listener, write_attachment, new Throwable( "Transport closed" ));
}else if ( connection.canWrite()){
write_selects_paused = true;
selector.ready( this, write_listener, write_attachment );
}
}
}
|
public java.net.InetSocketAddress | getAddress()
return( address );
|
public int | getConnectTimeout()
return( CONNECT_TIMEOUT );
|
protected UDPConnection | getConnection()
return( connection );
|
protected int | getMss()
if ( transport == null ){
return( UDPNetworkManager.getUdpMssSize());
}
return( transport.getMssSize());
|
public java.lang.String | getName()
return( " (UDP)" );
|
public int | getReadTimeout()
return( READ_TIMEOUT );
|
protected UDPTransport | getTransport()
return( transport );
|
public synchronized java.lang.Object | getUserData(java.lang.Object key)
if ( user_data == null ){
return(null);
}
return( user_data.get( key ));
|
public boolean | hasDelayedWrite()
return( false );
|
public boolean | isIncoming()
return( incoming );
|
public boolean | minimiseOverheads()
return( UDPNetworkManager.MINIMISE_OVERHEADS );
|
public synchronized void | pauseReadSelects()
if ( read_listener != null ){
selector.cancel( this, read_listener );
}
read_selects_paused = true;
|
public synchronized void | pauseWriteSelects()
if ( write_listener != null ){
selector.cancel( this, write_listener );
}
write_selects_paused = true;
|
protected void | poll()
synchronized( this ){
fireReadSelect();
fireWriteSelect();
}
|
public int | read(java.nio.ByteBuffer buffer)
synchronized( this ){
if ( failed != null ){
throw( failed );
}
if ( closed ){
throw( new IOException( "Transport closed" ));
}
}
return( connection.read( buffer ));
|
public long | read(java.nio.ByteBuffer[] buffers, int array_offset, int length)
synchronized( this ){
if ( failed != null ){
throw( failed );
}
if ( closed ){
throw( new IOException( "Transport closed" ));
}
}
long total = 0;
for (int i=array_offset;i<array_offset+length;i++){
ByteBuffer buffer = buffers[i];
int max = buffer.remaining();
int read = connection.read( buffer );
total += read;
if ( read < max ){
break;
}
}
//System.out.println( "total = " + total );
return( total );
|
public void | registerForReadSelects(selectListener listener, java.lang.Object attachment)
synchronized( this ){
read_listener = listener;
read_attachment = attachment;
}
resumeReadSelects();
|
public void | registerForWriteSelects(selectListener listener, java.lang.Object attachment)
synchronized( this ){
write_listener = listener;
write_attachment = attachment;
}
resumeWriteSelects();
|
public synchronized void | resumeReadSelects()
read_selects_paused = false;
fireReadSelect();
|
public synchronized void | resumeWriteSelects()
write_selects_paused = false;
fireWriteSelect();
|
public void | setTrace(boolean on)
|
protected void | setTransport(UDPTransport _transport)
transport = _transport;
|
public synchronized void | setUserData(java.lang.Object key, java.lang.Object data)
if ( user_data == null ){
user_data = new HashMap();
}
user_data.put( key, data );
|
public int | write(java.nio.ByteBuffer buffer, boolean partial_write)
synchronized( this ){
if ( failed != null ){
throw( failed );
}
if ( closed ){
throw( new IOException( "Transport closed" ));
}
}
if ( partial_write ){
if ( pending_partial_write == null ){
if ( buffer.remaining() < UDPConnectionSet.MIN_WRITE_PAYLOAD ){
ByteBuffer copy = ByteBuffer.allocate( buffer.remaining());
copy.put( buffer );
copy.position( 0 );
pending_partial_write = copy;
return( copy.remaining());
}
}
}
if ( pending_partial_write != null ){
try{
int pw_len = pending_partial_write.remaining();
int written = connection.write( new ByteBuffer[]{ pending_partial_write, buffer }, 0, 2 );
if ( written >= pw_len ){
return( written - pw_len );
}else{
return( 0 );
}
}finally{
if ( pending_partial_write.remaining() == 0 ){
pending_partial_write = null;
}
}
}else{
return( connection.write( new ByteBuffer[]{ buffer }, 0, 1 ));
}
|
public long | write(java.nio.ByteBuffer[] buffers, int array_offset, int length)
synchronized( this ){
if ( failed != null ){
throw( failed );
}
if ( closed ){
throw( new IOException( "Transport closed" ));
}
}
if ( pending_partial_write != null ){
ByteBuffer[] buffers2 = new ByteBuffer[length+1];
buffers2[0] = pending_partial_write;
int pos = 1;
for (int i=array_offset;i<array_offset+length;i++){
buffers2[pos++] = buffers[i];
}
try{
int pw_len = pending_partial_write.remaining();
int written = connection.write( buffers2, 0, buffers2.length );
if ( written >= pw_len ){
return( written - pw_len );
}else{
return( 0 );
}
}finally{
if ( pending_partial_write.remaining() == 0 ){
pending_partial_write = null;
}
}
}else{
return( connection.write( buffers, array_offset, length ));
}
|