Skip to content

Commit a35cd7f

Browse files
authored
Merge pull request #2579 from geky/nsapi-max-socket-accept
lwip - Fix handling of max sockets in socket_accept
2 parents fb7ffcb + db2738f commit a35cd7f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ static int lwip_socket_accept(nsapi_stack_t *stack, nsapi_socket_t server, nsapi
313313
{
314314
struct lwip_socket *s = (struct lwip_socket *)server;
315315
struct lwip_socket *ns = lwip_arena_alloc();
316+
if (!ns) {
317+
return NSAPI_ERROR_NO_SOCKET;
318+
}
316319

317320
err_t err = netconn_accept(s->conn, &ns->conn);
318321
if (err != ERR_OK) {

features/net/network-socket/TCPServer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,19 @@ int TCPServer::accept(TCPSocket *connection, SocketAddress *address)
7676

7777
connection->_lock.unlock();
7878
break;
79-
}
80-
81-
if (NSAPI_ERROR_WOULD_BLOCK == ret) {
79+
} else if (NSAPI_ERROR_WOULD_BLOCK != ret) {
80+
break;
81+
} else {
8282
int32_t count;
8383

84+
// Release lock before blocking so other threads
85+
// accessing this object aren't blocked
8486
_lock.unlock();
8587
count = _accept_sem.wait(_timeout);
8688
_lock.lock();
8789

8890
if (count < 1) {
91+
// Semaphore wait timed out so break out and return
8992
ret = NSAPI_ERROR_WOULD_BLOCK;
9093
break;
9194
}

0 commit comments

Comments
 (0)