Merge pull request #2579 from geky/nsapi-max-socket-accept

lwip - Fix handling of max sockets in socket_accept
pull/2593/head
Sam Grove 2016-09-10 07:11:20 -05:00 committed by GitHub
commit a35cd7f81f
2 changed files with 9 additions and 3 deletions

View File

@ -313,6 +313,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) {

View File

@ -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;
}