summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorJukka Rissanen <jukka.rissanen@linux.intel.com>2017-02-03 15:56:15 +0200
committerJukka Rissanen <jukka.rissanen@linux.intel.com>2017-02-08 10:12:35 +0200
commitbd3908b2a989f306e621125052a8d0e9b986ad79 (patch)
tree38e784b154882abc4612fb1be0912a206d484e6c /samples
parent8c6e76fb37bf78a7c61bbdefab6ffc98088d5c1a (diff)
net: nbuf: Add timeout to net_buf getters
This commit changes the net_buf getter functions in nbuf.h by adding a timeout parameter. These function prototypes are changed to accept a timeout parameter. net_nbuf_get_rx() net_nbuf_get_tx() net_nbuf_get_data() net_nbuf_get_reserve_rx() net_nbuf_get_reserve_tx() net_nbuf_get_reserve_data() net_nbuf_copy() net_nbuf_copy_all() net_nbuf_push() net_nbuf_append() net_nbuf_write() net_nbuf_insert() Following convinience functions have not been changed net_nbuf_append_u8 net_nbuf_append_be16 net_nbuf_append_be32 net_nbuf_insert_u8 net_nbuf_insert_be16 net_nbuf_insert_be32 net_nbuf_write_u8 net_nbuf_write_be16 net_nbuf_write_be32 so they call the base function using K_FOREVER. Use the base function if you want to have a timeout when net_buf is allocated. Change-Id: I20bb602ffb73069e5a02668fce60575141586c0f Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Diffstat (limited to 'samples')
-rw-r--r--samples/bluetooth/ipsp/src/main.c2
-rw-r--r--samples/net/coaps_client/src/udp.c4
-rw-r--r--samples/net/coaps_server/src/udp.c4
-rw-r--r--samples/net/echo_client/src/echo-client.c5
-rw-r--r--samples/net/echo_server/src/echo-server.c4
-rw-r--r--samples/net/http_client/src/http_client.c25
-rw-r--r--samples/net/http_server/src/http_write_utils.c10
-rw-r--r--samples/net/irc_bot/src/irc-bot.c4
-rw-r--r--samples/net/leds_demo/src/leds-demo.c16
-rw-r--r--samples/net/mbedtls_dtlsclient/src/udp.c4
-rw-r--r--samples/net/mbedtls_dtlsserver/src/udp.c4
-rw-r--r--samples/net/mbedtls_sslclient/src/tcp.c4
-rw-r--r--samples/net/wpan_serial/src/main.c8
-rw-r--r--samples/net/wpanusb/src/wpanusb.c13
-rw-r--r--samples/net/zoap_client/src/zoap-client.c4
-rw-r--r--samples/net/zoap_server/src/zoap-server.c40
-rw-r--r--samples/net/zperf/src/zperf_tcp_uploader.c11
-rw-r--r--samples/net/zperf/src/zperf_udp_receiver.c4
-rw-r--r--samples/net/zperf/src/zperf_udp_uploader.c18
19 files changed, 101 insertions, 83 deletions
diff --git a/samples/bluetooth/ipsp/src/main.c b/samples/bluetooth/ipsp/src/main.c
index 378dca0c7..e29b95cce 100644
--- a/samples/bluetooth/ipsp/src/main.c
+++ b/samples/bluetooth/ipsp/src/main.c
@@ -145,7 +145,7 @@ static struct net_buf *build_reply_buf(const char *name,
printk("%s received %d bytes", name,
net_nbuf_appdatalen(buf));
- reply_buf = net_nbuf_get_tx(context);
+ reply_buf = net_nbuf_get_tx(context, K_FOREVER);
recv_len = net_buf_frags_len(buf->frags);
diff --git a/samples/net/coaps_client/src/udp.c b/samples/net/coaps_client/src/udp.c
index 1da593e84..b2c8e3799 100644
--- a/samples/net/coaps_client/src/udp.c
+++ b/samples/net/coaps_client/src/udp.c
@@ -58,12 +58,12 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
udp_ctx = ctx->net_ctx;
- send_buf = net_nbuf_get_tx(udp_ctx);
+ send_buf = net_nbuf_get_tx(udp_ctx, K_FOREVER);
if (!send_buf) {
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
}
- rc = net_nbuf_append(send_buf, size, (uint8_t *) buf);
+ rc = net_nbuf_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
if (!rc) {
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
}
diff --git a/samples/net/coaps_server/src/udp.c b/samples/net/coaps_server/src/udp.c
index f2a7081db..76cd1500e 100644
--- a/samples/net/coaps_server/src/udp.c
+++ b/samples/net/coaps_server/src/udp.c
@@ -47,13 +47,13 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
net_ctx = ctx->net_ctx;
- send_buf = net_nbuf_get_tx(net_ctx);
+ send_buf = net_nbuf_get_tx(net_ctx, K_FOREVER);
if (!send_buf) {
printk("cannot create buf\n");
return -EIO;
}
- rc = net_nbuf_append(send_buf, size, (uint8_t *) buf);
+ rc = net_nbuf_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
if (!rc) {
printk("cannot write buf\n");
return -EIO;
diff --git a/samples/net/echo_client/src/echo-client.c b/samples/net/echo_client/src/echo-client.c
index 67cd58514..06f4ceafc 100644
--- a/samples/net/echo_client/src/echo-client.c
+++ b/samples/net/echo_client/src/echo-client.c
@@ -364,11 +364,12 @@ static struct net_buf *prepare_send_buf(const char *name,
struct net_buf *send_buf;
bool status;
- send_buf = net_nbuf_get_tx(context);
+ send_buf = net_nbuf_get_tx(context, K_FOREVER);
NET_ASSERT(send_buf);
- status = net_nbuf_append(send_buf, expecting_len, lorem_ipsum);
+ status = net_nbuf_append(send_buf, expecting_len, lorem_ipsum,
+ K_FOREVER);
if (!status) {
NET_ERR("%s: cannot create send buf", name);
return NULL;
diff --git a/samples/net/echo_server/src/echo-server.c b/samples/net/echo_server/src/echo-server.c
index 2344c12ed..fb3deecbd 100644
--- a/samples/net/echo_server/src/echo-server.c
+++ b/samples/net/echo_server/src/echo-server.c
@@ -271,7 +271,7 @@ static struct net_buf *build_reply_buf(const char *name,
return NULL;
}
- reply_buf = net_nbuf_get_tx(context);
+ reply_buf = net_nbuf_get_tx(context, K_FOREVER);
NET_ASSERT(reply_buf);
@@ -292,7 +292,7 @@ static struct net_buf *build_reply_buf(const char *name,
net_buf_pull(tmp, header_len);
while (tmp) {
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!net_buf_headroom(tmp)) {
/* If there is no link layer headers in the
diff --git a/samples/net/http_client/src/http_client.c b/samples/net/http_client/src/http_client.c
index 2632f6adc..5ae15713e 100644
--- a/samples/net/http_client/src/http_client.c
+++ b/samples/net/http_client/src/http_client.c
@@ -54,25 +54,27 @@ int http_send_request(struct http_client_ctx *http_ctx, const char *method,
struct net_buf *tx;
int rc;
- tx = net_nbuf_get_tx(http_ctx->tcp_ctx.net_ctx);
+ tx = net_nbuf_get_tx(http_ctx->tcp_ctx.net_ctx, K_FOREVER);
if (tx == NULL) {
return -ENOMEM;
}
- if (!net_nbuf_append(tx, strlen(method), (uint8_t *)method)) {
+ if (!net_nbuf_append(tx, strlen(method), (uint8_t *)method,
+ K_FOREVER)) {
goto lb_exit;
}
- if (!net_nbuf_append(tx, strlen(url), (uint8_t *)url)) {
+ if (!net_nbuf_append(tx, strlen(url), (uint8_t *)url, K_FOREVER)) {
goto lb_exit;
}
- if (!net_nbuf_append(tx, strlen(protocol), (uint8_t *)protocol)) {
+ if (!net_nbuf_append(tx, strlen(protocol), (uint8_t *)protocol,
+ K_FOREVER)) {
goto lb_exit;
}
if (!net_nbuf_append(tx, strlen(HEADER_FIELDS),
- (uint8_t *)HEADER_FIELDS)) {
+ (uint8_t *)HEADER_FIELDS, K_FOREVER)) {
goto lb_exit;
}
@@ -80,13 +82,14 @@ int http_send_request(struct http_client_ctx *http_ctx, const char *method,
char content_len_str[CON_LEN_SIZE];
if (!net_nbuf_append(tx, strlen(content_type),
- (uint8_t *)content_type)) {
+ (uint8_t *)content_type, K_FOREVER)) {
rc = -ENOMEM;
goto lb_exit;
}
if (!net_nbuf_append(tx, strlen(content_type_value),
- (uint8_t *)content_type_value)) {
+ (uint8_t *)content_type_value,
+ K_FOREVER)) {
rc = -ENOMEM;
goto lb_exit;
}
@@ -100,18 +103,20 @@ int http_send_request(struct http_client_ctx *http_ctx, const char *method,
}
if (!net_nbuf_append(tx, strlen(content_len_str),
- (uint8_t *)content_len_str)) {
+ (uint8_t *)content_len_str, K_FOREVER)) {
rc = -ENOMEM;
goto lb_exit;
}
- if (!net_nbuf_append(tx, strlen(payload), (uint8_t *)payload)) {
+ if (!net_nbuf_append(tx, strlen(payload), (uint8_t *)payload,
+ K_FOREVER)) {
rc = -ENOMEM;
goto lb_exit;
}
} else {
- if (!net_nbuf_append(tx, strlen(sep), (uint8_t *)sep)) {
+ if (!net_nbuf_append(tx, strlen(sep), (uint8_t *)sep,
+ K_FOREVER)) {
rc = -ENOMEM;
goto lb_exit;
}
diff --git a/samples/net/http_server/src/http_write_utils.c b/samples/net/http_server/src/http_write_utils.c
index a96853040..1167cfdcb 100644
--- a/samples/net/http_server/src/http_write_utils.c
+++ b/samples/net/http_server/src/http_write_utils.c
@@ -22,7 +22,7 @@ uint16_t http_strlen(const char *str)
int http_add_header(struct net_buf *tx, const char *str)
{
- net_nbuf_append(tx, strlen(str), (uint8_t *)str);
+ net_nbuf_append(tx, strlen(str), (uint8_t *)str, K_FOREVER);
return 0;
}
@@ -36,13 +36,13 @@ int http_add_chunk(struct net_buf *tx, const char *str)
str_len = http_strlen(str);
snprintf(chunk_header, sizeof(chunk_header), "%x\r\n", str_len);
- net_nbuf_append(tx, strlen(chunk_header), chunk_header);
+ net_nbuf_append(tx, strlen(chunk_header), chunk_header, K_FOREVER);
if (str_len) {
- net_nbuf_append(tx, str_len, (uint8_t *)str);
+ net_nbuf_append(tx, str_len, (uint8_t *)str, K_FOREVER);
}
- net_nbuf_append(tx, strlen(rn), rn);
+ net_nbuf_append(tx, strlen(rn), rn, K_FOREVER);
return 0;
}
@@ -54,7 +54,7 @@ int http_write(struct http_server_ctx *ctx, const char *http_header,
struct net_buf *tx;
int rc = -EINVAL;
- tx = net_nbuf_get_tx(ctx->net_ctx);
+ tx = net_nbuf_get_tx(ctx->net_ctx, K_FOREVER);
printf("[%s:%d] net_nbuf_get_tx, rc: %d <%s>\n",
__func__, __LINE__, !tx, RC_STR(!tx));
if (tx == NULL) {
diff --git a/samples/net/irc_bot/src/irc-bot.c b/samples/net/irc_bot/src/irc-bot.c
index d3c668eb9..8b6edb87e 100644
--- a/samples/net/irc_bot/src/irc-bot.c
+++ b/samples/net/irc_bot/src/irc-bot.c
@@ -146,12 +146,12 @@ transmit(struct net_context *ctx, char buffer[], size_t len)
{
struct net_buf *send_buf;
- send_buf = net_nbuf_get_tx(ctx);
+ send_buf = net_nbuf_get_tx(ctx, K_FOREVER);
if (!send_buf) {
return -ENOMEM;
}
- if (!net_nbuf_append(send_buf, len, buffer)) {
+ if (!net_nbuf_append(send_buf, len, buffer), K_FOREVER) {
return -EINVAL;
}
diff --git a/samples/net/leds_demo/src/leds-demo.c b/samples/net/leds_demo/src/leds-demo.c
index 0fe8044d8..5f081bbea 100644
--- a/samples/net/leds_demo/src/leds-demo.c
+++ b/samples/net/leds_demo/src/leds-demo.c
@@ -100,12 +100,12 @@ static int led_get(struct zoap_resource *resource,
id = zoap_header_get_id(request);
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
@@ -167,12 +167,12 @@ static int led_post(struct zoap_resource *resource,
id = zoap_header_get_id(request);
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
@@ -245,12 +245,12 @@ static int led_put(struct zoap_resource *resource,
id = zoap_header_get_id(request);
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
@@ -307,12 +307,12 @@ static int dummy_get(struct zoap_resource *resource,
id = zoap_header_get_id(request);
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
diff --git a/samples/net/mbedtls_dtlsclient/src/udp.c b/samples/net/mbedtls_dtlsclient/src/udp.c
index 06f7fb9da..bf6f3142f 100644
--- a/samples/net/mbedtls_dtlsclient/src/udp.c
+++ b/samples/net/mbedtls_dtlsclient/src/udp.c
@@ -66,13 +66,13 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
udp_ctx = ctx->net_ctx;
- send_buf = net_nbuf_get_tx(udp_ctx);
+ send_buf = net_nbuf_get_tx(udp_ctx, K_FOREVER);
if (!send_buf) {
printk("cannot create buf\n");
return -EIO;
}
- rc = net_nbuf_append(send_buf, size, (uint8_t *) buf);
+ rc = net_nbuf_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
if (!rc) {
printk("cannot write buf\n");
return -EIO;
diff --git a/samples/net/mbedtls_dtlsserver/src/udp.c b/samples/net/mbedtls_dtlsserver/src/udp.c
index 20b68a2d5..7ed500d8c 100644
--- a/samples/net/mbedtls_dtlsserver/src/udp.c
+++ b/samples/net/mbedtls_dtlsserver/src/udp.c
@@ -60,13 +60,13 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
net_ctx = ctx->net_ctx;
- send_buf = net_nbuf_get_tx(net_ctx);
+ send_buf = net_nbuf_get_tx(net_ctx, K_FOREVER);
if (!send_buf) {
printk("cannot create buf\n");
return -EIO;
}
- rc = net_nbuf_append(send_buf, size, (uint8_t *) buf);
+ rc = net_nbuf_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
if (!rc) {
printk("cannot write buf\n");
return -EIO;
diff --git a/samples/net/mbedtls_sslclient/src/tcp.c b/samples/net/mbedtls_sslclient/src/tcp.c
index 675cef09b..5f7cca16e 100644
--- a/samples/net/mbedtls_sslclient/src/tcp.c
+++ b/samples/net/mbedtls_sslclient/src/tcp.c
@@ -54,13 +54,13 @@ int tcp_tx(void *context, const unsigned char *buf, size_t size)
tcp_ctx = ctx->net_ctx;
- send_buf = net_nbuf_get_tx(tcp_ctx);
+ send_buf = net_nbuf_get_tx(tcp_ctx, K_FOREVER);
if (!send_buf) {
printk("cannot create buf\n");
return -EIO;
}
- rc = net_nbuf_append(send_buf, size, (uint8_t *) buf);
+ rc = net_nbuf_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
if (!rc) {
printk("cannot write buf\n");
return -EIO;
diff --git a/samples/net/wpan_serial/src/main.c b/samples/net/wpan_serial/src/main.c
index 86b99acee..da56daf42 100644
--- a/samples/net/wpan_serial/src/main.c
+++ b/samples/net/wpan_serial/src/main.c
@@ -143,12 +143,12 @@ static int slip_process_byte(unsigned char c)
#endif
if (!pkt_curr) {
- pkt_curr = net_nbuf_get_reserve_rx(0);
+ pkt_curr = net_nbuf_get_reserve_rx(0, K_NO_WAIT);
if (!pkt_curr) {
SYS_LOG_ERR("No more buffers");
return 0;
}
- buf = net_nbuf_get_reserve_data(0);
+ buf = net_nbuf_get_reserve_data(0, K_NO_WAIT);
if (!buf) {
SYS_LOG_ERR("No more buffers");
net_nbuf_unref(pkt_curr);
@@ -220,13 +220,13 @@ static void send_data(uint8_t *cfg, uint8_t *data, size_t len)
{
struct net_buf *buf, *pkt;
- pkt = net_nbuf_get_reserve_rx(0);
+ pkt = net_nbuf_get_reserve_rx(0, K_NO_WAIT);
if (!pkt) {
SYS_LOG_DBG("No buf available");
return;
}
- buf = net_nbuf_get_reserve_data(0);
+ buf = net_nbuf_get_reserve_data(0, K_NO_WAIT);
if (!buf) {
SYS_LOG_DBG("No fragment available");
net_nbuf_unref(pkt);
diff --git a/samples/net/wpanusb/src/wpanusb.c b/samples/net/wpanusb/src/wpanusb.c
index e764c70ec..ee9bc0992 100644
--- a/samples/net/wpanusb/src/wpanusb.c
+++ b/samples/net/wpanusb/src/wpanusb.c
@@ -382,8 +382,17 @@ static int wpanusb_vendor_handler(struct usb_setup_packet *setup,
{
struct net_buf *pkt, *buf;
- pkt = net_nbuf_get_reserve_tx(0);
- buf = net_nbuf_get_reserve_data(0);
+ pkt = net_nbuf_get_reserve_tx(0, K_NO_WAIT);
+ if (!pkt) {
+ return -ENOMEM;
+ }
+
+ buf = net_nbuf_get_reserve_data(0, K_NO_WAIT);
+ if (!buf) {
+ net_nbuf_unref(pkt);
+ return -ENOMEM;
+ }
+
net_buf_frag_insert(pkt, buf);
net_buf_add_u8(buf, setup->bRequest);
diff --git a/samples/net/zoap_client/src/zoap-client.c b/samples/net/zoap_client/src/zoap-client.c
index 984afa451..6e12077a2 100644
--- a/samples/net/zoap_client/src/zoap-client.c
+++ b/samples/net/zoap_client/src/zoap-client.c
@@ -173,13 +173,13 @@ static void event_iface_up(struct net_mgmt_event_callback *cb,
k_delayed_work_init(&retransmit_work, retransmit_request);
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
printk("Unable to get TX buffer, not enough memory.\n");
return;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
printk("Unable to get DATA buffer, not enough memory.\n");
return;
diff --git a/samples/net/zoap_server/src/zoap-server.c b/samples/net/zoap_server/src/zoap-server.c
index 1c7d1a783..51862fe12 100644
--- a/samples/net/zoap_server/src/zoap-server.c
+++ b/samples/net/zoap_server/src/zoap-server.c
@@ -64,12 +64,12 @@ static int test_del(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
@@ -123,12 +123,12 @@ static int test_put(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
@@ -188,12 +188,12 @@ static int test_post(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
@@ -257,12 +257,12 @@ static int location_query_post(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
@@ -317,12 +317,12 @@ static int piggyback_get(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
@@ -419,12 +419,12 @@ static int query_get(struct zoap_resource *resource,
NET_INFO("*******\n");
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
@@ -494,12 +494,12 @@ static int separate_get(struct zoap_resource *resource,
goto done;
}
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
@@ -525,12 +525,12 @@ static int separate_get(struct zoap_resource *resource,
}
done:
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
@@ -614,12 +614,12 @@ static int large_get(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
@@ -712,12 +712,12 @@ static int large_update_put(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
return -ENOMEM;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
return -ENOMEM;
}
diff --git a/samples/net/zperf/src/zperf_tcp_uploader.c b/samples/net/zperf/src/zperf_tcp_uploader.c
index 7d1735203..c40b96dc8 100644
--- a/samples/net/zperf/src/zperf_tcp_uploader.c
+++ b/samples/net/zperf/src/zperf_tcp_uploader.c
@@ -54,23 +54,24 @@ void zperf_tcp_upload(struct net_context *ctx,
loop_time = k_cycle_get_32();
last_loop_time = loop_time;
- buf = net_nbuf_get_tx(ctx);
+ buf = net_nbuf_get_tx(ctx, K_FOREVER);
if (!buf) {
printk(TAG "ERROR! Failed to retrieve a buffer\n");
- continue;
+ break;
}
- frag = net_nbuf_get_data(ctx);
+ frag = net_nbuf_get_data(ctx, K_FOREVER);
if (!frag) {
+ net_nbuf_unref(buf);
printk(TAG "ERROR! Failed to retrieve a fragment\n");
- continue;
+ break;
}
net_buf_frag_add(buf, frag);
/* Fill in the TCP payload */
st = net_nbuf_append(buf, sizeof(sample_packet),
- sample_packet);
+ sample_packet, K_FOREVER);
if (!st) {
printk(TAG "ERROR! Failed to fill packet\n");
diff --git a/samples/net/zperf/src/zperf_udp_receiver.c b/samples/net/zperf/src/zperf_udp_receiver.c
index 68ff53e90..cf3681e89 100644
--- a/samples/net/zperf/src/zperf_udp_receiver.c
+++ b/samples/net/zperf/src/zperf_udp_receiver.c
@@ -67,8 +67,8 @@ static inline struct net_buf *build_reply_buf(struct net_context *context,
printk(TAG "received %d bytes\n", net_nbuf_appdatalen(buf));
- reply_buf = net_nbuf_get_tx(context);
- frag = net_nbuf_get_data(context);
+ reply_buf = net_nbuf_get_tx(context, K_FOREVER);
+ frag = net_nbuf_get_data(context, K_FOREVER);
net_buf_frag_add(reply_buf, frag);
diff --git a/samples/net/zperf/src/zperf_udp_uploader.c b/samples/net/zperf/src/zperf_udp_uploader.c
index cdff49d60..794dfb373 100644
--- a/samples/net/zperf/src/zperf_udp_uploader.c
+++ b/samples/net/zperf/src/zperf_udp_uploader.c
@@ -86,13 +86,13 @@ static inline void zperf_upload_fin(struct net_context *context,
struct net_buf *buf, *frag;
bool status;
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
printk(TAG "ERROR! Failed to retrieve a buffer\n");
continue;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
printk(TAG "ERROR! Failed to retrieve a fragment\n");
continue;
@@ -107,7 +107,7 @@ static inline void zperf_upload_fin(struct net_context *context,
USEC_PER_SEC);
status = net_nbuf_append(buf, sizeof(datagram),
- (uint8_t *)&datagram);
+ (uint8_t *)&datagram, K_FOREVER);
if (!status) {
printk(TAG "ERROR! Cannot append datagram data\n");
break;
@@ -121,7 +121,8 @@ static inline void zperf_upload_fin(struct net_context *context,
frag = net_nbuf_write(buf, net_buf_frag_last(buf),
sizeof(struct zperf_udp_datagram),
- &pos, size, sample_packet);
+ &pos, size, sample_packet,
+ K_FOREVER);
}
/* Send the packet */
@@ -229,13 +230,13 @@ void zperf_udp_upload(struct net_context *context,
last_loop_time = loop_time;
- buf = net_nbuf_get_tx(context);
+ buf = net_nbuf_get_tx(context, K_FOREVER);
if (!buf) {
printk(TAG "ERROR! Failed to retrieve a buffer\n");
continue;
}
- frag = net_nbuf_get_data(context);
+ frag = net_nbuf_get_data(context, K_FOREVER);
if (!frag) {
printk(TAG "ERROR! Failed to retrieve a frag\n");
continue;
@@ -250,7 +251,7 @@ void zperf_udp_upload(struct net_context *context,
htonl(HW_CYCLES_TO_USEC(loop_time) % USEC_PER_SEC);
status = net_nbuf_append(buf, sizeof(datagram),
- (uint8_t *)&datagram);
+ (uint8_t *)&datagram, K_FOREVER);
if (!status) {
printk(TAG "ERROR! Cannot append datagram data\n");
break;
@@ -264,7 +265,8 @@ void zperf_udp_upload(struct net_context *context,
frag = net_nbuf_write(buf, net_buf_frag_last(buf),
sizeof(struct zperf_udp_datagram),
- &pos, size, sample_packet);
+ &pos, size, sample_packet,
+ K_FOREVER);
}
/* Send the packet */