From 3b178a08efcfb62a8b53c8aa6781e8ab7def6963 Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Tue, 21 Mar 2017 11:31:55 +0200 Subject: [PATCH] NSAPI/lwIP: Use netconn_recv_tcp_pbuf Slight RAM+speed efficiency improvement - read the TCP implementation's native pbufs, rather than forcing netconn_recv to generate netbuf wrappers for us. Saves one small lwIP heap allocation per TCP packet received. --- features/lwipstack/LWIPStack.cpp | 10 +++++----- features/lwipstack/LWIPStack.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/features/lwipstack/LWIPStack.cpp b/features/lwipstack/LWIPStack.cpp index 04ca9d59c9..e008826a70 100644 --- a/features/lwipstack/LWIPStack.cpp +++ b/features/lwipstack/LWIPStack.cpp @@ -341,7 +341,7 @@ nsapi_error_t LWIP::socket_close(nsapi_socket_t handle) _event_flag.wait_any(TCP_CLOSED_FLAG, TCP_CLOSE_TIMEOUT); } #endif - netbuf_delete(s->buf); + pbuf_free(s->buf); err_t err = netconn_delete(s->conn); arena_dealloc(s); return err_remap(err); @@ -465,7 +465,7 @@ nsapi_size_or_error_t LWIP::socket_recv(nsapi_socket_t handle, void *data, nsapi struct mbed_lwip_socket *s = (struct mbed_lwip_socket *)handle; if (!s->buf) { - err_t err = netconn_recv(s->conn, &s->buf); + err_t err = netconn_recv_tcp_pbuf(s->conn, &s->buf); s->offset = 0; if (err != ERR_OK) { @@ -473,11 +473,11 @@ nsapi_size_or_error_t LWIP::socket_recv(nsapi_socket_t handle, void *data, nsapi } } - u16_t recv = netbuf_copy_partial(s->buf, data, (u16_t)size, s->offset); + u16_t recv = pbuf_copy_partial(s->buf, data, (u16_t)size, s->offset); s->offset += recv; - if (s->offset >= netbuf_len(s->buf)) { - netbuf_delete(s->buf); + if (s->offset >= s->buf->tot_len) { + pbuf_free(s->buf); s->buf = 0; } diff --git a/features/lwipstack/LWIPStack.h b/features/lwipstack/LWIPStack.h index 00c32bea6a..a9b85cc7f6 100644 --- a/features/lwipstack/LWIPStack.h +++ b/features/lwipstack/LWIPStack.h @@ -526,7 +526,7 @@ private: bool in_use; struct netconn *conn; - struct netbuf *buf; + struct pbuf *buf; u16_t offset; void (*cb)(void *);