diff --git a/src/api/sockets.c b/src/api/sockets.c index 232a8343..78526350 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -2072,7 +2072,9 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, /* Call lwip_selscan again: there could have been events between the last scan (without us on the list) and putting us on the list! */ nready = lwip_selscan(maxfdp1, readset, writeset, exceptset, &lreadset, &lwriteset, &lexceptset); - if (!nready) { + if (nready < 0) { + set_errno(EBADF); + } else if (!nready) { /* Still none ready, just wait to be woken */ if (timeout == 0) { /* Wait forever */ @@ -2146,6 +2148,11 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, /* See what's set now after waiting */ nready = lwip_selscan(maxfdp1, readset, writeset, exceptset, &lreadset, &lwriteset, &lexceptset); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: nready=%d\n", nready)); + if (nready < 0) { + set_errno(EBADF); + lwip_select_dec_sockets_used(maxfdp1, &used_sockets); + return -1; + } } } }