Skip to content

Commit

Permalink
Merge pull request RIOT-OS#20690 from benpicco/nanocoap_get_blockwise…
Browse files Browse the repository at this point in the history
…_to_buf

nanocoap_sock: add nanocoap_get_blockwise_to_buf()
  • Loading branch information
benpicco committed May 27, 2024
2 parents 27b06aa + c5cfecb commit e62c25a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
23 changes: 23 additions & 0 deletions sys/include/net/nanocoap_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,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 @@ -826,6 +826,17 @@ ssize_t nanocoap_get_blockwise_url_to_buf(const char *url,
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)
{
sock_udp_t sock;
Expand Down

0 comments on commit e62c25a

Please sign in to comment.