Remove netconn_recved() call - it was only needed in sockets implementation and contributed to bug #47512

Simon and I think it can be removed - the receive window handling get a little less precise, but that should be OK for a lightweight stack.
Receive window is now updated with the whole pbuf size (instead of only count of read bytes from socket) as soon as socket implementation gets a pbuf from netconn layer.
Work on bug #47512: MPU_COMPATIBLE may fail on empty pool (still not finished)
This commit is contained in:
Dirk Ziegelmeier 2016-04-27 21:02:16 +02:00
parent 21354af674
commit e653ac9db7
3 changed files with 13 additions and 74 deletions

View File

@ -486,7 +486,6 @@ netconn_recv_data(struct netconn *conn, void **new_buf)
if (NETCONNTYPE_GROUP(conn->type) == NETCONN_TCP) if (NETCONNTYPE_GROUP(conn->type) == NETCONN_TCP)
#endif /* (LWIP_UDP || LWIP_RAW) */ #endif /* (LWIP_UDP || LWIP_RAW) */
{ {
if (!netconn_get_noautorecved(conn) || (buf == NULL)) {
/* Let the stack know that we have taken the data. */ /* Let the stack know that we have taken the data. */
/* TODO: Speedup: Don't block and wait for the answer here /* TODO: Speedup: Don't block and wait for the answer here
(to prevent multiple thread-switches). */ (to prevent multiple thread-switches). */
@ -497,10 +496,10 @@ netconn_recv_data(struct netconn *conn, void **new_buf)
} else { } else {
API_MSG_VAR_REF(msg).msg.r.len = 1; API_MSG_VAR_REF(msg).msg.r.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 */
netconn_apimsg(lwip_netconn_do_recv, &API_MSG_VAR_REF(msg)); netconn_apimsg(lwip_netconn_do_recv, &API_MSG_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) {
@ -613,39 +612,6 @@ netconn_recv(struct netconn *conn, struct netbuf **new_buf)
} }
} }
/**
* TCP: update the receive window: by calling this, the application
* tells the stack that it has processed data and is able to accept
* new data.
* ATTENTION: use with care, this is mainly used for sockets!
* Can only be used when calling netconn_set_noautorecved(conn, 1) before.
*
* @param conn the netconn for which to update the receive window
* @param length amount of data processed (ATTENTION: this must be accurate!)
*/
void
netconn_recved(struct netconn *conn, u32_t length)
{
#if LWIP_TCP
if ((conn != NULL) && (NETCONNTYPE_GROUP(conn->type) == NETCONN_TCP) &&
(netconn_get_noautorecved(conn))) {
API_MSG_VAR_DECLARE(msg);
/* Let the stack know that we have taken the data. */
/* TODO: Speedup: Don't block and wait for the answer here
(to prevent multiple thread-switches). */
API_MSG_VAR_ALLOC_DONTFAIL(msg);
API_MSG_VAR_REF(msg).conn = conn;
API_MSG_VAR_REF(msg).msg.r.len = length;
/* don't care for the return value of lwip_netconn_do_recv */
netconn_apimsg(lwip_netconn_do_recv, &API_MSG_VAR_REF(msg));
API_MSG_VAR_FREE(msg);
}
#else /* LWIP_TCP */
LWIP_UNUSED_ARG(conn);
LWIP_UNUSED_ARG(length);
#endif /* LWIP_TCP */
}
/** /**
* Send data (in form of a netbuf) to a specific remote IP address and port. * Send data (in form of a netbuf) to a specific remote IP address and port.
* Only to be used for UDP and RAW netconns (not TCP). * Only to be used for UDP and RAW netconns (not TCP).

View File

@ -522,8 +522,6 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
return -1; return -1;
} }
LWIP_ASSERT("newconn != NULL", newconn != NULL); LWIP_ASSERT("newconn != NULL", newconn != NULL);
/* Prevent automatic window updates, we do this on our own! */
netconn_set_noautorecved(newconn, 1);
newsock = alloc_socket(newconn, 1); newsock = alloc_socket(newconn, 1);
if (newsock == -1) { if (newsock == -1) {
@ -774,8 +772,6 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
if (((flags & MSG_DONTWAIT) || netconn_is_nonblocking(sock->conn)) && if (((flags & MSG_DONTWAIT) || netconn_is_nonblocking(sock->conn)) &&
(sock->rcvevent <= 0)) { (sock->rcvevent <= 0)) {
if (off > 0) { if (off > 0) {
/* update receive window */
netconn_recved(sock->conn, (u32_t)off);
/* already received data, return that */ /* already received data, return that */
sock_set_errno(sock, 0); sock_set_errno(sock, 0);
return off; return off;
@ -797,8 +793,6 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
if (err != ERR_OK) { if (err != ERR_OK) {
if (off > 0) { if (off > 0) {
/* update receive window */
netconn_recved(sock->conn, (u32_t)off);
if (err == ERR_CLSD) { if (err == ERR_CLSD) {
/* closed but already received data, ensure select gets the FIN, too */ /* closed but already received data, ensure select gets the FIN, too */
event_callback(sock->conn, NETCONN_EVT_RCVPLUS, 0); event_callback(sock->conn, NETCONN_EVT_RCVPLUS, 0);
@ -913,11 +907,6 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
} }
} while (!done); } while (!done);
if ((off > 0) && (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP) &&
((flags & MSG_PEEK) == 0)) {
/* update receive window */
netconn_recved(sock->conn, (u32_t)off);
}
sock_set_errno(sock, 0); sock_set_errno(sock, 0);
return off; return off;
} }
@ -1234,10 +1223,6 @@ lwip_socket(int domain, int type, int protocol)
conn = netconn_new_with_callback(DOMAIN_TO_NETCONN_TYPE(domain, NETCONN_TCP), event_callback); conn = netconn_new_with_callback(DOMAIN_TO_NETCONN_TYPE(domain, NETCONN_TCP), event_callback);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_STREAM, %d) = ", LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_STREAM, %d) = ",
domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol)); domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
if (conn != NULL) {
/* Prevent automatic window updates, we do this on our own! */
netconn_set_noautorecved(conn, 1);
}
break; break;
default: default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%d, %d/UNKNOWN, %d) = -1\n", LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%d, %d/UNKNOWN, %d) = -1\n",

View File

@ -65,9 +65,6 @@ extern "C" {
#define NETCONN_FLAG_NON_BLOCKING 0x02 #define NETCONN_FLAG_NON_BLOCKING 0x02
/** Was the last connect action a non-blocking one? */ /** Was the last connect action a non-blocking one? */
#define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04 #define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04
/** If this is set, a TCP netconn must call netconn_recved() to update
the TCP receive window (done automatically if not set). */
#define NETCONN_FLAG_NO_AUTO_RECVED 0x08
/** If a nonblocking write has been rejected before, poll_tcp needs to /** If a nonblocking write has been rejected before, poll_tcp needs to
check if the netconn is writable again */ check if the netconn is writable again */
#define NETCONN_FLAG_CHECK_WRITESPACE 0x10 #define NETCONN_FLAG_CHECK_WRITESPACE 0x10
@ -271,7 +268,6 @@ err_t netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);
err_t netconn_accept(struct netconn *conn, struct netconn **new_conn); err_t netconn_accept(struct netconn *conn, struct netconn **new_conn);
err_t netconn_recv(struct netconn *conn, struct netbuf **new_buf); err_t netconn_recv(struct netconn *conn, struct netbuf **new_buf);
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);
void netconn_recved(struct netconn *conn, u32_t length);
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);
@ -307,14 +303,6 @@ err_t netconn_gethostbyname(const char *name, ip_addr_t *addr);
/** Get the blocking status of netconn calls (@todo: write/send is missing) */ /** Get the blocking status of netconn calls (@todo: write/send is missing) */
#define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0) #define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0)
/** TCP: Set the no-auto-recved status of netconn calls (see NETCONN_FLAG_NO_AUTO_RECVED) */
#define netconn_set_noautorecved(conn, val) do { if(val) { \
(conn)->flags |= NETCONN_FLAG_NO_AUTO_RECVED; \
} else { \
(conn)->flags &= ~ NETCONN_FLAG_NO_AUTO_RECVED; }} while(0)
/** TCP: Get the no-auto-recved status of netconn calls (see NETCONN_FLAG_NO_AUTO_RECVED) */
#define netconn_get_noautorecved(conn) (((conn)->flags & NETCONN_FLAG_NO_AUTO_RECVED) != 0)
#if LWIP_IPV6 #if LWIP_IPV6
/** TCP: Set the IPv6 ONLY status of netconn calls (see NETCONN_FLAG_IPV6_V6ONLY) */ /** TCP: Set the IPv6 ONLY status of netconn calls (see NETCONN_FLAG_IPV6_V6ONLY) */
#define netconn_set_ipv6only(conn, val) do { if(val) { \ #define netconn_set_ipv6only(conn, val) do { if(val) { \