users@grizzly.java.net

Question About Protocol Parser Example and expanding the Buffer

From: Parker Lord <plord_at_seecontrol.com>
Date: Fri, 1 May 2009 16:33:46 -0700 (PDT)

I have used Sébastien Dionne's three part example on Migrating to Grizzly.
Thank you Sébastien!

The only question I have is in the Protocol Parser :


          protected static final int LIMITBB = 5;

          .....


          // but check if the max length is attein
         if (processingBuffer.capacity() + processingBuffer.remaining() <
LIMITBB)
          {
            ByteBuffer newBB =
ByteBufferFactory.allocateView(processingBuffer.capacity() * 2,
processingBuffer.isDirect());
            newBB.put(processingBuffer);
            processingBuffer = newBB;
            WorkerThread workerThread =
(WorkerThread)Thread.currentThread();
            workerThread.setByteBuffer(processingBuffer);
          }
          else
          {
            syslog.severe("BUFFER MAX REACH!");
            processingBuffer.clear();
            maxBufferReached = true;
            return maxBufferReached;
          }


I guess I am missing something in the line that checks to see if we have
reached our max length.


if (processingBuffer.capacity() + processingBuffer.remaining() < LIMITBB)

is NEVER going to be true. In the initial case where capacity is 8192, and
the buffer is full, we get this:

if (8192 + 8192 < 5)


Shouldn't this be:

if (processingBuffer.capacity() + processingBuffer.remaining() <
(LIMITBB*8192))

or something?

-- 
View this message in context: http://www.nabble.com/Question-About-Protocol-Parser-Example-and-expanding-the-Buffer-tp23341414p23341414.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.