Skip to content

net: coap_client: streaming blockwise payloads #59571

@bdunlay

Description

@bdunlay

Is your enhancement proposal related to a problem? Please describe.

How can clients stream large payloads in blockwise uploads that otherwise could not fit in memory alone?

Today, the CoAP client initiates blockwise uploads strictly when the payload is larger than the configurable CONFIG_COAP_CLIENT_MESSAGE_SIZE, iterating on blocks of a fixed size offset in a buffer pointer. The payload pointer and size are provided in the initiating request.

Users may wish to not hold large payloads in memory, and instead stream them chunk by chunk.

Describe the solution you'd like

One solution might be to add a new member to the coap_client_request struct, something like coap_client_get_payload_t below, which if assigned would fill a buffer to a maximum length and return the number of bytes written. The payload would be written directly to the TX buffer.

/* returns >= 0 for number of bytes written, < 0 for error */
typedef int (*coap_get_payload_t)(uint8_t *payload, size_t len, void *user_data);

Example:

int get_my_payload(uint8_t *payload, size_t len, void *user_data) {
    struct my_ctx *ctx = user_data;
    return fs_read(ctx->my_file, payload, len);    
}

struct coap_client_request req = {
    .payload_cb = get_my_payload,
    .payload = NULL,
    .len = my_file.size,
    .user_data = ctx,
    ...
};

Describe alternatives you've considered

n/a

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions