From 506aa3d4ea1dc4f28d150b573465b832e34adb77 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 29 Aug 2016 17:20:05 -0500 Subject: [PATCH 1/2] lwip - Fixed handling of max sockets in socket_accept --- features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c b/features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c index 1e048082755..b1ba8582e92 100644 --- a/features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c +++ b/features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c @@ -308,6 +308,9 @@ static int lwip_socket_accept(nsapi_stack_t *stack, nsapi_socket_t server, nsapi { struct lwip_socket *s = (struct lwip_socket *)server; struct lwip_socket *ns = lwip_arena_alloc(); + if (!ns) { + return NSAPI_ERROR_NO_SOCKET; + } err_t err = netconn_accept(s->conn, &ns->conn); if (err != ERR_OK) { From db2738f8506008b1f943304e90daf18b06d71127 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 29 Aug 2016 17:36:49 -0500 Subject: [PATCH 2/2] nsapi - Corrected handling of errors in TCPServer accept - Corrected handling, before errors would forcibly restart the accept loop without checks for timeouts - Rearranged accept logic to match the logic of recv/send/recvfrom/sendto --- features/net/network-socket/TCPServer.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/features/net/network-socket/TCPServer.cpp b/features/net/network-socket/TCPServer.cpp index a56372032f4..2ddfb9288e8 100644 --- a/features/net/network-socket/TCPServer.cpp +++ b/features/net/network-socket/TCPServer.cpp @@ -76,16 +76,19 @@ int TCPServer::accept(TCPSocket *connection, SocketAddress *address) connection->_lock.unlock(); break; - } - - if (NSAPI_ERROR_WOULD_BLOCK == ret) { + } else if (NSAPI_ERROR_WOULD_BLOCK != ret) { + break; + } else { int32_t count; + // Release lock before blocking so other threads + // accessing this object aren't blocked _lock.unlock(); count = _accept_sem.wait(_timeout); _lock.lock(); if (count < 1) { + // Semaphore wait timed out so break out and return ret = NSAPI_ERROR_WOULD_BLOCK; break; }