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.
pull/10807/head
Kevin Bracey 2017-03-21 11:31:55 +02:00
parent 09ea361c7e
commit 3b178a08ef
2 changed files with 6 additions and 6 deletions

View File

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

View File

@ -526,7 +526,7 @@ private:
bool in_use;
struct netconn *conn;
struct netbuf *buf;
struct pbuf *buf;
u16_t offset;
void (*cb)(void *);