Thanks for reply!
Erik Svensson-2 wrote:
>
> A quick look at the code shows that, as far as Grizzly knows, you aren't
> doing anything with the incoming byteBuffer. The position is the same when
> releaseBuffer() is called as it was when startBuffer() was called.
> Even more important, the buffer is still unread and full when you exit
> releaseBuffer()!
> grizzly asks protocol parser about the buffer state by calling
> hasMoreBytesToParse() - it do not check the buffer directly - you can see
> this here
https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/grizzly/src/main/java/com/sun/grizzly/filter/ParserProtocolFilter.java?rev=668&view=log
Take a look at execute() and postExecute() methods.
Erik Svensson-2 wrote:
>
> Looking at the code I'm wondering a bit about how you handle your retain
> buffer. If I was implementing this (with the scant knowledge I have) I
> would
> append the incoming bytebuffer to the retain buffer and then parse the
> retain buffer. ie:
>
> ByteBuffer byteBuffer, incomingPacketBuffer;
>
>
> incomingPacketBuffer = ByteBuffer.allocate(some_size);
>
>
> public void startBuffer(ByteBuffer pBuf) {
> if (incomingPacketBuffer.remaining() < pBuf) {
> // grow incomingPacketBuffer, by creating a new one and copy the old
> into the new.
> }
> incomingPacketBuffer.position(incomingPacketBuffer.limit());
> incomingPacketBuffer.put(pBuf);
> incomingPacketBuffer.position(0); // position at the begining
> }
>
> It seems to me that you are reading from the incoming buffer before you
> are
> checking to see if there is anything remaining in the
> incomingPacketBuffer.
> If you get an incomplete message shouldn't incomingPacketBuffer be the
> buffer that contains the header (and maybe more) for the message?
> You definitely need to take a closer look at my sources :) i'm reading
> into the `data` field of an `incomingPacket` - there is no need for "grow
> incomingPacketBuffer, by creating a new one and copy the old into the
> new." because i already know the packet size from the header.
--
View this message in context: http://www.nabble.com/Need-help-implementing-ProtocolParser-tp16091789p16098360.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.