Stop receiving requests

"Trustin Lee (이희승)" trustin at gmail.com
Tue Jun 1 03:35:27 EDT 2010


Shay

As we already discussed in the IRC channel a while ago, the latest
ObjectDecoder extends LengthFieldBasedFrameDecoder instead of extending
FrameDecoder directly.  Hence, ObjectDecoder became more robust to
corrupted / undecodable objects.

HTH,
Trustin

Shay Banon wrote:
> Hi,
> 
>    I have a problem and am trying to find the best solution for. In
> netty, I am using a FrameDecoder that simply does the following:
> 
>     protected Object decode(ChannelHandlerContext ctx, Channel channel,
> ChannelBuffer buffer) throws Exception {
> 
>         if (buffer.readableBytes() < 4) {
>             return null;
>         }
> 
>         int dataLen = buffer.getInt(buffer.readerIndex());
>         if (dataLen <= 0) {
>             throw new StreamCorruptedException("invalid data length: " +
> dataLen);
>         }
> 
>         if (buffer.readableBytes() < dataLen + 4) {
>             return null;
>         }
> 
>         buffer.skipBytes(4);
> 
>         return buffer;
>     }
> 
> On the next handler, I use the buffer to extract the request from (and
> other information). The problem I have is that something might fail and
> I won't read the whole buffer. In this case, things gets corrupted for
> requests that follow. Once I do read the whole buffer, things works
> correctly. I can skipBytes in the size of (writerIndex - readerIndex) in
> case of an exception, but then I wonder how does the built in
> ObjectDecoder handles this case..., maybe I am missing something?
> 
> cheers,
> shay.banon
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users

-- 
what we call human nature in actuality is human habit
http://gleamynode.net/



More information about the netty-users mailing list