Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lwip - Fix handling of max sockets in socket_accept #2579

Merged
merged 2 commits into from
Sep 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions features/net/network-socket/TCPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down