Srikanth Veeramachaneni wrote:
> Hi Niklas,
> 
> I was looking at your tunneling proxy example.
> 
> In AbstractProxyIoHandler.messageReceived() method, is there any
> problem if we do this
> --------------------------------------
>         ByteBuffer rb = ( ByteBuffer ) message;
>         rb.acquire();
>         ( ( IoSession ) session.getAttachment() ).write( rb );
>         SessionLog.info( session, rb.getString( CHARSET.newDecoder() ) );
> --------------------------------------
> instead of
> --------------------------------------
>         ByteBuffer rb = ( ByteBuffer ) message;
>         ByteBuffer wb = ByteBuffer.allocate( rb.remaining() );
>         rb.mark();
>         wb.put( rb );
>         wb.flip();
>         ( ( IoSession ) session.getAttachment() ).write( wb );
>         rb.reset();
>         SessionLog.info( session, rb.getString( CHARSET.newDecoder() ) );
> --------------------------------------
> 
> Basically, is there a problem doing an acquire() instead of making a
> copy of the byte buffer when I want to use the byte buffer for writes.

Hi, you're right that the copy is unnecessary. But I don't think it is
this simple since getString() will consume the buffer. And the order of
the wrtie() and getString() calls doesn't matter I think since write()
will probably be ansynchronous. IMO, you will still need the
mark()/reset() calls:

ByteBuffer rb = ( ByteBuffer ) message;
rb.acquire();
rb.mark();
SessionLog.info( session, rb.getString( CHARSET.newDecoder() ) );
rb.reset();
( ( IoSession ) session.getAttachment() ).write( rb );

Thanks for your input!

/Niklas

Reply via email to