mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maarten Bosteels" <mbosteels....@gmail.com>
Subject Re: Duplicate messages
Date Wed, 17 Jan 2007 12:42:48 GMT
1) how is length defined ?
Is it a result of reading the header ?
Is it an instance attribute ?

2) what happens when there is not enough data to read a header ?
in that case you should also return MessageDecoderResult.NEED_DATA;
No ?

3) please, show us the code for readHeader(ByteBuffer in)

Maarten

On 1/17/07, Nicolas FROMENT <nfroment@histor.fr> wrote:
> Thanks ! I just find your post. You said that you use
> Buffer.position(start) instead of Buffer.rewind() in your decoder.
> Apparently you used an old of version at the time of the post. Your code
> is :
>
> protected boolean doDecode(IoSession session, ByteBuffer in,
> ProtocolDecoderOutput out) throws Exception
>     {
>         try
>         {
>             if (in.remaining() < 4)
>             {
>                 // We didn't receive enough bytes to decode the
>                 // message length. Cumulate remainder to decode later.
>                 return false;
>             }
>
>             // We can decode the message length
>             int msize = in.getInt();
>
>             if (in.remaining() < msize)
>             {
>                 // We didn't receive enough bytes to decode the message
> body.
>                 // Cumulate remainder to decode later.
>                 in.rewind();
>                 return false;
>             }
>     //decode body
> }
>
> My code assumes that I don"t have to rewind or position the buffer if I
> need more data because the buffer counters are not changed when I call
> remaining(). Am I wrong ? why do you call rewind ?
> Here is my code inspired from the sumServer example :
>
> public MessageDecoderResult decode(IoSession session, ByteBuffer in,
> ProtocolDecoderOutput out)
>     {
>         // Read the header if not yet read
>
>         if (!readHeader)
>         {
>             readHeader(in); // the attribute lenght will be affected here
>             readHeader = true;
>         }
>
>         if (in.remaining() < length)
>         {
>             return MessageDecoderResult.NEED_DATA;
>         }
>         else
>         {
>             MyMessage m = decodeBody(session, in);
>
>             readHeader = false; // reset readHeader for the next decode
> if necessary
>             if (m != null)
>             {
>                 return MessageDecoderResult.OK;
>             }
>             else
>             {
>                 return MessageDecoderResult.NOT_OK;
>             }
>         }
>     }
>
>
>
>
>
>
>
>
>
>
> Luis Neves a écrit :
> > Nicolas FROMENT wrote:
> >>
> >> Thanks for the tip. I use tcpdump and ethereal to sniff the traffic.
> >> I can now say that the problem is on the server side. One more clue.
> >> Any specific place to look at ? Decoder ? anywhere else ?
> >> Am I the only one to have this issue ?
> >
> > I had this issue recently:
> > <http://thread.gmane.org/gmane.comp.apache.directory.mina.devel/2732/focus=2732>
> >
> >
> > In my case the problem was in the Decoder.
> >
> > --
> > Luis Neves
> >
>
>
> --
> ******************************************************************
> Nicolas Froment         nfroment@histor.fr
> Software Architect
>
> Hi-Stor Technologies        www.histor.fr
> 23 bd Victor Hugo            Std:    +33 (0) 562 12 14 40 (Voice)
> Bâtiment Socrate             Fax:    +33 (0) 562 12 14 49
> 31770 Colomiers
> FRANCE
>
> ****************************************************************
>
>
Mime
View raw message