From 01d41f25b73220e91d3f042bba7c10c9db54f38d Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Tue, 19 Feb 2019 13:48:10 +0100 Subject: [PATCH] logging: Switch to new net_pkt/net_context API Let's still use local pool for a buffer to avoid using stack. Signed-off-by: Tomasz Bursztyka --- subsys/logging/log_backend_net.c | 18 ++-------------- subsys/logging/sys_log_net.c | 36 ++++++++++++-------------------- 2 files changed, 15 insertions(+), 39 deletions(-) diff --git a/subsys/logging/log_backend_net.c b/subsys/logging/log_backend_net.c index 777ea4fd04..0d672143e6 100644 --- a/subsys/logging/log_backend_net.c +++ b/subsys/logging/log_backend_net.c @@ -58,33 +58,19 @@ static int line_out(u8_t *data, size_t length, void *output_ctx) { struct net_context *ctx = (struct net_context *)output_ctx; int ret = -ENOMEM; - struct net_pkt *pkt; if (ctx == NULL) { return length; } - pkt = net_pkt_get_tx(ctx, K_NO_WAIT); - if (pkt == NULL) { - goto fail; - } - - if (net_pkt_append_all(pkt, length, data, K_NO_WAIT) == false) { - goto fail; - } - - ret = net_context_send(pkt, NULL, K_NO_WAIT, NULL, NULL); + ret = net_context_send_new(ctx, data, length, + NULL, K_NO_WAIT, NULL, NULL); if (ret < 0) { goto fail; } DBG(data); - fail: - if (ret < 0 && (pkt != NULL)) { - net_pkt_unref(pkt); - } - return length; } diff --git a/subsys/logging/sys_log_net.c b/subsys/logging/sys_log_net.c index 97a4d8a15f..787c2e76b8 100644 --- a/subsys/logging/sys_log_net.c +++ b/subsys/logging/sys_log_net.c @@ -63,34 +63,24 @@ static void fill_header(struct net_buf *buf) static void syslog_hook_net(const char *fmt, ...) { - struct net_pkt *pkt; - struct net_buf *frag; - u8_t *ptr; + struct net_buf *buf; va_list vargs; + u8_t *ptr; int ret; - pkt = net_pkt_get_tx(ctx, K_NO_WAIT); - if (pkt == NULL) { + buf = net_buf_alloc(&syslog_tx_bufs, K_NO_WAIT); + if (!buf) { return; } - frag = net_pkt_get_data(ctx, K_NO_WAIT); - if (frag == NULL) { - net_pkt_unref(pkt); - return; - } - - net_pkt_frag_add(pkt, frag); - - fill_header(frag); + fill_header(buf); va_start(vargs, fmt); - ptr = net_buf_tail(frag); + ptr = net_buf_tail(buf); - ret = vsnprintk(ptr, (net_buf_tailroom(frag) - 1), fmt, vargs); + ret = vsnprintk(ptr, (net_buf_tailroom(buf) - 1), fmt, vargs); if (ret < 0) { - net_pkt_unref(pkt); return; } @@ -101,19 +91,19 @@ static void syslog_hook_net(const char *fmt, ...) ret--; } - net_buf_add(frag, ret); + net_buf_add(buf, ret); #if DEBUG_PRINTING { static u32_t count; - printk("%d:%s", ++count, frag->data); + printk("%d:%s", ++count, buf->data); } #endif - ret = net_context_send(pkt, NULL, K_NO_WAIT, NULL, NULL); - if (ret < 0) { - net_pkt_unref(pkt); - } + net_context_send_new(ctx, buf->data, buf->len, + NULL, K_NO_WAIT, NULL, NULL); + + net_buf_unref(buf); } void syslog_net_hook_install(void)