diff --git a/mongoose.c b/mongoose.c index 2663634c..383e3faf 100644 --- a/mongoose.c +++ b/mongoose.c @@ -14062,6 +14062,14 @@ static MG_SOCKET_TYPE raccept(MG_SOCKET_TYPE sock, union usa *usa, do { memset(usa, 0, sizeof(*usa)); fd = accept(sock, &usa->sa, len); +#if MG_ENABLE_FREERTOS_TCP + // FreeRTOS_accept() returns NULL to mean "no pending connection", + // therefore we avoid retrying it forever on non-blocking listeners + if (fd == NULL) { + fd = MG_INVALID_SOCKET; + break; + } +#endif } while (MG_SOCK_INTR(fd)); return fd; } diff --git a/src/sock.c b/src/sock.c index 56c4dc7d..e7f9690d 100644 --- a/src/sock.c +++ b/src/sock.c @@ -465,6 +465,14 @@ static MG_SOCKET_TYPE raccept(MG_SOCKET_TYPE sock, union usa *usa, do { memset(usa, 0, sizeof(*usa)); fd = accept(sock, &usa->sa, len); +#if MG_ENABLE_FREERTOS_TCP + // FreeRTOS_accept() returns NULL to mean "no pending connection", + // therefore we avoid retrying it forever on non-blocking listeners + if (fd == NULL) { + fd = MG_INVALID_SOCKET; + break; + } +#endif } while (MG_SOCK_INTR(fd)); return fd; }