Skip to content

Commit

Permalink
avoid callbacks for unsuccessful lwip_accept
Browse files Browse the repository at this point in the history
See bug #64780
  • Loading branch information
rd235 authored and goldsimon committed Jan 9, 2024
1 parent 0918866 commit 83abc87
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/api/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,25 +699,6 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
LWIP_ASSERT("invalid socket index", (newsock >= LWIP_SOCKET_OFFSET) && (newsock < NUM_SOCKETS + LWIP_SOCKET_OFFSET));
nsock = &sockets[newsock - LWIP_SOCKET_OFFSET];

/* See event_callback: If data comes in right away after an accept, even
* though the server task might not have created a new socket yet.
* In that case, newconn->socket is counted down (newconn->socket--),
* so nsock->rcvevent is >= 1 here!
*/
SYS_ARCH_PROTECT(lev);
recvevent = (s16_t)(-1 - newconn->callback_arg.socket);
newconn->callback_arg.socket = newsock;
SYS_ARCH_UNPROTECT(lev);

if (newconn->callback) {
LOCK_TCPIP_CORE();
while (recvevent > 0) {
recvevent--;
newconn->callback(newconn, NETCONN_EVT_RCVPLUS, 0);
}
UNLOCK_TCPIP_CORE();
}

/* Note that POSIX only requires us to check addr is non-NULL. addrlen must
* not be NULL if addr is valid.
*/
Expand All @@ -738,7 +719,28 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
*addrlen = IPADDR_SOCKADDR_GET_LEN(&tempaddr);
}
MEMCPY(addr, &tempaddr, *addrlen);
}

/* See event_callback: If data comes in right away after an accept, even
* though the server task might not have created a new socket yet.
* In that case, newconn->socket is counted down (newconn->socket--),
* so nsock->rcvevent is >= 1 here!
*/
SYS_ARCH_PROTECT(lev);
recvevent = (s16_t)(-1 - newconn->callback_arg.socket);
newconn->callback_arg.socket = newsock;
SYS_ARCH_UNPROTECT(lev);

if (newconn->callback) {
LOCK_TCPIP_CORE();
while (recvevent > 0) {
recvevent--;
newconn->callback(newconn, NETCONN_EVT_RCVPLUS, 0);
}
UNLOCK_TCPIP_CORE();
}

if ((addr != NULL) && (addrlen != NULL)) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d) returning new sock=%d addr=", s, newsock));
ip_addr_debug_print_val(SOCKETS_DEBUG, naddr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F"\n", port));
Expand Down

0 comments on commit 83abc87

Please sign in to comment.