mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 04:52:59 +01:00
sys/net/application_layer/nanocoap: add nanocoap_sock_get_non
This commit is contained in:
parent
821a7e8c9f
commit
95b46ee2a5
@ -389,6 +389,20 @@ static inline void nanocoap_sock_close(nanocoap_sock_t *sock)
|
||||
ssize_t nanocoap_sock_get(nanocoap_sock_t *sock, const char *path, void *buf,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* @brief Simple non-confirmable GET
|
||||
*
|
||||
* @param[in] sock socket to use for the request
|
||||
* @param[in] path remote path and query
|
||||
* @param[out] response buffer for the response, may be NULL
|
||||
* @param[in] len_max length of @p response
|
||||
*
|
||||
* @returns length of response payload on success
|
||||
* @returns <0 on error
|
||||
*/
|
||||
ssize_t nanocoap_sock_get_non(nanocoap_sock_t *sock, const char *path,
|
||||
void *response, size_t len_max);
|
||||
|
||||
/**
|
||||
* @brief Simple synchronous CoAP (confirmable) PUT
|
||||
*
|
||||
|
@ -390,7 +390,9 @@ static int _get_put_cb(void *arg, coap_pkt_t *pkt)
|
||||
return pkt->payload_len;
|
||||
}
|
||||
|
||||
ssize_t nanocoap_sock_get(nanocoap_sock_t *sock, const char *path, void *buf, size_t len)
|
||||
static ssize_t _sock_get(nanocoap_sock_t *sock, const char *path,
|
||||
uint8_t type,
|
||||
void *response, size_t max_len)
|
||||
{
|
||||
/* buffer for CoAP header */
|
||||
uint8_t buffer[CONFIG_NANOCOAP_BLOCK_HEADER_MAX];
|
||||
@ -401,11 +403,11 @@ ssize_t nanocoap_sock_get(nanocoap_sock_t *sock, const char *path, void *buf, si
|
||||
};
|
||||
|
||||
struct iovec ctx = {
|
||||
.iov_base = buf,
|
||||
.iov_len = len,
|
||||
.iov_base = response,
|
||||
.iov_len = max_len,
|
||||
};
|
||||
|
||||
pktpos += coap_build_hdr(pkt.hdr, COAP_TYPE_CON, NULL, 0, COAP_METHOD_GET,
|
||||
pktpos += coap_build_hdr(pkt.hdr, type, NULL, 0, COAP_METHOD_GET,
|
||||
nanocoap_sock_next_msg_id(sock));
|
||||
pktpos += coap_opt_put_uri_pathquery(pktpos, NULL, path);
|
||||
|
||||
@ -415,6 +417,11 @@ ssize_t nanocoap_sock_get(nanocoap_sock_t *sock, const char *path, void *buf, si
|
||||
return nanocoap_sock_request_cb(sock, &pkt, _get_put_cb, &ctx);
|
||||
}
|
||||
|
||||
ssize_t nanocoap_sock_get(nanocoap_sock_t *sock, const char *path, void *buf, size_t len)
|
||||
{
|
||||
return _sock_get(sock, path, COAP_TYPE_CON, buf, len);
|
||||
}
|
||||
|
||||
ssize_t _sock_put_post(nanocoap_sock_t *sock, const char *path, unsigned code,
|
||||
uint8_t type, const void *request, size_t len,
|
||||
void *response, size_t max_len)
|
||||
@ -507,6 +514,12 @@ ssize_t nanocoap_sock_fetch_non(nanocoap_sock_t *sock, const char *path,
|
||||
response, len_max);
|
||||
}
|
||||
|
||||
ssize_t nanocoap_sock_get_non(nanocoap_sock_t *sock, const char *path,
|
||||
void *response, size_t len_max)
|
||||
{
|
||||
return _sock_get(sock, path, COAP_TYPE_NON, response, len_max);
|
||||
}
|
||||
|
||||
static ssize_t _sock_put_post_url(const char *url, unsigned code,
|
||||
const void *request, size_t len,
|
||||
void *response, size_t len_max)
|
||||
|
Loading…
Reference in New Issue
Block a user