Skip to content

Plain UDP does not preserve packet borders #907

Description

@numo68

This issue is based just on looking at the 6.11 code while assessing of whether it is suitable for implementing a general UDP communication. I cannot exclude that I am overlooking something but I'll document the issue nevertheless.

One of the primary features of UDP is that it preserves the message borders - if I send a 1024 bytes packet, a 16384 one and a 384 one using three sendto calls, the other side gets those exact data in three subsequent recvfrom calls.

If I look into the mongoose code there is just one mbuf for the connection to send the data from. Two mg_sends without the underlying sendto (for whatever reason) will result in one packet containing data from both sends.

In the receiving direction the mg_handle_udp_read calls mg_recvfrom that uses a fixed buffer of a 1500 size and appends the data to a receiving mbuf. The code is completely unable to accept packets larger than a compile-time defined size, as the recvfrom on a datagram socket will silently truncate the excess data.

That means that the MG_F_UDP code is basically unusable for what the UDP communication is usually being used for, i.e. being able to send datagrams that are unreliable and might be out of order or duplicated, but a datagram is either completely received or not at all. If this is indeed the case I'd recommend to either fix it (e.g. by using linked mbufs, each containing one and only one packet, and a configurable buffer at the receiving side), or to remove the functionality completely, as it will only work for packets <= 1500 bytes being sent occasionally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions