Skip to content

Commit db2738f

Browse files
committed
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
1 parent 506aa3d commit db2738f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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)