mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lécharny <elecha...@gmail.com>
Subject Re: CumulativeProtocolDecoder and UDP
Date Wed, 02 Mar 2016 23:10:26 GMT
Le 02/03/16 07:38, tunca a écrit :
> Hi Emmanuel.
> http://pastebin.com/embed_iframe/EpL4WE4b
> This is the link to my doDecode method.
>
> A complete message starts with x01 and ends with x03.
> For test I send 2 udp messages.
> First Udp message starts with x01 
> Second Udp messages ends with x03.
>
> When I send first message doDecode message is called with the content of the
> first Udp message.
> the doDecode method returns false as the message is not complete.
>
> Then the second Udp message is sent.
> However doDecode method is still called with only First Udp message's
> content from in IoBuffer parameter.

Ok, I think I see what's going on. The
CumulativeProtocolDecoder.decode() method starts with :

    public void decode(IoSession session, IoBuffer in,
ProtocolDecoderOutput out) throws Exception {
        if (!session.getTransportMetadata().hasFragmentation()) {
            while (in.hasRemaining()) {
                if (!doDecode(session, in, out)) {
                    break;
                }
            }

            return;
        }

and for a UDP session, we initialize the transport metadata this way :

    static final TransportMetadata METADATA = new
DefaultTransportMetadata("nio", "datagram", true, false,
            InetSocketAddress.class, DatagramSessionConfig.class,
IoBuffer.class);


where the forth parameter is 'boolean fragmentation' :

    public DefaultTransportMetadata(String providerName, String name,
boolean connectionless, boolean fragmentation,
            Class<? extends SocketAddress> addressType, Class<? extends
IoSessionConfig> sessionConfigType,
            Class<?>... envelopeTypes) {

It's set to 'false', so the decode method simply don't accumulate the
data in one single buffer.

There is no way to change the flag once the metadata instance has been
created.

What you can do is to define your own version of the
CumulativeProtocolDecoder, copying the original code and simply discard
the test on the transportMetadata.

       

Mime
View raw message