<div dir="ltr">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.<div><div><br>
</div><div>Shay<br><br><div class="gmail_quote">On Thu, May 13, 2010 at 8:32 PM, Johnny Luong <span dir="ltr"><<a href="mailto:johnny.luong@trustcommerce.com">johnny.luong@trustcommerce.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Class FrameDecoder;<br>
<br>
<a href="http://docs.jboss.org/netty/3.1/api/org/jboss/netty/handler/codec/frame/FrameDecoder.html" target="_blank">http://docs.jboss.org/netty/3.1/api/org/jboss/netty/handler/codec/frame/FrameDecoder.html</a><br>
<div><div></div><div class="h5"><br>
<br>
Shay Banon wrote:<br>
> Where is it exactly?<br>
><br>
> On Thu, May 13, 2010 at 4:33 AM, Johnny Luong <<br>
> <a href="mailto:johnny.luong@trustcommerce.com">johnny.luong@trustcommerce.com</a>> wrote:<br>
><br>
>> Hi Shay,<br>
>><br>
>> I think the example provided in the javadoc under Decoder Implementation<br>
>> is what your trying to do and provides clarity...<br>
>><br>
>> <a href="http://docs.jboss.org/netty/3.1/api/" target="_blank">http://docs.jboss.org/netty/3.1/api/</a><br>
>><br>
>> Best,<br>
>> Johnny<br>
>><br>
>><br>
>> Shay Banon wrote:<br>
>>> Hi,<br>
>>><br>
>>> I have a problem and am trying to find the best solution for. In<br>
>> netty, I<br>
>>> am using a FrameDecoder that simply does the following:<br>
>>><br>
>>> protected Object decode(ChannelHandlerContext ctx, Channel channel,<br>
>>> ChannelBuffer buffer) throws Exception {<br>
>>><br>
>>> if (buffer.readableBytes() < 4) {<br>
>>> return null;<br>
>>> }<br>
>>><br>
>>> int dataLen = buffer.getInt(buffer.readerIndex());<br>
>>> if (dataLen <= 0) {<br>
>>> throw new StreamCorruptedException("invalid data length: " +<br>
>>> dataLen);<br>
>>> }<br>
>>><br>
>>> if (buffer.readableBytes() < dataLen + 4) {<br>
>>> return null;<br>
>>> }<br>
>>><br>
>>> buffer.skipBytes(4);<br>
>>><br>
>>> return buffer;<br>
>>> }<br>
>>><br>
>>> On the next handler, I use the buffer to extract the request from (and<br>
>> other<br>
>>> information). The problem I have is that something might fail and I won't<br>
>>> read the whole buffer. In this case, things gets corrupted for requests<br>
>> that<br>
>>> follow. Once I do read the whole buffer, things works correctly. I can<br>
>>> skipBytes in the size of (writerIndex - readerIndex) in case of an<br>
>>> exception, but then I wonder how does the built in ObjectDecoder handles<br>
>>> this case..., maybe I am missing something?<br>
>>><br>
>>> cheers,<br>
>>> shay.banon<br>
>>><br>
>>><br>
>>><br>
>>> ------------------------------------------------------------------------<br>
>>><br>
>>> _______________________________________________<br>
>>> netty-users mailing list<br>
>>> <a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>
>>> <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
>> _______________________________________________<br>
>> netty-users mailing list<br>
>> <a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>
>> <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
>><br>
><br>
><br>
> ------------------------------------------------------------------------<br>
><br>
> _______________________________________________<br>
> netty-users mailing list<br>
> <a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
<br>
_______________________________________________<br>
netty-users mailing list<br>
<a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
</div></div></blockquote></div><br></div></div></div>