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 <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2019-02-19 13:48:10 +01:00 committed by Andrew Boie
parent 5594aee9aa
commit 01d41f25b7
2 changed files with 15 additions and 39 deletions

View file

@ -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; struct net_context *ctx = (struct net_context *)output_ctx;
int ret = -ENOMEM; int ret = -ENOMEM;
struct net_pkt *pkt;
if (ctx == NULL) { if (ctx == NULL) {
return length; return length;
} }
pkt = net_pkt_get_tx(ctx, K_NO_WAIT); ret = net_context_send_new(ctx, data, length,
if (pkt == NULL) { NULL, K_NO_WAIT, NULL, 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);
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }
DBG(data); DBG(data);
fail: fail:
if (ret < 0 && (pkt != NULL)) {
net_pkt_unref(pkt);
}
return length; return length;
} }

View file

@ -63,34 +63,24 @@ static void fill_header(struct net_buf *buf)
static void syslog_hook_net(const char *fmt, ...) static void syslog_hook_net(const char *fmt, ...)
{ {
struct net_pkt *pkt; struct net_buf *buf;
struct net_buf *frag;
u8_t *ptr;
va_list vargs; va_list vargs;
u8_t *ptr;
int ret; int ret;
pkt = net_pkt_get_tx(ctx, K_NO_WAIT); buf = net_buf_alloc(&syslog_tx_bufs, K_NO_WAIT);
if (pkt == NULL) { if (!buf) {
return; return;
} }
frag = net_pkt_get_data(ctx, K_NO_WAIT); fill_header(buf);
if (frag == NULL) {
net_pkt_unref(pkt);
return;
}
net_pkt_frag_add(pkt, frag);
fill_header(frag);
va_start(vargs, fmt); 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) { if (ret < 0) {
net_pkt_unref(pkt);
return; return;
} }
@ -101,19 +91,19 @@ static void syslog_hook_net(const char *fmt, ...)
ret--; ret--;
} }
net_buf_add(frag, ret); net_buf_add(buf, ret);
#if DEBUG_PRINTING #if DEBUG_PRINTING
{ {
static u32_t count; static u32_t count;
printk("%d:%s", ++count, frag->data); printk("%d:%s", ++count, buf->data);
} }
#endif #endif
ret = net_context_send(pkt, NULL, K_NO_WAIT, NULL, NULL); net_context_send_new(ctx, buf->data, buf->len,
if (ret < 0) { NULL, K_NO_WAIT, NULL, NULL);
net_pkt_unref(pkt);
} net_buf_unref(buf);
} }
void syslog_net_hook_install(void) void syslog_net_hook_install(void)