Skip to content

Commit 3b178a0

Browse files
committed
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.
1 parent 09ea361 commit 3b178a0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

features/lwipstack/LWIPStack.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ nsapi_error_t LWIP::socket_close(nsapi_socket_t handle)
341341
_event_flag.wait_any(TCP_CLOSED_FLAG, TCP_CLOSE_TIMEOUT);
342342
}
343343
#endif
344-
netbuf_delete(s->buf);
344+
pbuf_free(s->buf);
345345
err_t err = netconn_delete(s->conn);
346346
arena_dealloc(s);
347347
return err_remap(err);
@@ -465,19 +465,19 @@ nsapi_size_or_error_t LWIP::socket_recv(nsapi_socket_t handle, void *data, nsapi
465465
struct mbed_lwip_socket *s = (struct mbed_lwip_socket *)handle;
466466

467467
if (!s->buf) {
468-
err_t err = netconn_recv(s->conn, &s->buf);
468+
err_t err = netconn_recv_tcp_pbuf(s->conn, &s->buf);
469469
s->offset = 0;
470470

471471
if (err != ERR_OK) {
472472
return err_remap(err);
473473
}
474474
}
475475

476-
u16_t recv = netbuf_copy_partial(s->buf, data, (u16_t)size, s->offset);
476+
u16_t recv = pbuf_copy_partial(s->buf, data, (u16_t)size, s->offset);
477477
s->offset += recv;
478478

479-
if (s->offset >= netbuf_len(s->buf)) {
480-
netbuf_delete(s->buf);
479+
if (s->offset >= s->buf->tot_len) {
480+
pbuf_free(s->buf);
481481
s->buf = 0;
482482
}
483483

features/lwipstack/LWIPStack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
526526
bool in_use;
527527

528528
struct netconn *conn;
529-
struct netbuf *buf;
529+
struct pbuf *buf;
530530
u16_t offset;
531531

532532
void (*cb)(void *);

0 commit comments

Comments
 (0)