protected void write ( ) throws Exception { ByteBuffer buffer = queue . peek ( ) ; if ( buffer == null ) { if ( key != null ) { key . interestOps ( 0 ) ; } return ; } if ( channel != null ) { int count ; while ( true ) { count = channel . write ( buffer ) ; // Debug if ( debug ) { logger . info ( count + " bytes submitted to " + channel . getRemoteAddress ( ) + "." ) ; } // EOF? if ( count == - 1 ) { throw new InvalidPacketDataError ( nodeID , "host" , host , "port" , port ) ; } // Remove the submitted buffer from the queue if ( ! buffer . hasRemaining ( ) ) { queue . poll ( ) ; } // Turn off write mode (if the queue is empty) if ( queue . isEmpty ( ) ) { if ( blockerBuffer . compareAndSet ( buffer , null ) && key != null ) { key . interestOps ( 0 ) ; } return ; } else { buffer = queue . peek ( ) ; } } } }
Writes N bytes to the target channel .