Exemplo n.º 1
0
        Datagram CreateSpecialDatagram(MessageType messageType, int payloadSize)
        {
            var datagram = Datagram.CreateNew(peer.Configuration.MemoryStreamPool, payloadSize);

            datagram.Type = messageType;
            return(datagram);
        }
Exemplo n.º 2
0
        UdpSendStatus SendFragmentedMessage(UdpRawMessage message, IChannel channel)
        {
            message.Position = 0;
            int    mtu     = this.Mtu;
            ushort frame   = 1;
            ushort frames  = (ushort)Math.Ceiling(message.Length / (float)(mtu - Datagram.GetHeaderSize(true)));
            ushort groupId = GetNextFragementationGroupId();

            do
            {
                Debug.Assert(frame <= frames, "frame > frames");

                Datagram datagramFrag = Datagram.CreateNew(peer.Configuration.MemoryStreamPool, mtu);
                datagramFrag.Type              = MessageType.UserData;
                datagramFrag.Channel           = channel.Descriptor.Channel;
                datagramFrag.DeliveryType      = channel.Descriptor.DeliveryType;
                datagramFrag.FragmentationInfo = new Datagram.FragmentInfo(groupId, frame, frames);
                datagramFrag.ConnectionKey     = this.EndPoint.ConnectionKey;

                int toCopy = mtu - Datagram.GetHeaderSize(true);
                if (toCopy > message.Length - message.Position)
                {
                    toCopy = message.Length - message.Position;
                }
                message.CopyTo(datagramFrag.BaseStream, toCopy);

                channel.SendDatagram(datagramFrag);
                frame++;
            } while (message.Position < message.Length);

            message.Dispose();

            return(UdpSendStatus.Enqueued);
        }
Exemplo n.º 3
0
        Datagram CreateSpecialDatagram(MessageType messageType, UdpRawMessage payload)
        {
            if (!CheckCanBeSendUnfragmented(payload))
            {
                throw new ArgumentException($"Payload can be datagram only smaller than current MTU ({Mtu})");
            }
            var datagram = Datagram.CreateNew(peer.Configuration.MemoryStreamPool, (int)payload.BaseStream.Length);

            datagram.Type = messageType;
            payload.BaseStream.Position = 0;
            payload.BaseStream.CopyTo(datagram.BaseStream);
            return(datagram);
        }