Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nanocoap_sock: add nanocoap_get_blockwise_to_buf() #20690

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions sys/include/net/nanocoap_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,29 @@ ssize_t nanocoap_get_blockwise_url_to_buf(const char *url,
coap_blksize_t blksize,
void *buf, size_t len);

/**
* @brief Performs a blockwise CoAP GET request, store the response
* in a buffer.
*
* This function will fetch the content of the specified resource path via
* block-wise-transfer.
* The blocks will be re-assembled into @p buf
*
* @param[in] sock socket to use for the request
* @param[in] path pointer to source path
* @param[in] blksize sender suggested SZX for the COAP block request
* @param[in] buf Target buffer
* @param[in] len Target buffer length
*
* @returns <0 on error
* @returns -EINVAL if an invalid url is provided
* @returns -ENOBUFS if the provided buffer was too small
* @returns size of the response payload on success
*/
ssize_t nanocoap_get_blockwise_to_buf(nanocoap_sock_t *sock, const char *path,
coap_blksize_t blksize,
void *buf, size_t len);

/**
* @brief Simple synchronous CoAP request
*
Expand Down
11 changes: 11 additions & 0 deletions sys/net/application_layer/nanocoap/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@

/* random timeout, deadline for receive retries */
uint32_t timeout = random_uint32_range((uint32_t)CONFIG_COAP_ACK_TIMEOUT_MS * US_PER_MS,
(uint32_t)CONFIG_COAP_ACK_TIMEOUT_MS * CONFIG_COAP_RANDOM_FACTOR_1000);

Check warning on line 196 in sys/net/application_layer/nanocoap/sock.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
uint32_t deadline = _deadline_from_interval(timeout);

/* check if we expect a reply */
Expand Down Expand Up @@ -811,6 +811,17 @@
return (res < 0) ? (ssize_t)res : (ssize_t)_buf.len;
}

ssize_t nanocoap_get_blockwise_to_buf(nanocoap_sock_t *sock, const char *path,
coap_blksize_t blksize,
void *buf, size_t len)
{
_buf_t _buf = { .ptr = buf, .len = len };

int res = nanocoap_sock_get_blockwise(sock, path, blksize, _2buf, &_buf);

return (res < 0) ? (ssize_t)res : (ssize_t)_buf.len;
}

int nanocoap_server(sock_udp_ep_t *local, uint8_t *buf, size_t bufsize)
{
nanocoap_sock_t sock;
Expand Down
Loading