You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Emmanuel Lecharny <el...@gmail.com> on 2008/09/11 16:58:34 UTC

Dubious code in protocolCodecFilter

Hi guys,

while I was adding some javadoc and comments in this class, I found a 
very dubious portion of code :


    public void messageReceived(NextFilter nextFilter, IoSession session,
            Object message) throws Exception {

        ...
        while (in.hasRemaining()) {
            int oldPos = in.position();
            try {
                synchronized (decoderOut) {
                    // Call the decoder with the read bytes
                    decoder.decode(session, in, decoderOut);
                }
                // Finish decoding if no exception was thrown.
                decoderOut.flush();
               
                // TODO :
                // here, we shouldn't break,
                // we should loop to decode the next portion of the buffer.
                break;
            } catch (Throwable t) {

The 'break' here will exit the loop, even if we have some remaining 
bytes in the buffer. Now what will happen if we don't receive anymore 
bytes ? I'm afraid that the decoder will never be call again, as we 
won't receive another messageReceive event.

I think we should not break, but instead continue the loop, until we 
have ate all the bytes, or until we get an exception because the decoder 
can't decode a partial message.

Did I missed something ?

Thanks !

-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org