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

gcoap: make gcoap_req_send_tl() an alias of gcoap_req_send() #20514

Merged
merged 1 commit into from
Mar 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
6 changes: 4 additions & 2 deletions examples/gcoap/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ static void _resp_handler(const gcoap_request_memo_t *memo, coap_pkt_t* pdu,

int len = coap_opt_finish(pdu, COAP_OPT_FINISH_NONE);
gcoap_req_send((uint8_t *)pdu->hdr, len, remote,
_resp_handler, memo->context);
_resp_handler, memo->context,
GCOAP_SOCKET_TYPE_UNDEF);
Teufelchen1 marked this conversation as resolved.
Show resolved Hide resolved
}
else {
puts("--- blockwise complete ---");
Expand All @@ -158,7 +159,8 @@ static size_t _send(uint8_t *buf, size_t len, sock_udp_ep_t *remote)
{
size_t bytes_sent;

bytes_sent = gcoap_req_send(buf, len, remote, _resp_handler, NULL);
bytes_sent = gcoap_req_send(buf, len, remote, _resp_handler, NULL,
GCOAP_SOCKET_TYPE_UNDEF);
if (bytes_sent > 0) {
req_count++;
}
Expand Down
38 changes: 21 additions & 17 deletions sys/include/net/gcoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
* identify the slice with a Block2 option. This implementation toggles the
* actual writing of data as it passes over the code for the full response
* body. See the _riot_block2_handler() example in
* [gcoap-block-server](https://github.com/kb2ma/riot-apps/blob/kb2ma-master/gcoap-block-server/gcoap_block.c),

Check warning on line 222 in sys/include/net/gcoap.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
* which implements the sequence described below.
*
* - Use coap_block2_init() to initialize a _slicer_ struct from the Block2
Expand All @@ -244,7 +244,7 @@
* The server must ack each blockwise portion of the response body received
* from the client by writing a Block1 option in the response. See the
* _sha256_handler() example in
* [gcoap-block-server](https://github.com/kb2ma/riot-apps/blob/kb2ma-master/gcoap-block-server/gcoap_block.c),

Check warning on line 247 in sys/include/net/gcoap.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
* which implements the sequence described below.
*
* - Use coap_get_block1() to initialize a block1 struct from the request.
Expand Down Expand Up @@ -284,7 +284,7 @@
*
* The client pushes a specific blockwise payload from the overall body to the
* server by writing a Block1 option in the request. See _do_block_post() in
* the [gcoap-block-client](https://github.com/kb2ma/riot-apps/blob/kb2ma-master/gcoap-block-client/gcoap_block.c)

Check warning on line 287 in sys/include/net/gcoap.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
* example, which implements the sequence described below.
*
* - For the first request, use coap_block_slicer_init() to initialize a
Expand Down Expand Up @@ -330,7 +330,8 @@
* coap_opt_add_proxy_uri(&pdu, uri);
* unsigned len = coap_opt_finish(&pdu, COAP_OPT_FINISH_NONE);
*
* gcoap_req_send((uint8_t *) pdu->hdr, len, proxy_remote, _resp_handler, NULL);
* gcoap_req_send((uint8_t *) pdu->hdr, len, proxy_remote, _resp_handler, NULL,
* GCOAP_SOCKET_TYPE_UNDEF);
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* See the gcoap example for a sample implementation.
Expand Down Expand Up @@ -960,9 +961,6 @@
/**
* @brief Sends a buffer containing a CoAP request to the provided endpoint
*
* @deprecated Will be an alias for @ref gcoap_req_send after the 2022.01
* release. Will be removed after the 2022.04 release.
*
* @param[in] buf Buffer containing the PDU
* @param[in] len Length of the buffer
* @param[in] remote Destination for the packet
Expand All @@ -973,39 +971,45 @@
* available (by value) will be selected. Only single
* types are allowed, not a combination of them.
*
* @note The highest supported (by value) gcoap_socket_type_t will be selected
* as transport type.
*
* @return length of the packet
* @return -ENOTCONN, if DTLS was used and session establishment failed
* @return -EINVAL, if @p tl_type is is not supported
* @return 0 if cannot send
*/
ssize_t gcoap_req_send_tl(const uint8_t *buf, size_t len,
const sock_udp_ep_t *remote,
gcoap_resp_handler_t resp_handler, void *context,
gcoap_socket_type_t tl_type);
ssize_t gcoap_req_send(const uint8_t *buf, size_t len,
const sock_udp_ep_t *remote,
gcoap_resp_handler_t resp_handler, void *context,
gcoap_socket_type_t tl_type);

/**
* @brief Sends a buffer containing a CoAP request to the provided endpoint
*
* @deprecated Will be removed after the 2023.10 release. Use alias @ref gcoap_req_send() instead.
*
* @param[in] buf Buffer containing the PDU
* @param[in] len Length of the buffer
* @param[in] remote Destination for the packet
* @param[in] resp_handler Callback when response received, may be NULL
* @param[in] context User defined context passed to the response handler
*
* @note The highest supported (by value) gcoap_socket_type_t will be selected
* as transport type.
* @param[in] tl_type The transport type to use for send. When
* @ref GCOAP_SOCKET_TYPE_UNDEF is selected, the highest
* available (by value) will be selected. Only single
* types are allowed, not a combination of them.
*
* @return length of the packet
* @return -ENOTCONN, if DTLS was used and session establishment failed
* @return -EINVAL, if @p tl_type is is not supported
* @return 0 if cannot send
*/
static inline ssize_t gcoap_req_send(const uint8_t *buf, size_t len,
const sock_udp_ep_t *remote,
gcoap_resp_handler_t resp_handler,
void *context)
static inline ssize_t gcoap_req_send_tl(const uint8_t *buf, size_t len,
const sock_udp_ep_t *remote,
gcoap_resp_handler_t resp_handler, void *context,
gcoap_socket_type_t tl_type)
{
return gcoap_req_send_tl(buf, len, remote, resp_handler, context,
GCOAP_SOCKET_TYPE_UNDEF);
return gcoap_req_send(buf, len, remote, resp_handler, context, tl_type);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions sys/net/application_layer/cord/ep/cord_ep.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
ssize_t pkt_len = coap_opt_finish(&pkt, COAP_OPT_FINISH_NONE);

/* send request */
ssize_t send_len = gcoap_req_send(buf, pkt_len, &_rd_remote, handle, NULL);
ssize_t send_len = gcoap_req_send(buf, pkt_len, &_rd_remote, handle, NULL, GCOAP_SOCKET_TYPE_UNDEF);

Check warning on line 154 in sys/net/application_layer/cord/ep/cord_ep.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
if (send_len <= 0) {
return CORD_EP_ERR;
}
Expand Down Expand Up @@ -225,7 +225,7 @@
coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON);
coap_opt_add_uri_query(&pkt, "rt", "core.rd");
size_t pkt_len = coap_opt_finish(&pkt, COAP_OPT_FINISH_NONE);
res = gcoap_req_send(buf, pkt_len, remote, _on_discover, NULL);
res = gcoap_req_send(buf, pkt_len, remote, _on_discover, NULL, GCOAP_SOCKET_TYPE_UNDEF);
if (res <= 0) {
return CORD_EP_ERR;
}
Expand Down Expand Up @@ -296,7 +296,7 @@
pkt_len += res;

/* send out the request */
res = gcoap_req_send(buf, pkt_len, remote, _on_register, NULL);
res = gcoap_req_send(buf, pkt_len, remote, _on_register, NULL, GCOAP_SOCKET_TYPE_UNDEF);
if (res <= 0) {
retval = CORD_EP_ERR;
goto end;
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/cord/epsim/cord_epsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int cord_epsim_register(const sock_udp_ep_t *rd_ep)
/* finish, we don't have any payload */
ssize_t len = coap_opt_finish(&pkt, COAP_OPT_FINISH_NONE);
_state = CORD_EPSIM_BUSY;
if (gcoap_req_send(buf, len, rd_ep, _req_handler, NULL) == 0) {
if (gcoap_req_send(buf, len, rd_ep, _req_handler, NULL, GCOAP_SOCKET_TYPE_UNDEF) == 0) {
return CORD_EPSIM_ERROR;
}

Expand Down
4 changes: 2 additions & 2 deletions sys/net/application_layer/cord/lc/cord_lc.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
while (f) {
for (unsigned i = 0; i < f->len; i++) {
clif_attr_t *kv = &(f->array[i]);
if (coap_opt_add_uri_query2(pkt, kv->key, kv->key_len, kv->value, kv->value_len) == -1) {

Check warning on line 144 in sys/net/application_layer/cord/lc/cord_lc.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
return CORD_LC_OVERFLOW;
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@
if (pkt_len < 0) {
return CORD_LC_ERR;
}
res = gcoap_req_send(reqbuf, pkt_len, rd->remote, _on_lookup, NULL);
res = gcoap_req_send(reqbuf, pkt_len, rd->remote, _on_lookup, NULL, GCOAP_SOCKET_TYPE_UNDEF);
if (res < 0) {
return CORD_LC_ERR;
}
Expand Down Expand Up @@ -250,7 +250,7 @@
return CORD_LC_ERR;
}

if (!gcoap_req_send(buf, pkt_len, remote, _on_rd_init, NULL)) {
if (!gcoap_req_send(buf, pkt_len, remote, _on_rd_init, NULL, GCOAP_SOCKET_TYPE_UNDEF)) {
DEBUG("cord_lc: error gcoap_req_send()\n");
return CORD_LC_ERR;
}
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/gcoap/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,6 @@ static ssize_t _send(const void *buf, size_t len, const sock_udp_ep_t *remote,
if (lock_resp_wait) {
mutex_lock(&context->resp_wait);
}
return gcoap_req_send_tl(buf, len, remote, _resp_handler, context, tl_type);
return gcoap_req_send(buf, len, remote, _resp_handler, context, tl_type);
}
/** @} */
9 changes: 5 additions & 4 deletions sys/net/application_layer/gcoap/forward_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ static bool _parse_endpoint(sock_udp_ep_t *remote,
static ssize_t _dispatch_msg(const void *buf, size_t len, sock_udp_ep_t *remote)
{
/* Yes it's not a request -- but turns out there is nothing in
* gcoap_req_send_tl that is actually request specific, especially if we
* gcoap_req_send that is actually request specific, especially if we
* don't assign a callback. */
ssize_t res = gcoap_req_send_tl(buf, len, remote, NULL, NULL,
GCOAP_SOCKET_TYPE_UDP);
ssize_t res = gcoap_req_send(buf, len, remote, NULL, NULL,
GCOAP_SOCKET_TYPE_UDP);
if (res <= 0) {
DEBUG("gcoap_forward_proxy: unable to dispatch message: %d\n", -res);
}
Expand Down Expand Up @@ -440,7 +440,8 @@ static int _gcoap_forward_proxy_via_coap(coap_pkt_t *client_pkt,

len = gcoap_req_send((uint8_t *)pkt.hdr, len,
&origin_server_ep,
_forward_resp_handler, (void *)client_ep);
_forward_resp_handler, (void *)client_ep,
GCOAP_SOCKET_TYPE_UNDEF);
return len;
}

Expand Down
8 changes: 4 additions & 4 deletions sys/net/application_layer/gcoap/gcoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#define NO_IMMEDIATE_REPLY (-1)

/* End of the range to pick a random timeout */
#define TIMEOUT_RANGE_END ((uint32_t)CONFIG_COAP_ACK_TIMEOUT_MS * CONFIG_COAP_RANDOM_FACTOR_1000 / 1000)

Check warning on line 53 in sys/net/application_layer/gcoap/gcoap.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters

/* Internal functions */
static void *_event_loop(void *arg);
Expand Down Expand Up @@ -1612,10 +1612,10 @@
return res;
}

ssize_t gcoap_req_send_tl(const uint8_t *buf, size_t len,
const sock_udp_ep_t *remote,
gcoap_resp_handler_t resp_handler, void *context,
gcoap_socket_type_t tl_type)
ssize_t gcoap_req_send(const uint8_t *buf, size_t len,
const sock_udp_ep_t *remote,
gcoap_resp_handler_t resp_handler, void *context,
gcoap_socket_type_t tl_type)
{
gcoap_socket_t socket = { 0 };
gcoap_request_memo_t *memo = NULL;
Expand Down
Loading