Stop receiving requests

Shay Banon kimchy at gmail.com
Thu May 13 14:04:51 EDT 2010


So, I had a chat with trustin over IRC. You do need to skipBytes or
reposition the reader index to the originalReaderIndex + length if in your
exception handler you don't close the connection.

Shay

On Thu, May 13, 2010 at 8:32 PM, Johnny Luong <
johnny.luong at trustcommerce.com> wrote:

> Class FrameDecoder;
>
>
> http://docs.jboss.org/netty/3.1/api/org/jboss/netty/handler/codec/frame/FrameDecoder.html
>
>
> Shay Banon wrote:
> > Where is it exactly?
> >
> > On Thu, May 13, 2010 at 4:33 AM, Johnny Luong <
> > johnny.luong at trustcommerce.com> wrote:
> >
> >> Hi Shay,
> >>
> >> I think the example provided in the javadoc under Decoder Implementation
> >> is what your trying to do and provides clarity...
> >>
> >> http://docs.jboss.org/netty/3.1/api/
> >>
> >> Best,
> >> Johnny
> >>
> >>
> >> 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
> >> _______________________________________________
> >> netty-users mailing list
> >> netty-users at lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/netty-users
> >>
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > netty-users mailing list
> > netty-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/netty-users
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20100513/fc0d74d7/attachment-0001.html 


More information about the netty-users mailing list