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
pull/2579/head
Christopher Haster 2016-08-29 17:36:49 -05:00
parent 506aa3d4ea
commit db2738f850
1 changed files with 6 additions and 3 deletions

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