Skip to content

WiFiUDP not reading last byte #145

Closed
@henrikkunzelmann

Description

@henrikkunzelmann

The WiFiUDP implementation is not reading the last byte in WiFiUDP::read().

Example (code is working fine on ESP8266 and ESP32 with one byte extra padding when sending packets to it):

int size = udp->parsePacket();
udp->read(buffer, size);

Size is for example 17 but read() reads only 16 bytes. The bug is in the cbuf class: cbuf::write() copies 16 bytes because cbuf::room() returns only 16 bytes (and not the correct length of 17 bytes).

The bug in the cbuf class should be fixed, but also a new method should be added to WiFiUDP:

int WiFiUDP::parsePacket(char* buffer, size_t size) (or some other signature).

parsePacket copies the packet content in the user provided buffer and returning the size of the packet. With this approach there is no need to create an internal cbuf instance and saving some memory overall.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions