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;
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;
}

View file

@ -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)