garbled data passed in cumulation buffer for decode(), probably when data re-transmission.

huican ping pinghuican at gmail.com
Thu Sep 10 23:17:29 EDT 2009


Hello Trustin,

I thought I found some place in my parser suspicious, now my logic is
pretty much same as the example posted at the FrameDecoder page, and
still get the same issue.

// My decode() logic.
protected Object decode(ChannelHandlerContext ctx, Channel channel,
			ChannelBuffer buffer) throws Exception {

	// return if the buffer empty
	if (buffer.readableBytes() <= 0) {
		return null;
	}

	// Mark the current buffer position before parsing the buffer
	// because the whole message might not be in the buffer yet.
	// We will reset the buffer position to the marked position in
	// that case.
	buffer.markReaderIndex();


	for ( loc = buffer.readerIndex(); loc < buffer.writerIndex(); loc++)
	{
		// Paser code.
		// if find the whole message, then return that message
		// otherwise, it will hit the end of the loop
		// Inside the loop
		
		// I didn't modify the buffer except change its readerIndex if
		// the whole message is not there yet.
	}


	// The whole message were not received yet - return null.
	// This method will be invoked again when more packets are
	// received and appended to the buffer.

	// Reset to the marked position to read the length field again
	// next time.
	buffer.resetReaderIndex();
	return null;
}

// my getPipeline() logic:
		pipeline.addLast("decoder", new acmeDecoder());
		pipeline.addLast("encoder", new acmeEncoder());
                pipeline.addLast("handler", new acmeServerHandler());


Thanks
Huican Ping

On Thu, Sep 10, 2009 at 9:49 PM, Huican Ping <pinghuican at gmail.com> wrote:
>
> Hello Trustin,
>
> Probably it is my parser problem. Don't waste time on it now. I am
> sorry about it.
>
> Thanks
> Huican Ping
>
> On Thu, Sep 10, 2009 at 5:40 PM, Huican Ping (via Nabble)
> <ml-user+135163-919750110 at n2.nabble.com> wrote:
>> FYI, my decoder inherited from the FrameDecoder.
>>
>> Thanks
>> Huican Ping


More information about the netty-users mailing list