netconn: added receive flag NETCONN_NOAUTORCVD and netconn_tcp_recvd() to delay rx window updates (e.g. when receiving more data as performance improvement)

This commit is contained in:
goldsimon 2017-03-06 21:33:35 +01:00
parent b86787c39c
commit 1945582c10
2 changed files with 49 additions and 16 deletions

View File

@ -558,6 +558,32 @@ netconn_recv_data(struct netconn *conn, void **new_buf, u8_t apiflags)
return ERR_OK; return ERR_OK;
} }
static err_t
netconn_tcp_recvd_msg(struct netconn *conn, u16_t len, struct api_msg* msg)
{
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn", (conn != NULL) &&
NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP, return ERR_ARG;);
msg->conn = conn;
msg->msg.r.len = len;
return netconn_apimsg(lwip_netconn_do_recv, msg);
}
err_t
netconn_tcp_recvd(struct netconn *conn, u16_t len)
{
err_t err;
API_MSG_VAR_DECLARE(msg);
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn", (conn != NULL) &&
NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP, return ERR_ARG;);
API_MSG_VAR_ALLOC(msg);
err = netconn_tcp_recvd_msg(conn, len, &API_VAR_REF(msg));
API_MSG_VAR_FREE(msg);
return err;
}
#if LWIP_TCP #if LWIP_TCP
static err_t static err_t
netconn_recv_data_tcp(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags) netconn_recv_data_tcp(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags)
@ -576,23 +602,28 @@ netconn_recv_data_tcp(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags
return sys_mbox_valid(&conn->acceptmbox) ? ERR_CONN : ERR_CLSD; return sys_mbox_valid(&conn->acceptmbox) ? ERR_CONN : ERR_CLSD;
} }
/* need to allocate API message here so empty message pool does not result in event loss if (!(apiflags & NETCONN_NOAUTORCVD)) {
* see bug #47512: MPU_COMPATIBLE may fail on empty pool */ /* need to allocate API message here so empty message pool does not result in event loss
API_MSG_VAR_ALLOC(msg); * see bug #47512: MPU_COMPATIBLE may fail on empty pool */
API_MSG_VAR_ALLOC(msg);
}
err = netconn_recv_data(conn, (void **)new_buf, apiflags); err = netconn_recv_data(conn, (void **)new_buf, apiflags);
if (err != ERR_OK) { if (err != ERR_OK) {
API_MSG_VAR_FREE(msg); if (!(apiflags & NETCONN_NOAUTORCVD)) {
API_MSG_VAR_FREE(msg);
}
return err; return err;
} }
buf = *new_buf; buf = *new_buf;
/* Let the stack know that we have taken the data. */ if (!(apiflags & NETCONN_NOAUTORCVD)) {
API_VAR_REF(msg).conn = conn; /* Let the stack know that we have taken the data. */
API_VAR_REF(msg).msg.r.len = buf ? buf->tot_len : 1; u16_t len = buf ? buf->tot_len : 1;
/* don't care for the return value of lwip_netconn_do_recv */ /* don't care for the return value of lwip_netconn_do_recv */
/* @todo: this should really be fixed, e.g. by retrying in poll on error */ /* @todo: this should really be fixed, e.g. by retrying in poll on error */
netconn_apimsg(lwip_netconn_do_recv, &API_VAR_REF(msg)); netconn_tcp_recvd_msg(conn, len, &API_VAR_REF(msg));
API_MSG_VAR_FREE(msg); API_MSG_VAR_FREE(msg);
}
/* If we are closed, we indicate that we no longer wish to use the socket */ /* If we are closed, we indicate that we no longer wish to use the socket */
if (buf == NULL) { if (buf == NULL) {

View File

@ -58,11 +58,12 @@ extern "C" {
*/ */
/* Flags for netconn_write (u8_t) */ /* Flags for netconn_write (u8_t) */
#define NETCONN_NOFLAG 0x00 #define NETCONN_NOFLAG 0x00
#define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */ #define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */
#define NETCONN_COPY 0x01 #define NETCONN_COPY 0x01
#define NETCONN_MORE 0x02 #define NETCONN_MORE 0x02
#define NETCONN_DONTBLOCK 0x04 #define NETCONN_DONTBLOCK 0x04
#define NETCONN_NOAUTORCVD 0x08 /* prevent netconn_recv_data_tcp() from updating the tcp window - must be done manually via netconn_tcp_recvd() */
/* Flags for struct netconn.flags (u8_t) */ /* Flags for struct netconn.flags (u8_t) */
/** Should this netconn avoid blocking? */ /** Should this netconn avoid blocking? */
@ -319,6 +320,7 @@ err_t netconn_recv_udp_raw_netbuf(struct netconn *conn, struct netbuf **new_bu
err_t netconn_recv_udp_raw_netbuf_flags(struct netconn *conn, struct netbuf **new_buf, u8_t apiflags); err_t netconn_recv_udp_raw_netbuf_flags(struct netconn *conn, struct netbuf **new_buf, u8_t apiflags);
err_t netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf); err_t netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf);
err_t netconn_recv_tcp_pbuf_flags(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags); err_t netconn_recv_tcp_pbuf_flags(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags);
err_t netconn_tcp_recvd(struct netconn *conn, u16_t len);
err_t netconn_sendto(struct netconn *conn, struct netbuf *buf, err_t netconn_sendto(struct netconn *conn, struct netbuf *buf,
const ip_addr_t *addr, u16_t port); const ip_addr_t *addr, u16_t port);
err_t netconn_send(struct netconn *conn, struct netbuf *buf); err_t netconn_send(struct netconn *conn, struct netbuf *buf);